Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\ClassMethod\AssertClassToThisAssertRector\Fixture;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class SkipAnonymousClass extends TestCase
{
public function testMe()
{
$repository = new class() {
public function getEntities(array $args = []): array
{
Assert::assertSame(['key' => 'value'], $args);

return [];
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeVisitor;
use Rector\PHPUnit\Enum\PHPUnitClassName;
Expand Down Expand Up @@ -88,6 +89,11 @@ public function refactor(Node $node): ?Node
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

// anonymous class has its own $this scope, that is not a test case
if ($node instanceof Class_) {
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if (! $node instanceof StaticCall) {
return null;
}
Expand Down
Loading