From e36d163a04998bd31a15dda83541222e92f4fd7b Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Wed, 10 Jun 2020 18:35:24 +0200 Subject: [PATCH] Fix traits issues --- composer.json | 2 +- .../Analyser/AnalyserIntegrationTest.php | 14 ++++++++++- .../Rules/Methods/CallMethodsRuleTest.php | 16 ++++++++++++ .../PHPStan/Rules/Methods/data/bug-3415-2.php | 21 ++++++++++++++++ tests/PHPStan/Rules/Methods/data/bug-3415.php | 25 +++++++++++++++++++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 tests/PHPStan/Rules/Methods/data/bug-3415-2.php create mode 100644 tests/PHPStan/Rules/Methods/data/bug-3415.php diff --git a/composer.json b/composer.json index 08f16ba99d..f33c6974f8 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "nette/utils": "^3.1.1", "nikic/php-parser": "^4.5.0", "ondram/ci-detector": "^3.1", - "ondrejmirtes/better-reflection": "^4.3.7", + "ondrejmirtes/better-reflection": "^4.3.8", "phpdocumentor/type-resolver": "1.0.1", "phpstan/phpdoc-parser": "^0.4.8", "react/child-process": "^0.6.1", diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index ffd596d16a..452c94acd2 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -232,6 +232,18 @@ public function testBug3405(): void $this->assertCount(0, $errors); } + public function testBug3415(): void + { + $errors = $this->runAnalyse(__DIR__ . '/../Rules/Methods/data/bug-3415.php'); + $this->assertCount(0, $errors); + } + + public function testBug3415Two(): void + { + $errors = $this->runAnalyse(__DIR__ . '/../Rules/Methods/data/bug-3415-2.php'); + $this->assertCount(0, $errors); + } + /** * @param string $file * @return \PHPStan\Analyser\Error[] @@ -246,7 +258,7 @@ private function runAnalyse(string $file): array /** @var \PHPStan\Analyser\Error[] $errors */ $errors = $analyser->analyse([$file])->getErrors(); foreach ($errors as $error) { - $this->assertSame($fileHelper->normalizePath($file), $error->getFile()); + $this->assertSame($fileHelper->normalizePath($file), $error->getFilePath()); } return $errors; diff --git a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php index 744c4955b7..2aa1760816 100644 --- a/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php +++ b/tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php @@ -1395,4 +1395,20 @@ public function testBug2600(): void ]); } + public function testBug3415(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/data/bug-3415.php'], []); + } + + public function testBug3415Two(): void + { + $this->checkThisOnly = false; + $this->checkNullables = true; + $this->checkUnionTypes = true; + $this->analyse([__DIR__ . '/data/bug-3415-2.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Methods/data/bug-3415-2.php b/tests/PHPStan/Rules/Methods/data/bug-3415-2.php new file mode 100644 index 0000000000..42391d5aba --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-3415-2.php @@ -0,0 +1,21 @@ +bar(); + $this->baz(); + } +} diff --git a/tests/PHPStan/Rules/Methods/data/bug-3415.php b/tests/PHPStan/Rules/Methods/data/bug-3415.php new file mode 100644 index 0000000000..f7246641ee --- /dev/null +++ b/tests/PHPStan/Rules/Methods/data/bug-3415.php @@ -0,0 +1,25 @@ +bar(); + $this->baz(); + } +}