diff --git a/tests/DeletesDirectories.php b/tests/DeletesDirectories.php index c6c976a7a16..94420ad0ab8 100644 --- a/tests/DeletesDirectories.php +++ b/tests/DeletesDirectories.php @@ -24,7 +24,7 @@ protected function deleteDirectory(string $directory): void // each other. unlink() removes files and file symlinks, rmdir() removes // empty directories, directory symlinks and junctions without touching // what they point at, and anything surviving both has contents in it. - if (@unlink($path) || @rmdir($path)) { + if ($this->removePath($path)) { continue; } @@ -33,4 +33,17 @@ protected function deleteDirectory(string $directory): void @rmdir($directory); } + + // The failed attempt is expected, so its warning is swallowed by a handler rather than + // `@`. Pest reports warnings that `@` silenced, which would flood every run. + protected function removePath(string $path): bool + { + set_error_handler(fn () => true); + + try { + return unlink($path) || rmdir($path); + } finally { + restore_error_handler(); + } + } } diff --git a/tests/RestoresTestbenchSkeleton.php b/tests/RestoresTestbenchSkeleton.php index 98444e89dc1..8567c80f1ff 100644 --- a/tests/RestoresTestbenchSkeleton.php +++ b/tests/RestoresTestbenchSkeleton.php @@ -78,7 +78,7 @@ private function purgeTestbenchSkeleton(): void ->flatMap(fn ($path) => str_contains($path, '*') ? $files->glob($path) : [$path]); foreach ($expand($purge['files']) as $file) { - $files->delete($file); + $this->removePath($file); } foreach ($expand($purge['directories']) as $directory) { @@ -104,7 +104,7 @@ protected function restoreTestbenchSkeleton(): void // directory or a link, because a junction gives contradictory answers. unlink() // takes files and file links, rmdir() takes empty directories, directory links // and junctions without following them. - @unlink($absolute) || @rmdir($absolute); + $this->removePath($absolute); } }