diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index d423d80dbb..9e5018953e 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -3608,6 +3608,25 @@ public function testBug9141(): void $this->analyse([__DIR__ . '/data/bug-9141.php'], []); } + public function testBug3589(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->checkExplicitMixed = true; + + $this->analyse([__DIR__ . '/data/bug-3589.php'], [ + [ + 'Parameter #1 $fooId of method Bug3589\FooRepository::load() expects Bug3589\Id, Bug3589\Id given.', + 35, + ], + [ + 'Parameter #1 $fooId of method Bug3589\FooRepository::load() expects Bug3589\Id, Bug3589\Id given.', + 41, + ], + ]); + } + public function testBug3396(): void { $this->checkThisOnly = false; diff --git a/tests/PHPStan/Rules/Methods/data/bug-3589.php b/tests/PHPStan/Rules/Methods/data/bug-3589.php new file mode 100644 index 0000000000..f82e1bbcdd --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-3589.php @@ -0,0 +1,41 @@ + $fooId + */ + public function load(Id $fooId): Foo + { + // ... + return new Foo; + } +} + +$fooRepository = new FooRepository; + +// Expected behavior: no error +/** @var Id */ +$fooId = new Id; +$fooRepository->load($fooId); + +// Expected behavior: error on line 33 +/** @var Id */ +$barId = new Id; +$fooRepository->load($barId); + +// Expected behavior: errors +// - line 38 - Template Tpl is not specified +// - line 39 - Parameter #1 fooId of method FooRepository::load() expects Id, nonspecified Id given. +$unknownId = new Id; +$fooRepository->load($unknownId);