diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index b2d044559..33c88b372 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -603,6 +603,11 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc 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][$this->parent_fq_class_name] = true; diff --git a/tests/ClassTest.php b/tests/ClassTest.php index e8531acfe..08d0e7a2e 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -21,8 +21,6 @@ class ClassTest extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { self::$parser = (new ParserFactory)->create(ParserFactory::PREFER_PHP7); - - $config = new TestConfig(); } /** @@ -30,6 +28,7 @@ class ClassTest extends PHPUnit_Framework_TestCase */ public function setUp() { + $config = new TestConfig(); FileChecker::clearCache(); $this->project_checker = new \Psalm\Checker\ProjectChecker(); } @@ -532,4 +531,39 @@ class ClassTest extends PHPUnit_Framework_TestCase $context = new Context(); $file_checker->visitAndAnalyzeMethods($context); } + + /** + * @expectedException \Psalm\Exception\CodeException + * @expectedExceptionMessage UndefinedClass + * @return void + */ + public function testMissingParent() + { + $stmts = self::$parser->parse('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('project_checker, $stmts); + $context = new Context(); + $file_checker->visitAndAnalyzeMethods($context); + } }