Skip to content

Repository methods considered pure #550

Open
@derrabus

Description

@derrabus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions