Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update minimum CI4 version to 4.3.5 #871

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ See the [An Official Auth Library](https://codeigniter.com/news/shield) for more

Usage of Shield requires the following:

- A [CodeIgniter 4.2.7+](https://github.com/codeigniter4/CodeIgniter4/) based project
- A [CodeIgniter 4.3.5+](https://github.com/codeigniter4/CodeIgniter4/) based project
- [Composer](https://getcomposer.org/) for package management
- PHP 7.4.3+

Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Version 1.0.0-beta.6 to 1.0.0-beta.7

### The minimum CodeIgniter version

Shield requires CodeIgniter 4.3.5 or later.
Versions prior to 4.3.5 have known vulnerabilities.
See https://github.com/codeigniter4/CodeIgniter4/security/advisories

### Mandatory Config Changes

#### New Config\AuthToken
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"require-dev": {
"codeigniter/phpstan-codeigniter": "^1.3",
"codeigniter4/devkit": "^1.0",
"codeigniter4/framework": "^4.2.7",
"codeigniter4/framework": "^4.3.5",
"firebase/php-jwt": "^6.4",
"mikey179/vfsstream": "^1.6.7",
"mockery/mockery": "^1.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ These instructions assume that you have already [installed the CodeIgniter 4 app
## Requirements

- [Composer](https://getcomposer.org)
- Codeigniter **v4.2.7** or later
- Codeigniter **v4.3.5** or later
- A created database that you can access via the Spark CLI script
- InnoDB (not MyISAM) is required if MySQL is used.

Expand Down
41 changes: 14 additions & 27 deletions src/Test/MockInputOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace CodeIgniter\Shield\Test;

use CodeIgniter\CLI\CLI;
use CodeIgniter\CodeIgniter;
use CodeIgniter\Shield\Commands\Utils\InputOutput;
use CodeIgniter\Shield\Exceptions\LogicException;
use CodeIgniter\Test\Filters\CITestStreamFilter;
Expand Down Expand Up @@ -52,23 +51,21 @@ public function prompt(string $field, $options = null, $validation = null): stri
{
$input = array_shift($this->inputs);

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();

PhpStreamWrapper::register();
PhpStreamWrapper::setContent($input);
PhpStreamWrapper::register();
PhpStreamWrapper::setContent($input);

$userInput = CLI::prompt($field, $options, $validation);
$userInput = CLI::prompt($field, $options, $validation);

PhpStreamWrapper::restore();
PhpStreamWrapper::restore();

CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();

if ($input !== $userInput) {
throw new LogicException($input . '!==' . $userInput);
}
if ($input !== $userInput) {
throw new LogicException($input . '!==' . $userInput);
}

return $input;
Expand All @@ -79,23 +76,13 @@ public function write(
?string $foreground = null,
?string $background = null
): void {
if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
} else {
CITestStreamFilter::$buffer = '';

$streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
}
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();

CLI::write($text, $foreground, $background);
$this->outputs[] = CITestStreamFilter::$buffer;

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
} else {
stream_filter_remove($streamFilter);
}
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
}
}
20 changes: 4 additions & 16 deletions tests/Commands/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Commands;

use CodeIgniter\CodeIgniter;
use CodeIgniter\Shield\Commands\Setup;
use CodeIgniter\Test\Filters\CITestStreamFilter;
use Config\Services;
Expand All @@ -16,31 +15,20 @@
*/
final class SetupTest extends TestCase
{
private $streamFilter;

protected function setUp(): void
{
parent::setUp();

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
} else {
CITestStreamFilter::$buffer = '';
$this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
}
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
}

protected function tearDown(): void
{
parent::tearDown();

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
} else {
stream_filter_remove($this->streamFilter);
}
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
}

public function testRun(): void
Expand Down
24 changes: 5 additions & 19 deletions tests/Commands/UserModelGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Commands;

use CodeIgniter\CodeIgniter;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\Filters\CITestStreamFilter;

Expand All @@ -13,22 +12,13 @@
*/
final class UserModelGeneratorTest extends CIUnitTestCase
{
private $streamFilter;

protected function setUp(): void
{
parent::setUp();

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
CITestStreamFilter::addErrorFilter();
} else {
CITestStreamFilter::$buffer = '';

$this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
$this->streamFilter = stream_filter_append(STDERR, 'CITestStreamFilter');
}
CITestStreamFilter::registration();
CITestStreamFilter::addOutputFilter();
CITestStreamFilter::addErrorFilter();

if (is_file(HOMEPATH . 'src/Models/UserModel.php')) {
copy(HOMEPATH . 'src/Models/UserModel.php', HOMEPATH . 'src/Models/UserModel.php.bak');
Expand All @@ -41,12 +31,8 @@ protected function tearDown(): void
{
parent::tearDown();

if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();
} else {
stream_filter_remove($this->streamFilter);
}
CITestStreamFilter::removeOutputFilter();
CITestStreamFilter::removeErrorFilter();

$this->deleteTestFiles();

Expand Down
13 changes: 2 additions & 11 deletions tests/Controllers/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Tests\Controllers;

use CodeIgniter\CodeIgniter;
use CodeIgniter\Config\Factories;
use CodeIgniter\I18n\Time;
use CodeIgniter\Shield\Authentication\Actions\Email2FA;
Expand Down Expand Up @@ -35,7 +34,7 @@
Services::injectMock('routes', $routes);
}

public function testLoginBadEmail(): void

Check warning on line 37 in tests/Controllers/LoginTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - OCI8

Took 1.98s from 0.50s limit to run Tests\\Controllers\\LoginTest::testLoginBadEmail
{
$this->user->createEmailIdentity([
'email' => 'foo@example.com',
Expand Down Expand Up @@ -110,11 +109,7 @@

public function testLoginActionEmailSuccess(): void
{
if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
Time::setTestNow('March 10, 2017', 'UTC');
} else {
Time::setTestNow('March 10, 2017', 'America/Chicago');
}
Time::setTestNow('March 10, 2017', 'UTC');

$this->user->createEmailIdentity([
'email' => 'foo@example.com',
Expand Down Expand Up @@ -166,11 +161,7 @@

public function testLoginActionUsernameSuccess(): void
{
if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) {
Time::setTestNow('March 10, 2017', 'UTC');
} else {
Time::setTestNow('March 10, 2017', 'America/Chicago');
}
Time::setTestNow('March 10, 2017', 'UTC');

// Add 'username' to $validFields
$authConfig = config('Auth');
Expand Down
Loading