phpstan/phpstan-doctrine

Repository methods considered pure

derrabus opened this issue · 0 comments

PHPStan 1.10.59, phpstan-doctrine 1.3.62, phpstan-phpunit 1.3.16, bleeding edge + strict rules

I have a piece of code in my tests that roughly looks like this:

self::assertNull($userRepository->findOneBy(['email' => 'foo@example.com']));

// Calls to the class I'm testing that should lead to new database records.

$user = $userRepository->findOneBy(['email' => 'foo@example.com']);
self::assertInstanceOf(User::class, $staff2);

PHPStan emits an error:

Call to static method PHPUnit\Framework\Assert::assertInstanceOf() with 'App\Entity\User' and null will always evaluate to false.

If I remove the first assertNull() call, the error is gone. Apparently, PHPStan treats the findOneBy() call as pure which is a mistake from my POV.