Skip to content

Commit

Permalink
Fix traits issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 11, 2020
1 parent 29740a5 commit e36d163
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'], []);
}

}
21 changes: 21 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3415-2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php declare(strict_types = 1);

namespace Bug3415;

trait Foo {
public function bar(): void {
echo "bar";
}
}

class SomeClass {
use Foo {
bar as baz;
}

public function __construct()
{
$this->bar();
$this->baz();
}
}
25 changes: 25 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-3415.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types = 1);

namespace Bug3415;

trait FooParentTrait {
public function bar(): void {
echo "bar";
}
}

trait Foo {
use FooParentTrait;
}

class SomeClass {
use Foo {
bar as baz;
}

public function __construct()
{
$this->bar();
$this->baz();
}
}

0 comments on commit e36d163

Please sign in to comment.