Skip to content

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

@m-vo

Description

@m-vo

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.)

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