Skip to content

Commit 6ad762b

Browse files
authored
[PHPUnit60] Skip Twig IntegrationTestCase children in AddDoesNotPerformAssertionToNonAssertingTestRector (#762)
1 parent 56d5cb0 commit 6ad762b

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;
4+
5+
use Twig\Test\IntegrationTestCase;
6+
7+
final class SkipTwigIntegrationTestCase extends IntegrationTestCase
8+
{
9+
public function testIntegration($file, $message, $condition, $templates, $exception, $outputs)
10+
{
11+
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
12+
}
13+
}

‎rules/PHPUnit60/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
use PhpParser\Node\Stmt\ClassMethod;
99
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
1010
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
11+
use PHPStan\Reflection\ClassReflection;
1112
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1213
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
1314
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
15+
use Rector\PHPUnit\Enum\PHPUnitClassName;
1416
use Rector\PHPUnit\NodeAnalyzer\AssertCallAnalyzer;
1517
use Rector\PHPUnit\NodeAnalyzer\MockedVariableAnalyzer;
1618
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
1719
use Rector\Rector\AbstractRector;
20+
use Rector\Reflection\ReflectionResolver;
1821
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
1922
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
2023
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -43,6 +46,7 @@ public function __construct(
4346
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
4447
private readonly DocBlockUpdater $docBlockUpdater,
4548
private readonly PhpDocInfoFactory $phpDocInfoFactory,
49+
private readonly ReflectionResolver $reflectionResolver,
4650
) {
4751
}
4852

@@ -122,6 +126,11 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
122126
return true;
123127
}
124128

129+
// the parent test case asserts in its own integration methods
130+
if ($this->isInTwigIntegrationTestCase($classMethod)) {
131+
return true;
132+
}
133+
125134
if ($this->hasAssertingAnnotationOrAttribute($classMethod)) {
126135
return true;
127136
}
@@ -134,6 +143,16 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
134143
return $this->mockedVariableAnalyzer->containsMockAsUsedVariable($classMethod);
135144
}
136145

146+
private function isInTwigIntegrationTestCase(ClassMethod $classMethod): bool
147+
{
148+
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
149+
if (! $classReflection instanceof ClassReflection) {
150+
return false;
151+
}
152+
153+
return $classReflection->is(PHPUnitClassName::TWIG_INTEGRATION_TEST_CASE);
154+
}
155+
137156
private function hasAssertingAnnotationOrAttribute(ClassMethod $classMethod): bool
138157
{
139158
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);

‎src/Enum/PHPUnitClassName.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ final class PHPUnitClassName
3434

3535
public const string SYMFONY_TYPE_TEST_CASE = 'Symfony\Component\Form\Test\TypeTestCase';
3636

37+
public const string TWIG_INTEGRATION_TEST_CASE = 'Twig\Test\IntegrationTestCase';
38+
3739
/**
3840
* @var string[]
3941
*/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Twig\Test;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
abstract class IntegrationTestCase extends TestCase
8+
{
9+
/**
10+
* @param array<string, string> $templates
11+
* @param array<string> $outputs
12+
*/
13+
protected function doIntegrationTest(
14+
string $file,
15+
string $message,
16+
string $condition,
17+
array $templates,
18+
string $exception,
19+
array $outputs,
20+
string $deprecation = ''
21+
): void {
22+
}
23+
}

0 commit comments

Comments
 (0)