Skip to content

Commit

Permalink
Update IntegrationTestCase.php
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed May 27, 2024
1 parent 77d9e7a commit 55b8a32
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Integration/Util/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use RecursiveIteratorIterator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder;

/**
* Class IntegrationTestCase
Expand Down Expand Up @@ -89,6 +90,39 @@ protected function deleteDir($dir)

$filesystem = new Filesystem(new LocalFilesystemAdapter('/'));

/**
* Delete symlinks first.
*
* @see https://github.com/thephpleague/flysystem/issues/1560
*/
$finder = new Finder();
$finder->in($dir);
if ($finder->hasResults()) {

/** @var \SplFileInfo[] $files */
$files = iterator_to_array($finder->getIterator());
/** @var \SplFileInfo[] $links */
$links = array_filter(
$files,
function ($file) {
return $file->isLink();
}
);

// Sort by longest filename first.
uasort($links, function ($a, $b) {
return strlen($b->getPath()) <=> strlen($a->getPath());
});

foreach ($links as $link) {
$linkPath = "{$link->getPath()}/{$link->getFilename()}";
unlink($linkPath);
if (is_readable($linkPath)) {
rmdir($linkPath);
}
}
}

$filesystem->deleteDirectory($dir);
}
}

0 comments on commit 55b8a32

Please sign in to comment.