phpstan / phpstan-phpunit

PHPUnit extensions and rules for PHPStan
MIT License
468 stars 47 forks source link

ArrayObject will always evaluate to false #167

Closed altdovydas closed 1 year ago

altdovydas commented 1 year ago

Bug report

Tested with 1.9.11 - 1.9.17 PHP 8.1.10 PHPUnit 9.5.27

Code snippet that reproduces the problem

$arrayObject = new ArrayObject(['test' => true]);
$this->assertArrayHasKey('test', $arrayObject);

Result

Call to method PHPUnit\Framework\Assert::assertArrayHasKey() with 'test' and ArrayObject<string, bool> will always evaluate to false.

Expected output

OK

Code snippet with god results

$arrayObject = new ArrayObject(['test']);
$this->assertArrayHasKey('test', $arrayObject);

Result

PHPUnit output:

Failed asserting that an array has the key 'test'.

PHPStan output:

Call to method PHPUnit\Framework\Assert::assertArrayHasKey() with 'test' and ArrayObject<int, string> will always evaluate to false.

mergeable[bot] commented 1 year ago

This bug report is missing a link to reproduction at phpstan.org/try.

It will most likely be closed after manual review.

derrabus commented 1 year ago

This issue seems to be fixed in 1.3.14 while at the same time false positives are now reported for assertNotContains().

derrabus commented 1 year ago

With 1.3.15, I cannot reproduce either of the issues. assertArrayHasKey() and assertNotContains() both seem to be understood correctly now.

ondrejmirtes commented 1 year ago

Great, thank you :)

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.