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,18 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipInStaticMethodTest extends TestCase
{
private static function getExceptionMessage(string $fqcn): string
{
$exception = new $fqcn();
assert($exception instanceof \Exception);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be handled too. The static call on Assert::.. should be used instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the method is not a test method without test prefix, I think assert is not needed. I guess static method is not a test method tho

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see 👍


return $exception->getMessage();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\NodeVisitor;
use PHPStan\Reflection\ClassReflection;
use Rector\PhpParser\Node\Value\ValueResolver;
Expand Down Expand Up @@ -78,15 +79,23 @@ public function test()
*/
public function getNodeTypes(): array
{
return [Closure::class, FuncCall::class];
return [ClassMethod::class, Closure::class, FuncCall::class];
}

/**
* @param Closure|FuncCall $node
* @param ClassMethod|Closure|FuncCall $node
* @return StaticCall|MethodCall|null|NodeVisitor::DONT_TRAVERSE_CHILDREN
*/
public function refactor(Node $node): StaticCall|MethodCall|null|int
{
if ($node instanceof ClassMethod) {
if ($node->isStatic()) {
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}

return null;
}

if ($node instanceof Closure) {
if ($node->static) {
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
Expand Down