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

Unable to resolve the template type error when calling statement twice #77

Open
m-vo opened this issue Jul 11, 2020 · 0 comments
Open

Comments

@m-vo
Copy link

m-vo commented Jul 11, 2020

I noticed a strange error "Unable to resolve the template type ExpectedType" when executing the same statement twice. Please see the following example code:

class Test extends \PHPUnit\Framework\TestCase
{
    public const A = 0;
    public const B = 1;

    public function testDemo(): void
    {
        $foo = 0;

        self::assertSame(self::A, $foo);
        self::assertSame(self::B, $foo);
        self::assertSame(self::B, $foo); // triggers error below
    }
}
Unable to resolve the template type ExpectedType in call to method static method PHPUnit\Framework\Assert::assertSame()      

I'm unsure where to start debugging this. It seems self::A appears as ConstantIntegerType while self::B as NeverType but I'm yet lacking the understanding of the internals to go further. 😄

Minimal needed config to produce the error:

services:
    -
        class: PHPStan\Type\PHPUnit\Assert\AssertStaticMethodTypeSpecifyingExtension
        tags:
            - phpstan.typeSpecifier.staticMethodTypeSpecifyingExtension

I've created a small reproducer in case you want to check it out https://github.com/m-vo/phpstan-debug-ttype (composer update && composer run phpstan).

(Please ignore the fact that this code example will also produce the message "Call to static method PHPUnit\Framework\Assert::assertSame() with 1 and 0 will always evaluate to false. " - which is of course correct. I didn't want to create a more complex example only to get rid of this.)

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