1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
<?php declare(strict_types = 1);
namespace TheSeer\phpDox;
class DirectoryCleanerTest extends \PHPUnit\Framework\TestCase {
/**
* @var DirectoryCleaner
*/
private $cleaner;
protected function setUp(): void {
$this->cleaner = new DirectoryCleaner();
}
public function testTryingToDeleteAShortPathThrowsException(): void {
$this->expectException('\TheSeer\phpDox\DirectoryCleanerException');
$this->expectExceptionCode(\TheSeer\phpDox\DirectoryCleanerException::SecurityLimitation);
$this->cleaner->process(new FileInfo('/tmp'));
}
public function testTryingToDeleteNonExistingDirectoryJustReturns(): void {
$this->cleaner->process(new FileInfo('/not/existing/directory'));
$this->assertTrue(true);
}
public function testCanDeleteRecursiveDirectoryStructure(): void {
$base = '/tmp/' . \uniqid('dctest-');
$path = $base . '/a/b/c/d/e/f/g/h';
\mkdir($path, 0700, true);
\touch($path . '/test-h.txt');
\touch($path . '/../test-g.txt');
\touch($path . '/../../test-f.txt');
$this->assertFileExists($path . '/test-h.txt');
$this->assertDirectoryExists($path);
$this->cleaner->process(new FileInfo($base));
$this->assertFileNotExists($path . '/test-h.txt', 'File vanished');
$this->assertDirectoryNotExists($base, 'Directory vanished');
}
}
|