mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Add failing testcase for #4705
This commit is contained in:
parent
c6d0561612
commit
27d928b684
@ -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__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
<stubs>
|
||||
<file name="tests/fixtures/stubs/Doctrine.php" />
|
||||
</stubs>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$this->addFile(
|
||||
getcwd() . '/vendor/doctrine/import.php',
|
||||
'<?php
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
interface EntityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param string $entityName The name of the entity type.
|
||||
* @param mixed $id The entity identifier.
|
||||
*
|
||||
* @return object|null The entity reference.
|
||||
*/
|
||||
public function getReference($entityName, $id);
|
||||
}
|
||||
|
||||
class EntityManager implements EntityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnType
|
||||
*/
|
||||
public function getReference($entityName, $id) {
|
||||
/**
|
||||
* @psalm-suppress InvalidReturnStatement
|
||||
*/
|
||||
return new \stdClass;
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
use Doctrine\ORM\EntityManager;
|
||||
|
||||
interface I {}
|
||||
|
||||
function em(EntityManager $em) : void {
|
||||
echo $em->getReference(I::class, 1);
|
||||
}'
|
||||
);
|
||||
|
||||
$this->expectException(\Psalm\Exception\CodeException::class);
|
||||
$this->expectExceptionMessage('I|null');
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
}
|
||||
|
30
tests/fixtures/stubs/Doctrine.php
vendored
Normal file
30
tests/fixtures/stubs/Doctrine.php
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\ORM;
|
||||
|
||||
class EntityManager implements EntityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @template T
|
||||
* @param class-string<T> $entityName
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return null|T
|
||||
*/
|
||||
public function getReference($entityName, $id)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
interface EntityManagerInterface
|
||||
{
|
||||
/**
|
||||
* @param class-string<T> $entityName
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return T|null
|
||||
*
|
||||
* @template T
|
||||
*/
|
||||
public function getReference(string $entityName, $id);
|
||||
}
|
Loading…
Reference in New Issue
Block a user