Files
azuracast-on-demand-hls/tests/Support/TemporaryDirectoryTestCase.php
T

41 lines
1005 B
PHP

<?php
declare(strict_types=1);
namespace Plugin\AzuraCastOnDemandHls\Tests\Support;
use PHPUnit\Framework\TestCase;
abstract class TemporaryDirectoryTestCase extends TestCase
{
protected string $temporaryDirectory;
protected function setUp(): void
{
parent::setUp();
$this->temporaryDirectory = sys_get_temp_dir() . '/ondemand-hls-test-' . bin2hex(random_bytes(8));
mkdir($this->temporaryDirectory, 0700, true);
}
protected function tearDown(): void
{
$this->removeTree($this->temporaryDirectory);
parent::tearDown();
}
private function removeTree(string $path): void
{
if (is_link($path) || is_file($path)) {
@unlink($path);
return;
}
if (!is_dir($path)) {
return;
}
foreach (new \FilesystemIterator($path, \FilesystemIterator::SKIP_DOTS) as $item) {
$this->removeTree($item->getPathname());
}
@rmdir($path);
}
}