@@ -43,11 +43,11 @@ public function processNode(Node $node, Scope $scope): array
43
43
44
44
$ argType = $ scope ->getType ($ node ->var );
45
45
46
- $ isTestContainerType = ( new ObjectType ( ' Symfony\Bundle\FrameworkBundle\Test\TestContainer ' ))-> isSuperTypeOf ($ argType );
46
+ $ isTestContainer = $ this -> isTestContainer ($ argType, $ scope );
47
47
$ isOldServiceSubscriber = (new ObjectType ('Symfony\Component\DependencyInjection\ServiceSubscriberInterface ' ))->isSuperTypeOf ($ argType );
48
48
$ isServiceSubscriber = $ this ->isServiceSubscriber ($ argType , $ scope );
49
49
$ isServiceLocator = (new ObjectType ('Symfony\Component\DependencyInjection\ServiceLocator ' ))->isSuperTypeOf ($ argType );
50
- if ($ isTestContainerType ->yes () || $ isOldServiceSubscriber ->yes () || $ isServiceSubscriber ->yes () || $ isServiceLocator ->yes ()) {
50
+ if ($ isTestContainer ->yes () || $ isOldServiceSubscriber ->yes () || $ isServiceSubscriber ->yes () || $ isServiceLocator ->yes ()) {
51
51
return [];
52
52
}
53
53
@@ -91,4 +91,25 @@ private function isServiceSubscriber(Type $containerType, Scope $scope): Trinary
91
91
return $ isContainerServiceSubscriber ->or ($ serviceSubscriberInterfaceType ->isSuperTypeOf ($ containedClassType )->result );
92
92
}
93
93
94
+ private function isTestContainer (Type $ containerType , Scope $ scope ): TrinaryLogic
95
+ {
96
+ $ testContainer = new ObjectType ('Symfony\Bundle\FrameworkBundle\Test\TestContainer ' );
97
+ $ isTestContainer = $ testContainer ->isSuperTypeOf ($ containerType )->result ;
98
+
99
+ $ classReflection = $ scope ->getClassReflection ();
100
+ if ($ classReflection === null ) {
101
+ return $ isTestContainer ;
102
+ }
103
+
104
+ $ containerInterface = new ObjectType ('Symfony\Component\DependencyInjection\ContainerInterface ' );
105
+ $ kernelTestCase = new ObjectType ('Symfony\Bundle\FrameworkBundle\Test\KernelTestCase ' );
106
+ $ containedClassType = new ObjectType ($ classReflection ->getName ());
107
+
108
+ return $ isTestContainer ->or (
109
+ $ containerInterface ->isSuperTypeOf ($ containerType )->result ->and (
110
+ $ kernelTestCase ->isSuperTypeOf ($ containedClassType )->result ,
111
+ ),
112
+ );
113
+ }
114
+
94
115
}
0 commit comments