From 27d928b684db229922d32955ae28689cbe2d39dc Mon Sep 17 00:00:00 2001 From: Matt Brown Date: Tue, 1 Dec 2020 10:26:45 -0500 Subject: [PATCH] Add failing testcase for #4705 --- tests/StubTest.php | 69 +++++++++++++++++++++++++++++++ tests/fixtures/stubs/Doctrine.php | 30 ++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 tests/fixtures/stubs/Doctrine.php diff --git a/tests/StubTest.php b/tests/StubTest.php index 1a0fecd9e..3c806baae 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -1178,4 +1178,73 @@ class StubTest extends TestCase $this->analyzeFile($file_path, new Context()); } + + public function testStubReplacingInterfaceDocblock(): void + { + $this->markTestSkipped('Tis broken'); + + $this->project_analyzer = $this->getProjectAnalyzerWithConfig( + TestConfig::loadFromXML( + dirname(__DIR__), + ' + + + + + + + + ' + ) + ); + + $this->addFile( + getcwd() . '/vendor/doctrine/import.php', + 'addFile( + $file_path, + 'getReference(I::class, 1); + }' + ); + + $this->expectException(\Psalm\Exception\CodeException::class); + $this->expectExceptionMessage('I|null'); + + $this->analyzeFile($file_path, new Context()); + } } diff --git a/tests/fixtures/stubs/Doctrine.php b/tests/fixtures/stubs/Doctrine.php new file mode 100644 index 000000000..9dea1259b --- /dev/null +++ b/tests/fixtures/stubs/Doctrine.php @@ -0,0 +1,30 @@ + $entityName + * @param mixed $id + * + * @return null|T + */ + public function getReference($entityName, $id) + { + } +} + +interface EntityManagerInterface +{ + /** + * @param class-string $entityName + * @param mixed $id + * + * @return T|null + * + * @template T + */ + public function getReference(string $entityName, $id); +}