mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Be more resilient if we ignore that parent class does not exist
This commit is contained in:
parent
374dc65de1
commit
3ad6ec2e34
@ -603,6 +603,11 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we don't care the parent class does not exist, exit now.
|
||||||
|
if (!ClassLikeChecker::classOrInterfaceExists($parent_class, $this->getFileChecker())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self::$class_extends[$this->fq_class_name] = self::$class_extends[$this->parent_fq_class_name];
|
self::$class_extends[$this->fq_class_name] = self::$class_extends[$this->parent_fq_class_name];
|
||||||
self::$class_extends[$this->fq_class_name][$this->parent_fq_class_name] = true;
|
self::$class_extends[$this->fq_class_name][$this->parent_fq_class_name] = true;
|
||||||
|
|
||||||
|
@ -21,8 +21,6 @@ class ClassTest extends PHPUnit_Framework_TestCase
|
|||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
{
|
{
|
||||||
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7);
|
||||||
|
|
||||||
$config = new TestConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +28,7 @@ class ClassTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
$config = new TestConfig();
|
||||||
FileChecker::clearCache();
|
FileChecker::clearCache();
|
||||||
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
$this->project_checker = new \Psalm\Checker\ProjectChecker();
|
||||||
}
|
}
|
||||||
@ -532,4 +531,39 @@ class ClassTest extends PHPUnit_Framework_TestCase
|
|||||||
$context = new Context();
|
$context = new Context();
|
||||||
$file_checker->visitAndAnalyzeMethods($context);
|
$file_checker->visitAndAnalyzeMethods($context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Psalm\Exception\CodeException
|
||||||
|
* @expectedExceptionMessage UndefinedClass
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMissingParent()
|
||||||
|
{
|
||||||
|
$stmts = self::$parser->parse('<?php
|
||||||
|
class A extends B { }
|
||||||
|
');
|
||||||
|
|
||||||
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||||
|
$context = new Context();
|
||||||
|
$file_checker->visitAndAnalyzeMethods($context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testMissingParentWithFunction()
|
||||||
|
{
|
||||||
|
Config::getInstance()->setCustomErrorLevel('UndefinedClass', Config::REPORT_SUPPRESS);
|
||||||
|
|
||||||
|
$stmts = self::$parser->parse('<?php
|
||||||
|
class A extends B {
|
||||||
|
/** @return void */
|
||||||
|
public function foo() { }
|
||||||
|
}
|
||||||
|
');
|
||||||
|
|
||||||
|
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||||
|
$context = new Context();
|
||||||
|
$file_checker->visitAndAnalyzeMethods($context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user