Skip to content

Commit

Permalink
Make implementation windows safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurt Friars committed Nov 22, 2023
1 parent e37371c commit df519be
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

function setBladePath(string $path = ''): void
{
$fixtures = str(realpath(__DIR__).DIRECTORY_SEPARATOR.'Helper'.DIRECTORY_SEPARATOR.'Blade'.DIRECTORY_SEPARATOR)
$dir = realpath(__DIR__)
.DIRECTORY_SEPARATOR
.'Helper'
.DIRECTORY_SEPARATOR
.'Blade'
.DIRECTORY_SEPARATOR;

$fixtures = str($dir)
->append($path)
->rtrim(DIRECTORY_SEPARATOR)
->explode(DIRECTORY_SEPARATOR);
Expand All @@ -20,7 +27,14 @@ function setBladePath(string $path = ''): void

function setInertiaPath(string $path = ''): void
{
$fixtures = str(realpath(__DIR__).DIRECTORY_SEPARATOR.'Helper'.DIRECTORY_SEPARATOR.'Inertia'.DIRECTORY_SEPARATOR)
$dir = realpath(__DIR__)
.DIRECTORY_SEPARATOR
.'Helper'
.DIRECTORY_SEPARATOR
.'Inertia'
.DIRECTORY_SEPARATOR;

$fixtures = str($dir)
->append($path)
->rtrim(DIRECTORY_SEPARATOR)
->explode(DIRECTORY_SEPARATOR);
Expand Down Expand Up @@ -56,10 +70,27 @@ function clearInertiaPath(): void
$target = resource_path('js'.DIRECTORY_SEPARATOR.'Pages');

if (file_exists($target)) {
if (is_link($target)) {
unlink($target);
osSafeUnlink($target);
}
}

function osSafeUnlink(string $path): bool
{
if (!is_link($path)) {
return false; // Not a symlink, handle error or do nothing
}

// Check if the symlink points to a directory
if (is_dir(readlink($path))) {
// On Windows, use rmdir for directories
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return rmdir($path);
} else {
rmdir($target);
// On Unix/Linux/Mac, unlink works for directory symlinks
return unlink($path);
}
} else {
// For files, just use unlink
return unlink($path);
}
}
}

0 comments on commit df519be

Please sign in to comment.