File: DirectoryCleanerTest.php

package info (click to toggle)
phpdox 0.12.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 7,672 kB
  • sloc: xml: 80,724; php: 9,167; makefile: 13
file content (43 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download | duplicates (2)
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
42
43
<?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();
    }

    /**
     * @expectedException \TheSeer\phpDox\DirectoryCleanerException
     * @expectedException \TheSeer\phpDox\DirectoryCleanerException::SecurityLimitation
     */
    public function testTryingToDeleteAShortPathThrowsException(): void {
        $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');
    }
}