phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Repository methods considered pure

Open derrabus opened this issue 1 year ago • 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' => '[email protected]']));

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

$user = $userRepository->findOneBy(['email' => '[email protected]']);
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.

derrabus avatar Feb 27 '24 16:02 derrabus