added unit tests
This commit is contained in:
48
tests/Support/TestFilesystem.php
Normal file
48
tests/Support/TestFilesystem.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Support;
|
||||
|
||||
final class TestFilesystem
|
||||
{
|
||||
public static function resetUploads(): void
|
||||
{
|
||||
if (!defined('QDB_TEST_UPLOADS')) {
|
||||
return;
|
||||
}
|
||||
if (defined('QDB_PATH')) {
|
||||
if (is_file(QDB_PATH)) {
|
||||
@unlink(QDB_PATH);
|
||||
}
|
||||
if (defined('QDB_LOCK') && is_file(QDB_LOCK)) {
|
||||
@unlink(QDB_LOCK);
|
||||
}
|
||||
}
|
||||
self::rmTree(QDB_TEST_UPLOADS);
|
||||
mkdir(QDB_TEST_UPLOADS, 0755, true);
|
||||
}
|
||||
|
||||
private static function rmTree(string $dir): void
|
||||
{
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
$items = scandir($dir);
|
||||
if ($items === false) {
|
||||
return;
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
if ($item === '.' || $item === '..') {
|
||||
continue;
|
||||
}
|
||||
$path = $dir . DIRECTORY_SEPARATOR . $item;
|
||||
if (is_dir($path)) {
|
||||
self::rmTree($path);
|
||||
} else {
|
||||
@unlink($path);
|
||||
}
|
||||
}
|
||||
@rmdir($dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user