From 7dd635640fa7361ca4b3549fd20534a0165beff8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:13:37 +0900 Subject: [PATCH 1/8] test: fix Model::update() usage --- tests/Unit/UserModelTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/UserModelTest.php b/tests/Unit/UserModelTest.php index 3b8371fd1..65eee5b27 100644 --- a/tests/Unit/UserModelTest.php +++ b/tests/Unit/UserModelTest.php @@ -173,7 +173,7 @@ public function testUpdateUserObjectWithUserDataToUpdate(): void $user->email = 'bar@bar.com'; $user->active = true; - $users->update(null, $user); + $users->update($user->id, $user); $this->seeInDatabase('auth_identities', [ 'user_id' => $user->id, @@ -209,7 +209,7 @@ public function testUpdateUserArrayWithUserDataToUpdate(): void // Fix value type $userArray['active'] = (int) $userArray['active']; - $users->update(null, $userArray); + $users->update($user->id, $userArray); $this->dontSeeInDatabase('auth_identities', [ 'user_id' => $user->id, From 5e420d351ffd64a19c402881f598959e26a9de68 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:14:40 +0900 Subject: [PATCH 2/8] test: update test with CITestStreamFilter --- tests/Commands/SetupTest.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/Commands/SetupTest.php b/tests/Commands/SetupTest.php index 198df5884..205778e29 100644 --- a/tests/Commands/SetupTest.php +++ b/tests/Commands/SetupTest.php @@ -4,6 +4,7 @@ namespace Tests\Commands; +use CodeIgniter\CodeIgniter; use CodeIgniter\Shield\Commands\Setup; use CodeIgniter\Test\Filters\CITestStreamFilter; use Config\Services; @@ -21,15 +22,27 @@ protected function setUp(): void { parent::setUp(); - CITestStreamFilter::$buffer = ''; - $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter'); + // @phpstan-ignore-next-line + if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { + CITestStreamFilter::registration(); + CITestStreamFilter::addOutputFilter(); + } else { + CITestStreamFilter::$buffer = ''; + $this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter'); + } } protected function tearDown(): void { parent::tearDown(); - stream_filter_remove($this->streamFilter); + // @phpstan-ignore-next-line + if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { + CITestStreamFilter::removeOutputFilter(); + CITestStreamFilter::removeErrorFilter(); + } else { + stream_filter_remove($this->streamFilter); + } } public function testRun(): void From 7e50795cb465d8cffcc8a0a3a3415e0b0b34463b Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:15:12 +0900 Subject: [PATCH 3/8] test: update timezone for tests --- tests/Controllers/LoginTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/Controllers/LoginTest.php b/tests/Controllers/LoginTest.php index 063ce4878..76b7c394f 100644 --- a/tests/Controllers/LoginTest.php +++ b/tests/Controllers/LoginTest.php @@ -4,6 +4,7 @@ namespace Tests\Controllers; +use CodeIgniter\CodeIgniter; use CodeIgniter\Config\Factories; use CodeIgniter\I18n\Time; use CodeIgniter\Shield\Authentication\Actions\Email2FA; @@ -64,7 +65,12 @@ public function testLoginBadEmail(): void public function testLoginActionEmailSuccess(): void { - Time::setTestNow('March 10, 2017', 'America/Chicago'); + // @phpstan-ignore-next-line + if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { + Time::setTestNow('March 10, 2017', 'UTC'); + } else { + Time::setTestNow('March 10, 2017', 'America/Chicago'); + } $this->user->createEmailIdentity([ 'email' => 'foo@example.com', @@ -116,7 +122,12 @@ public function testAfterLoggedInNotDisplayLoginPage(): void public function testLoginActionUsernameSuccess(): void { - Time::setTestNow('March 10, 2017', 'America/Chicago'); + // @phpstan-ignore-next-line + if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { + Time::setTestNow('March 10, 2017', 'UTC'); + } else { + Time::setTestNow('March 10, 2017', 'America/Chicago'); + } // Add 'username' to $validFields $authConfig = config('Auth'); From 36ea56783d9df3ec609aadcfc60a46f80369c4d7 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:20:48 +0900 Subject: [PATCH 4/8] chore: add skip --- rector.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rector.php b/rector.php index 1b797a7d0..528fb5757 100644 --- a/rector.php +++ b/rector.php @@ -114,9 +114,13 @@ // Ignore tests that use CodeIgniter::CI_VERSION UnwrapFutureCompatibleIfPhpVersionRector::class => [ __DIR__ . '/tests/Commands/UserModelGeneratorTest.php', + __DIR__ . '/tests/Controllers/LoginTest.php', + __DIR__ . '/tests/Commands/SetupTest.php', ], RemoveUnusedPrivatePropertyRector::class => [ __DIR__ . '/tests/Commands/UserModelGeneratorTest.php', + __DIR__ . '/tests/Controllers/LoginTest.php', + __DIR__ . '/tests/Commands/SetupTest.php', ], ]); // auto import fully qualified class names From e9f0bc8937050633996af4f6afe6887c58a5f446 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:41:37 +0900 Subject: [PATCH 5/8] chore: update psalm_autoload.php --- psalm_autoload.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/psalm_autoload.php b/psalm_autoload.php index 5601e5146..f68b2665a 100644 --- a/psalm_autoload.php +++ b/psalm_autoload.php @@ -12,6 +12,10 @@ foreach ($helperDirs as $dir) { $dir = __DIR__ . '/' . $dir; + if (! is_dir($dir)) { + continue; + } + chdir($dir); foreach (glob('*_helper.php') as $filename) { @@ -20,3 +24,5 @@ require_once $filePath; } } + +chdir(__DIR__); From 688e88d36105d2e9fa36cfa2411f1842b8322289 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:42:02 +0900 Subject: [PATCH 6/8] chore: add baseline vendor/bin/psalm --set-baseline=psalm-baseline.xml --- psalm-baseline.xml | 11 +++++++++++ psalm.xml | 1 + 2 files changed, 12 insertions(+) create mode 100644 psalm-baseline.xml diff --git a/psalm-baseline.xml b/psalm-baseline.xml new file mode 100644 index 000000000..8ada55d82 --- /dev/null +++ b/psalm-baseline.xml @@ -0,0 +1,11 @@ + + + + + $this->where(['user_id' => $user->id])->delete() + + + + + + diff --git a/psalm.xml b/psalm.xml index 28656c022..5ea186498 100644 --- a/psalm.xml +++ b/psalm.xml @@ -7,6 +7,7 @@ xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" autoloader="psalm_autoload.php" cacheDirectory="build/psalm/" + errorBaseline="psalm-baseline.xml" > From 80166b415de52cc09c4235a6ca663b7afe845c5e Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 11 Jan 2023 14:51:29 +0900 Subject: [PATCH 7/8] chore: add baseline ERROR: ReservedWord - src/Controllers/MagicLinkController.php:155:9 - 'resource' is a reserved word (see https://psalm.dev/095) $identityModel->delete($identity->id); ERROR: ReservedWord - src/Models/GroupModel.php:30:17 - 'resource' is a reserved word (see https://psalm.dev/095) $rows = $this->builder() ->select('group') ->where('user_id', $user->id) ->get() --- psalm-baseline.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8ada55d82..3c9f7c89e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -8,4 +8,10 @@ + + + + + + From cb81db05045494472a68771ac7b5490e2112875b Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 12 Jan 2023 17:34:42 +0900 Subject: [PATCH 8/8] docs: remove unneeded @phpstan-ignore-next-line --- tests/Commands/SetupTest.php | 2 -- tests/Controllers/LoginTest.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/tests/Commands/SetupTest.php b/tests/Commands/SetupTest.php index 205778e29..43225adf9 100644 --- a/tests/Commands/SetupTest.php +++ b/tests/Commands/SetupTest.php @@ -22,7 +22,6 @@ protected function setUp(): void { parent::setUp(); - // @phpstan-ignore-next-line if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { CITestStreamFilter::registration(); CITestStreamFilter::addOutputFilter(); @@ -36,7 +35,6 @@ protected function tearDown(): void { parent::tearDown(); - // @phpstan-ignore-next-line if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { CITestStreamFilter::removeOutputFilter(); CITestStreamFilter::removeErrorFilter(); diff --git a/tests/Controllers/LoginTest.php b/tests/Controllers/LoginTest.php index 76b7c394f..2ffe35341 100644 --- a/tests/Controllers/LoginTest.php +++ b/tests/Controllers/LoginTest.php @@ -65,7 +65,6 @@ public function testLoginBadEmail(): void public function testLoginActionEmailSuccess(): void { - // @phpstan-ignore-next-line if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { Time::setTestNow('March 10, 2017', 'UTC'); } else { @@ -122,7 +121,6 @@ public function testAfterLoggedInNotDisplayLoginPage(): void public function testLoginActionUsernameSuccess(): void { - // @phpstan-ignore-next-line if (version_compare(CodeIgniter::CI_VERSION, '4.3.0', '>=')) { Time::setTestNow('March 10, 2017', 'UTC'); } else {