From df829ad19dd389a5441f47ae303cd1ecd45908d2 Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sat, 2 May 2026 17:37:47 +0100 Subject: [PATCH] wip --- src/Plugins/Tia/FileState.php | 16 +++++++++++++--- src/Plugins/Tia/Graph.php | 9 ++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Plugins/Tia/FileState.php b/src/Plugins/Tia/FileState.php index 92dd4c03..91dc7892 100644 --- a/src/Plugins/Tia/FileState.php +++ b/src/Plugins/Tia/FileState.php @@ -9,9 +9,11 @@ use Pest\Plugins\Tia\Contracts\State; /** * @internal */ -final readonly class FileState implements State +final class FileState implements State { - private string $rootDir; + private readonly string $rootDir; + + private ?string $resolvedRoot = null; public function __construct(string $rootDir) { @@ -100,9 +102,17 @@ final readonly class FileState implements State private function resolvedRoot(): ?string { + if ($this->resolvedRoot !== null) { + return $this->resolvedRoot; + } + $resolved = @realpath($this->rootDir); - return $resolved === false ? null : $resolved; + if ($resolved === false) { + return null; + } + + return $this->resolvedRoot = $resolved; } private function ensureRoot(): bool diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index 0327658d..e23d0485 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -52,6 +52,9 @@ final class Graph /** @var array|null */ private ?array $archTestFiles = null; + /** @var array */ + private array $realpathCache = []; + public function __construct(string $projectRoot) { $real = @realpath($projectRoot); @@ -1331,7 +1334,11 @@ final class Graph $isAbsolute = str_starts_with($path, DIRECTORY_SEPARATOR) || (strlen($path) >= 2 && $path[1] === ':'); if ($isAbsolute) { - $real = @realpath($path); + if (array_key_exists($path, $this->realpathCache)) { + $real = $this->realpathCache[$path]; + } else { + $real = $this->realpathCache[$path] = @realpath($path); + } if ($real === false) { $real = $path;