From 8461519e587a43efc140e40054e1d6b9f262dd5c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 4 Feb 2023 09:36:59 +0900 Subject: [PATCH 1/3] test: replace deprecated assertObjectHasAttribute() --- tests/system/Commands/BaseCommandTest.php | 4 ++-- tests/system/Config/BaseConfigTest.php | 2 +- tests/system/Entity/EntityTest.php | 2 +- tests/system/Log/Handlers/ChromeLoggerHandlerTest.php | 5 +++-- tests/system/Test/FabricatorTest.php | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/system/Commands/BaseCommandTest.php b/tests/system/Commands/BaseCommandTest.php index e1b857e40060..068a8d832924 100644 --- a/tests/system/Commands/BaseCommandTest.php +++ b/tests/system/Commands/BaseCommandTest.php @@ -35,14 +35,14 @@ public function testMagicIssetTrue() { $command = new AppInfo($this->logger, service('commands')); - $this->assertObjectHasAttribute('group', $command); + $this->assertTrue(isset($command->group)); } public function testMagicIssetFalse() { $command = new AppInfo($this->logger, service('commands')); - $this->assertObjectNotHasAttribute('foobar', $command); + $this->assertFalse(isset($command->foobar)); } public function testMagicGet() diff --git a/tests/system/Config/BaseConfigTest.php b/tests/system/Config/BaseConfigTest.php index 014deca6c344..3d1fe88c53a8 100644 --- a/tests/system/Config/BaseConfigTest.php +++ b/tests/system/Config/BaseConfigTest.php @@ -110,7 +110,7 @@ public function testEnvironmentOverrides() // override config with shortPrefix ENV var $this->assertSame('hubbahubba', $config->delta); // incorrect env name should not inject property - $this->assertObjectNotHasAttribute('notthere', $config); + $this->assertFalse(property_exists($config, 'notthere')); // empty ENV var should not affect config setting $this->assertSame('pineapple', $config->fruit); // non-empty ENV var should overrideconfig setting diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index 4ee74514a1b6..1e03157ab188 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -96,7 +96,7 @@ public function testFill() $this->assertSame(123, $entity->foo); $this->assertSame('bar:234:bar', $entity->bar); - $this->assertObjectNotHasAttribute('baz', $entity); + $this->assertSame(4556, $entity->baz); } /** diff --git a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php index 0587763bec09..88a27b45b351 100644 --- a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php +++ b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php @@ -66,10 +66,11 @@ public function testSetDateFormat() $config->handlers['CodeIgniter\Log\Handlers\TestHandler']['handles'] = ['critical']; $logger = new ChromeLoggerHandler($config->handlers['CodeIgniter\Log\Handlers\TestHandler']); + $result = $logger->setDateFormat('F j, Y'); - $this->assertObjectHasAttribute('dateFormat', $result); - $this->assertObjectHasAttribute('dateFormat', $logger); + $this->assertSame('F j, Y', $this->getPrivateProperty($result, 'dateFormat')); + $this->assertSame('F j, Y', $this->getPrivateProperty($logger, 'dateFormat')); } public function testChromeLoggerHeaderSent() diff --git a/tests/system/Test/FabricatorTest.php b/tests/system/Test/FabricatorTest.php index 7cadb350e047..6f92be2aaaad 100644 --- a/tests/system/Test/FabricatorTest.php +++ b/tests/system/Test/FabricatorTest.php @@ -406,7 +406,7 @@ public function testCreateMockSetsDatabaseFields() $this->assertIsInt($result->created_at); $this->assertIsInt($result->updated_at); - $this->assertObjectHasAttribute('deleted_at', $result); + $this->assertTrue(property_exists($result, 'deleted_at')); $this->assertNull($result->deleted_at); } From b5355a40b3563d2709229b46c8796da8e244674d Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 4 Feb 2023 10:46:42 +0900 Subject: [PATCH 2/3] chore: skip AssertPropertyExistsRector --- rector.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rector.php b/rector.php index c2f296f5f8e5..797387ba4aba 100644 --- a/rector.php +++ b/rector.php @@ -40,6 +40,7 @@ use Rector\Php71\Rector\FuncCall\CountOnNullRector; use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; +use Rector\PHPUnit\Rector\MethodCall\AssertPropertyExistsRector; use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; @@ -80,6 +81,8 @@ __DIR__ . '/tests/_support', JsonThrowOnErrorRector::class, StringifyStrNeedlesRector::class, + // assertObjectHasAttribute() is deprecated + AssertPropertyExistsRector::class, RemoveUnusedPrivateMethodRector::class => [ // private method called via getPrivateMethodInvoker From fe71013b0474f2b67a204e05caa69fc084b3bb4c Mon Sep 17 00:00:00 2001 From: kenjis Date: Sat, 4 Feb 2023 11:18:06 +0900 Subject: [PATCH 3/3] chore: add UndefinedClass in psalm-baseline.xml --- psalm-baseline.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6fe1103175b9..9816237b9c82 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -172,6 +172,11 @@ UnexsistenceClass + + + SimpleConfig + + 'SomeWidget'