Skip to content

Commit e4c5a22

Browse files
committed
TestMethodsHelper - class methods cache
1 parent 80091f9 commit e4c5a22

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Rules/PHPUnit/TestMethodsHelper.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPStan\Reflection\MethodReflection;
1010
use PHPStan\Type\FileTypeMapper;
1111
use PHPUnit\Framework\TestCase;
12+
use function array_key_exists;
1213
use function str_starts_with;
1314
use 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

Comments
 (0)