Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Fix randomly failed tests on Windows v2 #75

Merged
merged 12 commits into from
Oct 31, 2024
25 changes: 17 additions & 8 deletions tests/TailwindBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,36 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfonycasts\TailwindBundle\TailwindBuilder;

class TailwindBuilderTest extends TestCase
{
protected function setUp(): void
{
$fs = new Filesystem();
if (file_exists(__DIR__.'/fixtures/var/tailwind')) {
$fs->remove(__DIR__.'/fixtures/var/tailwind');
}
$fs->mkdir(__DIR__.'/fixtures/var/tailwind');
}

protected function tearDown(): void
{
$finder = new Finder();
$finder->in(__DIR__.'/fixtures/var/tailwind')->files();
foreach ($finder as $file) {
unlink($file->getRealPath());
$fs = new Filesystem();
$i = 0;
// Sometimes "Permission denied" error happens on Windows
// so try to clean up the dir a few times
while (true) {
try {
$fs->remove(__DIR__.'/fixtures/var/tailwind');
break;
} catch (IOException $e) {
if ($i++ > 5) {
// Still not able to delete it? Throw
throw $e;
}
// Try again in a second
sleep(1);
}
}
}

Expand Down
Loading