From 9cecffe76701654559f2db886b55dcc58389937e Mon Sep 17 00:00:00 2001 From: Albert Chen Date: Tue, 14 Apr 2026 00:12:01 +0800 Subject: [PATCH] fix: fix some error tests on macOS --- src/testbench/src/Bootstrapper.php | 9 +++++++-- .../Foundation/Console/Concerns/CopyTestbenchFiles.php | 2 +- tests/Testbench/CommanderPathResolutionTest.php | 3 ++- .../Testbench/Integrations/EnvironmentVariablesTest.php | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/testbench/src/Bootstrapper.php b/src/testbench/src/Bootstrapper.php index 59f64a531..334fae302 100644 --- a/src/testbench/src/Bootstrapper.php +++ b/src/testbench/src/Bootstrapper.php @@ -130,7 +130,12 @@ protected static function createRuntimeCopy(string $sourcePath): string { $token = $_SERVER['TEST_TOKEN'] ?? $_ENV['TEST_TOKEN'] ?? 'default'; $pid = getmypid(); - $runtimePath = sys_get_temp_dir() . "/hypervel-components-testbench-{$token}-{$pid}"; + // Normalize the temp dir so that BASE_PATH matches paths derived via + // realpath() (e.g. default_skeleton_path()). On macOS, sys_get_temp_dir() + // returns /var/folders/... but glob() resolves symlinks to /private/var/... + // causing BASE_PATH to differ from app->basePath() used in test assertions. + $tempDir = realpath(sys_get_temp_dir()) ?: sys_get_temp_dir(); + $runtimePath = $tempDir . "/hypervel-components-testbench-{$token}-{$pid}"; $filesystem = static::getFilesystem(); @@ -139,7 +144,7 @@ protected static function createRuntimeCopy(string $sourcePath): string // (PPID=1, meaning the test process that spawned it exited). Orphaned // serve processes (confirmed via hypervel.pid) are killed before their // dirs are removed. - foreach (glob(sys_get_temp_dir() . "/hypervel-components-testbench-{$token}-*") as $staleDir) { + foreach (glob($tempDir . "/hypervel-components-testbench-{$token}-*") as $staleDir) { if (! $filesystem->isDirectory($staleDir)) { continue; } diff --git a/src/testbench/src/Foundation/Console/Concerns/CopyTestbenchFiles.php b/src/testbench/src/Foundation/Console/Concerns/CopyTestbenchFiles.php index a1c30a398..2fd2f4378 100644 --- a/src/testbench/src/Foundation/Console/Concerns/CopyTestbenchFiles.php +++ b/src/testbench/src/Foundation/Console/Concerns/CopyTestbenchFiles.php @@ -73,7 +73,7 @@ protected function copyTestbenchDotEnvFile( bool $resetOnTerminating = true ): void { $sourcePath = $this->resolveTestbenchSourcePath($filesystem, $workingPath); - $workingPath = $filesystem->isDirectory(join_paths($sourcePath, 'workbench')) + $workingPath = ($sourcePath !== testbench_path() && $filesystem->isDirectory(join_paths($sourcePath, 'workbench'))) ? join_paths($sourcePath, 'workbench') : $sourcePath; diff --git a/tests/Testbench/CommanderPathResolutionTest.php b/tests/Testbench/CommanderPathResolutionTest.php index af786939b..db6c6d870 100644 --- a/tests/Testbench/CommanderPathResolutionTest.php +++ b/tests/Testbench/CommanderPathResolutionTest.php @@ -25,7 +25,8 @@ protected function setUp(): void { parent::setUp(); - $this->temporaryPackagePath = sys_get_temp_dir() . '/hypervel-testbench-paths-' . getmypid() . '-' . uniqid(); + $tempDir = realpath(sys_get_temp_dir()) ?: sys_get_temp_dir(); + $this->temporaryPackagePath = $tempDir . '/hypervel-testbench-paths-' . getmypid() . '-' . uniqid(); } protected function tearDown(): void diff --git a/tests/Testbench/Integrations/EnvironmentVariablesTest.php b/tests/Testbench/Integrations/EnvironmentVariablesTest.php index 9eebe4e89..db4d570e8 100644 --- a/tests/Testbench/Integrations/EnvironmentVariablesTest.php +++ b/tests/Testbench/Integrations/EnvironmentVariablesTest.php @@ -41,7 +41,7 @@ public function itCanBeUsedWithoutHavingAnEnvironmentVariablesFile(): void $user = UserFactory::new()->create(); - $this->assertFalse(file_exists(testbench_path('workbench/.env'))); + $this->assertFalse(file_exists(testbench_path('hypervel/.env'))); $this->assertFalse(file_exists(base_path('.env'))); $this->assertInstanceOf(User::class, $user);