Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository methods considered pure #550

Open
derrabus opened this issue Feb 27, 2024 · 0 comments
Open

Repository methods considered pure #550

derrabus opened this issue Feb 27, 2024 · 0 comments

Comments

@derrabus
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant