Skip to content

Commit b71925f

Browse files
committed
skip test case and test classes as handled by PHPUnit
1 parent 0fcb26e commit b71925f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector\Fixture;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class SkipInCaseOfTest extends TestCase
8+
{
9+
}

rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public function refactor(Node $node): ?Node
7676
return null;
7777
}
7878

79+
if ($this->shouldSkipClass($node)) {
80+
return null;
81+
}
82+
7983
// it already has a constructor, skip as it might require specific tweaking
8084
if ($node->getMethod(MethodName::CONSTRUCT)) {
8185
return null;
@@ -96,4 +100,24 @@ private function createParentConstructorCall(): StaticCall
96100

97101
return new StaticCall(new Name('parent'), MethodName::CONSTRUCT, [new Arg($staticClassConstFetch)]);
98102
}
103+
104+
private function shouldSkipClass(Class_ $class): bool
105+
{
106+
if ($class->isAbstract()) {
107+
return true;
108+
}
109+
110+
if ($class->isAnonymous()) {
111+
return true;
112+
}
113+
114+
$className = $this->getName($class);
115+
116+
// loaded automatically by PHPUnit
117+
if (str_ends_with($className, 'Test')) {
118+
return true;
119+
}
120+
121+
return str_ends_with($className, 'TestCase');
122+
}
99123
}

0 commit comments

Comments
 (0)