Skip to content

Commit

Permalink
add more non-trait tests
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Dec 17, 2022
1 parent c6b619b commit ac100bc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
Expand Up @@ -616,7 +616,28 @@ public function testPhpUnitIntegration(): void
public function testBug3633(): void
{
$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/data/bug-3633.php'], []);
$this->analyse([__DIR__ . '/data/bug-3633.php'], [
[
'Strict comparison using === between class-string<Bug3633\HelloWorld> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
23,
],
[
'Strict comparison using === between class-string<Bug3633\OtherClass> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
35,
],
[
'Strict comparison using === between class-string<Bug3633\FinalClass> and \'Bug3633\\\HelloWorld\' will always evaluate to false.',
50,
],
[
'Strict comparison using === between class-string<Bug3633\FinalClass> and \'Bug3633\\\OtherClass\' will always evaluate to false.',
53,
],
[
'Strict comparison using === between \'Bug3633\\\FinalClass\' and \'Bug3633\\\FinalClass\' will always evaluate to true.',
59,
],
]);
}

}
35 changes: 35 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-3633.php
Expand Up @@ -17,6 +17,13 @@ class HelloWorld {
use Foo;

public function bar(): void {
if (get_class($this) === HelloWorld::class) {
echo "OK";
}
if (get_class($this) === OtherClass::class) {
echo "OK";
}

$this->test();
}
}
Expand All @@ -25,6 +32,34 @@ class OtherClass {
use Foo;

public function bar(): void {
if (get_class($this) === HelloWorld::class) {
echo "OK";
}
if (get_class($this) === OtherClass::class) {
echo "OK";
}

$this->test();
}
}

final class FinalClass {
use Foo;

public function bar(): void {
if (get_class($this) === HelloWorld::class) {
echo "OK";
}
if (get_class($this) === OtherClass::class) {
echo "OK";
}
if (get_class($this) !== FinalClass::class) {
echo "OK";
}
if (get_class($this) === FinalClass::class) {
echo "OK";
}

$this->test();
}
}

0 comments on commit ac100bc

Please sign in to comment.