phpstan/phpstan-phpunit

ArrayObject will always evaluate to false

altdovydas opened this issue · 5 comments

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.

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

It will most likely be closed after manual review.

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

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

Great, thank you :)

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.