From 61adbcfd347d03b95a061960a1080e78588acfa4 Mon Sep 17 00:00:00 2001 From: Syl Date: Sat, 14 Nov 2026 21:07:40 +0100 Subject: [PATCH] perf: cache is_dir lookups in TestRepository::make() (#2027) Co-authored-by: Sylvain Valienne <2300259+sylouuu@users.noreply.github.com> Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> --- src/Repositories/TestRepository.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Repositories/TestRepository.php b/src/Repositories/TestRepository.php index 2d6573f5..1d4df194 100644 --- a/src/Repositories/TestRepository.php +++ b/src/Repositories/TestRepository.php @@ -31,6 +31,11 @@ final class TestRepository */ private array $uses = []; + /** + * @var array + */ + private array $isDirectory = []; + /** * @var array */ @@ -156,7 +161,9 @@ final class TestRepository foreach ($this->uses as $path => $uses) { [$classOrTraits, $groups, $hooks] = $uses; - if ((! is_dir($path) && $testCase->filename === $path) || (is_dir($path) && $startsWith($testCase->filename, $path))) { + $isDirectory = $this->isDirectory[$path] ??= is_dir($path); + + if ((! $isDirectory && $testCase->filename === $path) || ($isDirectory && $startsWith($testCase->filename, $path))) { foreach ($classOrTraits as $class) { /** @var string $class */ if (class_exists($class)) {