Skip to content

Commit d22b617

Browse files
committed
remove node traverser stop from AssertFuncCallToPHPUnitAssertRector
1 parent 0abb9be commit d22b617

File tree

3 files changed

+61
-34
lines changed

3 files changed

+61
-34
lines changed

rules-tests/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector/Fixture/skip_in_static_method.php.inc

Lines changed: 0 additions & 18 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class StaticAssertInStaticMethodTest extends TestCase
8+
{
9+
private static function getExceptionMessage(string $fqcn): string
10+
{
11+
$exception = new $fqcn();
12+
assert($exception instanceof \Exception);
13+
14+
return $exception->getMessage();
15+
}
16+
}
17+
18+
?>
19+
-----
20+
<?php
21+
22+
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\FuncCall\AssertFuncCallToPHPUnitAssertRector\Fixture;
23+
24+
use PHPUnit\Framework\Assert;
25+
use PHPUnit\Framework\TestCase;
26+
27+
final class StaticAssertInStaticMethodTest extends TestCase
28+
{
29+
private static function getExceptionMessage(string $fqcn): string
30+
{
31+
$exception = new $fqcn();
32+
Assert::assertInstanceOf($exception, \Exception::class);
33+
34+
return $exception->getMessage();
35+
}
36+
}
37+
38+
?>

rules/CodeQuality/Rector/FuncCall/AssertFuncCallToPHPUnitAssertRector.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Rector\PHPStan\ScopeFetcher;
2727
use Rector\PHPUnit\Enum\AssertMethod;
2828
use Rector\PHPUnit\Enum\PHPUnitClassName;
29+
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
2930
use Rector\Rector\AbstractRector;
3031
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
3132
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -36,7 +37,8 @@
3637
final class AssertFuncCallToPHPUnitAssertRector extends AbstractRector
3738
{
3839
public function __construct(
39-
private readonly ValueResolver $valueResolver
40+
private readonly ValueResolver $valueResolver,
41+
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
4042
) {
4143
}
4244

@@ -88,21 +90,26 @@ public function getNodeTypes(): array
8890
*/
8991
public function refactor(Node $node): StaticCall|MethodCall|null|int
9092
{
91-
if ($node instanceof ClassMethod) {
92-
if ($node->isStatic()) {
93-
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
94-
}
95-
96-
return null;
97-
}
98-
99-
if ($node instanceof Closure) {
100-
if ($node->static) {
101-
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
102-
}
103-
104-
return null;
105-
}
93+
// @todo handle only in test classes!
94+
95+
// most liekly hook to ClassMethod :) + traverse then
96+
$this->testsNodeAnalyzer->isInTestClass($node);
97+
98+
// if ($node instanceof ClassMethod) {
99+
// if ($node->isStatic()) {
100+
// return NodeVisitor::DONT_TRAVERSE_CHILDREN;
101+
// }
102+
//
103+
// return null;
104+
// }
105+
106+
// if ($node instanceof Closure) {
107+
// if ($node->static) {
108+
// return NodeVisitor::DONT_TRAVERSE_CHILDREN;
109+
// }
110+
//
111+
// return null;
112+
// }
106113

107114
if ($node->isFirstClassCallable()) {
108115
return null;

0 commit comments

Comments
 (0)