99use PHPStan \Reflection \MethodReflection ;
1010use PHPStan \Type \FileTypeMapper ;
1111use PHPUnit \Framework \TestCase ;
12+ use function array_key_exists ;
1213use function str_starts_with ;
1314use function strtolower ;
1415
@@ -19,6 +20,9 @@ final class TestMethodsHelper
1920
2021 private PHPUnitVersion $ PHPUnitVersion ;
2122
23+ /** @var array<string, array<ReflectionMethod>> */
24+ private array $ methodCache = [];
25+
2226 public function __construct (
2327 FileTypeMapper $ fileTypeMapper ,
2428 PHPUnitVersion $ PHPUnitVersion
@@ -44,8 +48,11 @@ public function getTestMethodReflection(ClassReflection $classReflection, Method
4448 */
4549 public function getTestMethods (ClassReflection $ classReflection , Scope $ scope ): array
4650 {
51+ if (array_key_exists ($ classReflection ->getName (), $ this ->methodCache )) {
52+ return $ this ->methodCache [$ classReflection ->getName ()];
53+ }
4754 if (!$ classReflection ->is (TestCase::class)) {
48- return [];
55+ return $ this -> methodCache [ $ classReflection -> getName ()] = [];
4956 }
5057
5158 $ testMethods = [];
@@ -87,7 +94,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope):
8794 $ testMethods [] = $ reflectionMethod ;
8895 }
8996
90- return $ testMethods ;
97+ return $ this -> methodCache [ $ classReflection -> getName ()] = $ testMethods ;
9198 }
9299
93100 private function hasTestAnnotation (?ResolvedPhpDocBlock $ phpDoc ): bool
0 commit comments