mirror of
https://github.com/danog/psalm-plugin-phpunit.git
synced 2024-11-30 04:29:08 +01:00
Merge pull request #20 from weirdan/fix-19
Fix psalm/phpunit-psalm-plugin#19
This commit is contained in:
commit
f3e0aae3f6
@ -49,10 +49,34 @@ class TestCaseHandler implements
|
||||
$meta = (array) ($storage->custom_metadata[__NAMESPACE__] ?? []);
|
||||
if ($codebase->classExtends($name, TestCase::class) && ($meta['hasInitializers'] ?? false)) {
|
||||
$storage->suppressed_issues[] = 'MissingConstructor';
|
||||
|
||||
foreach (self::getDescendants($codebase, $name) as $dependent_name) {
|
||||
$dependent_storage = $codebase->classlike_storage_provider->get($dependent_name);
|
||||
$dependent_storage->suppressed_issues[] = 'MissingConstructor';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
private static function getDescendants(Codebase $codebase, string $name): array
|
||||
{
|
||||
if (!$codebase->classlike_storage_provider->has($name)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$storage = $codebase->classlike_storage_provider->get($name);
|
||||
$ret = [];
|
||||
|
||||
foreach ($storage->dependent_classlikes as $dependent => $_) {
|
||||
if ($codebase->classExtends($dependent, $name)) {
|
||||
$ret[] = $dependent;
|
||||
$ret = array_merge($ret, self::getDescendants($codebase, $dependent));
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -680,3 +680,70 @@ Feature: TestCase
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: Descendant of a test that has setUp produces no MissingConstructor
|
||||
Given I have the following code
|
||||
"""
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
|
||||
interface I { public function work(): int; }
|
||||
|
||||
class BaseTestCase extends TestCase {
|
||||
/** @var ObjectProphecy<I> */
|
||||
protected $i;
|
||||
|
||||
/** @return void */
|
||||
public function setUp() {
|
||||
$this->i = $this->prophesize(I::class);
|
||||
}
|
||||
}
|
||||
|
||||
class Intermediate extends BaseTestCase {}
|
||||
|
||||
class MyTestCase extends Intermediate
|
||||
{
|
||||
/** @return void */
|
||||
public function testSomething() {
|
||||
$this->i->work()->willReturn(1);;
|
||||
$i = $this->i->reveal();
|
||||
$this->assertEquals(1, $i->work());
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
||||
Scenario: Descendant of a test that has @before produces no MissingConstructor
|
||||
Given I have the following code
|
||||
"""
|
||||
use Prophecy\Prophecy\ObjectProphecy;
|
||||
|
||||
interface I { public function work(): int; }
|
||||
|
||||
class BaseTestCase extends TestCase {
|
||||
/** @var ObjectProphecy<I> */
|
||||
protected $i;
|
||||
|
||||
/**
|
||||
* @before
|
||||
* @return void
|
||||
*/
|
||||
public function myInit() {
|
||||
$this->i = $this->prophesize(I::class);
|
||||
}
|
||||
}
|
||||
|
||||
class Intermediate extends BaseTestCase {}
|
||||
|
||||
class MyTestCase extends Intermediate
|
||||
{
|
||||
/** @return void */
|
||||
public function testSomething() {
|
||||
$this->i->work()->willReturn(1);;
|
||||
$i = $this->i->reveal();
|
||||
$this->assertEquals(1, $i->work());
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
||||
|
Loading…
Reference in New Issue
Block a user