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

Wrong type detection when variable is changed by reference #4

Open
ossinkine opened this issue Dec 12, 2017 · 2 comments
Open

Wrong type detection when variable is changed by reference #4

ossinkine opened this issue Dec 12, 2017 · 2 comments
Labels

Comments

@ossinkine
Copy link

Example

class Test extends \PHPUnit\Framework\TestCase
{
    public function testAssertVariable()
    {
        $foo = null;
        $value = new \stdClass();
        $mock = $this->getMockBuilder('Foo')->setMethods(['update'])->getMock();
        $mock->method('update')->willReturnCallback(function () use (&$foo, $value) {
            $foo = $value;
        });
        $this->assertSame($value, $foo);
    }
}

$foo variable equals $value after $mock->update() call but PHPStan throws error Call to assertSame() with different types stdClass and null will always result in test failure.

@ondrejmirtes
Copy link
Member

Yes, understanding of the could could be improved on PHPStan's part. Meanwhile, you can annotate the variable:

/** @var \stdClass|null $foo */
$foo = null;

@ossinkine
Copy link
Author

Yes, I already use @var annotation as workaround, thanks

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

No branches or pull requests

2 participants