88use PhpParser \Node \Stmt \ClassMethod ;
99use PHPStan \PhpDocParser \Ast \PhpDoc \GenericTagValueNode ;
1010use PHPStan \PhpDocParser \Ast \PhpDoc \PhpDocTagNode ;
11+ use PHPStan \Reflection \ClassReflection ;
1112use Rector \BetterPhpDocParser \PhpDocInfo \PhpDocInfoFactory ;
1213use Rector \Comments \NodeDocBlock \DocBlockUpdater ;
1314use Rector \Php80 \NodeAnalyzer \PhpAttributeAnalyzer ;
15+ use Rector \PHPUnit \Enum \PHPUnitClassName ;
1416use Rector \PHPUnit \NodeAnalyzer \AssertCallAnalyzer ;
1517use Rector \PHPUnit \NodeAnalyzer \MockedVariableAnalyzer ;
1618use Rector \PHPUnit \NodeAnalyzer \TestsNodeAnalyzer ;
1719use Rector \Rector \AbstractRector ;
20+ use Rector \Reflection \ReflectionResolver ;
1821use Rector \VersionBonding \Contract \ComposerPackageConstraintInterface ;
1922use Rector \VersionBonding \ValueObject \ComposerPackageConstraint ;
2023use 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 );
0 commit comments