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

namespace Rector\PHPUnit\Tests\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector\Fixture;

use Twig\Test\IntegrationTestCase;

final class SkipTwigIntegrationTestCase extends IntegrationTestCase
{
public function testIntegration($file, $message, $condition, $templates, $exception, $outputs)
{
$this->doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\Reflection\ClassReflection;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\PHPUnit\Enum\PHPUnitClassName;
use Rector\PHPUnit\NodeAnalyzer\AssertCallAnalyzer;
use Rector\PHPUnit\NodeAnalyzer\MockedVariableAnalyzer;
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\VersionBonding\Contract\ComposerPackageConstraintInterface;
use Rector\VersionBonding\ValueObject\ComposerPackageConstraint;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -43,6 +46,7 @@ public function __construct(
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly ReflectionResolver $reflectionResolver,
) {
}

Expand Down Expand Up @@ -122,6 +126,11 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
return true;
}

// the parent test case asserts in its own integration methods
if ($this->isInTwigIntegrationTestCase($classMethod)) {
return true;
}

if ($this->hasAssertingAnnotationOrAttribute($classMethod)) {
return true;
}
Expand All @@ -134,6 +143,16 @@ private function shouldSkipClassMethod(ClassMethod $classMethod): bool
return $this->mockedVariableAnalyzer->containsMockAsUsedVariable($classMethod);
}

private function isInTwigIntegrationTestCase(ClassMethod $classMethod): bool
{
$classReflection = $this->reflectionResolver->resolveClassReflection($classMethod);
if (! $classReflection instanceof ClassReflection) {
return false;
}

return $classReflection->is(PHPUnitClassName::TWIG_INTEGRATION_TEST_CASE);
}

private function hasAssertingAnnotationOrAttribute(ClassMethod $classMethod): bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
Expand Down
2 changes: 2 additions & 0 deletions src/Enum/PHPUnitClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ final class PHPUnitClassName

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

public const string TWIG_INTEGRATION_TEST_CASE = 'Twig\Test\IntegrationTestCase';

/**
* @var string[]
*/
Expand Down
23 changes: 23 additions & 0 deletions stubs/Twig/Test/IntegrationTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Twig\Test;

use PHPUnit\Framework\TestCase;

abstract class IntegrationTestCase extends TestCase
{
/**
* @param array<string, string> $templates
* @param array<string> $outputs
*/
protected function doIntegrationTest(
string $file,
string $message,
string $condition,
array $templates,
string $exception,
array $outputs,
string $deprecation = ''
): void {
}
}
Loading