From 4c53284d5c160a9a0570437ea3588464fa686a67 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Wed, 11 Nov 2026 09:44:17 -0500 Subject: [PATCH] Stop Pest reporting suppressed unlink warnings from the skeleton cleanup Deleting without knowing the path type means an unlink() or rmdir() is expected to fail, and Pest reports warnings even when they're silenced with `@`, so CI printed thousands of them. Swallow them with a scoped error handler instead. Co-Authored-By: Claude Opus 5.5 --- tests/DeletesDirectories.php | 15 ++++++++++++++- tests/RestoresTestbenchSkeleton.php | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) 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); } }