Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/DeletesDirectories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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();
}
}
}
4 changes: 2 additions & 2 deletions tests/RestoresTestbenchSkeleton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
}

Expand Down
Loading