Skip to content

Analysis of assertSame cannot infer type if expected value is constant from symfony Response object #133

@keulinho

Description

@keulinho

Since the phpstan update to 1.7.0, assertSame throws an error when used with symfonys Response::HTTP_*constants. As the error only appears forassertSamecalls and not others e.g.assertEquals` I think the error may lay in this extension instead of in phpstan itself.

Error message

Parameter #1 $expected of method PHPUnit\Framework\Assert::assertSame() contains unresolvable type.

How to reproduce

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Response;

class Test extends TestCase
{
    public function testThrowsAnError(): void
    {
         $this->assertSame(Response::HTTP_OK, 200);   
    }

    public function testThrowsNoError(): void
    {
         $this->assertEquals(Response::HTTP_OK, 200);   
         $this->assertSame(\PDO::PARAM_BOOL, 5);   
    }
}

Environment

PHP: 8.1.5
phpstan: 1.7.0
phpstan-phpunit: 1.1.1
phpunit: 9.5.20

Other extensions:
phpstan-symfony: 1.1.8
phpstan-doctrine: 1.3.5

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