Skip to content

Commit f9d09b9

Browse files
authored
Merge pull request #7220 from kenjis/fix-test-BaseCommandTest
test: replace deprecated assertObjectHasAttribute()
2 parents f7ab736 + fe71013 commit f9d09b9

File tree

7 files changed

+16
-7
lines changed

7 files changed

+16
-7
lines changed

psalm-baseline.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@
172172
<code>UnexsistenceClass</code>
173173
</UndefinedClass>
174174
</file>
175+
<file src="tests/system/Config/BaseConfigTest.php">
176+
<UndefinedClass occurrences="1">
177+
<code>SimpleConfig</code>
178+
</UndefinedClass>
179+
</file>
175180
<file src="tests/system/Config/FactoriesTest.php">
176181
<UndefinedClass occurrences="1">
177182
<code>'SomeWidget'</code>

rector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
4141
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
4242
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
43+
use Rector\PHPUnit\Rector\MethodCall\AssertPropertyExistsRector;
4344
use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector;
4445
use Rector\PHPUnit\Set\PHPUnitSetList;
4546
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
@@ -80,6 +81,8 @@
8081
__DIR__ . '/tests/_support',
8182
JsonThrowOnErrorRector::class,
8283
StringifyStrNeedlesRector::class,
84+
// assertObjectHasAttribute() is deprecated
85+
AssertPropertyExistsRector::class,
8386

8487
RemoveUnusedPrivateMethodRector::class => [
8588
// private method called via getPrivateMethodInvoker

tests/system/Commands/BaseCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public function testMagicIssetTrue()
3535
{
3636
$command = new AppInfo($this->logger, service('commands'));
3737

38-
$this->assertObjectHasAttribute('group', $command);
38+
$this->assertTrue(isset($command->group));
3939
}
4040

4141
public function testMagicIssetFalse()
4242
{
4343
$command = new AppInfo($this->logger, service('commands'));
4444

45-
$this->assertObjectNotHasAttribute('foobar', $command);
45+
$this->assertFalse(isset($command->foobar));
4646
}
4747

4848
public function testMagicGet()

tests/system/Config/BaseConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function testEnvironmentOverrides()
110110
// override config with shortPrefix ENV var
111111
$this->assertSame('hubbahubba', $config->delta);
112112
// incorrect env name should not inject property
113-
$this->assertObjectNotHasAttribute('notthere', $config);
113+
$this->assertFalse(property_exists($config, 'notthere'));
114114
// empty ENV var should not affect config setting
115115
$this->assertSame('pineapple', $config->fruit);
116116
// non-empty ENV var should overrideconfig setting

tests/system/Entity/EntityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testFill()
9696

9797
$this->assertSame(123, $entity->foo);
9898
$this->assertSame('bar:234:bar', $entity->bar);
99-
$this->assertObjectNotHasAttribute('baz', $entity);
99+
$this->assertSame(4556, $entity->baz);
100100
}
101101

102102
/**

tests/system/Log/Handlers/ChromeLoggerHandlerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ public function testSetDateFormat()
6666
$config->handlers['CodeIgniter\Log\Handlers\TestHandler']['handles'] = ['critical'];
6767

6868
$logger = new ChromeLoggerHandler($config->handlers['CodeIgniter\Log\Handlers\TestHandler']);
69+
6970
$result = $logger->setDateFormat('F j, Y');
7071

71-
$this->assertObjectHasAttribute('dateFormat', $result);
72-
$this->assertObjectHasAttribute('dateFormat', $logger);
72+
$this->assertSame('F j, Y', $this->getPrivateProperty($result, 'dateFormat'));
73+
$this->assertSame('F j, Y', $this->getPrivateProperty($logger, 'dateFormat'));
7374
}
7475

7576
public function testChromeLoggerHeaderSent()

tests/system/Test/FabricatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function testCreateMockSetsDatabaseFields()
406406
$this->assertIsInt($result->created_at);
407407
$this->assertIsInt($result->updated_at);
408408

409-
$this->assertObjectHasAttribute('deleted_at', $result);
409+
$this->assertTrue(property_exists($result, 'deleted_at'));
410410
$this->assertNull($result->deleted_at);
411411
}
412412

0 commit comments

Comments
 (0)