File: FileUtilsTests.php

package info (click to toggle)
php-arthurhoaro-web-thumbnailer 2.1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 892 kB
  • sloc: php: 3,365; makefile: 19; sh: 9
file content (60 lines) | stat: -rw-r--r-- 1,395 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

declare(strict_types=1);

namespace WebThumbnailer\Utils;

use WebThumbnailer\TestCase;

class FileUtilsTests extends TestCase
{
    /**
     * Test getPath() with a valid path.
     */
    public function testGetPathValid(): void
    {
        $path = FileUtils::getPath(__DIR__, '..', 'resources');
        $this->assertRegExp('#^/.*?/tests/resources/$#', $path);
    }

    /**
     * Test getPath() with a non existent path.
     */
    public function testGetPathNonExistent(): void
    {
        $this->assertFalse(FileUtils::getPath(__DIR__, 'nope'));
    }

    /**
     * Test getPath() with a non existent path.
     */
    public function testGetPathEmpty(): void
    {
        $this->assertFalse(FileUtils::getPath());
    }

    /**
     * Test rmdir with a valid path.
     */
    public function testRmdirValid(): void
    {
        mkdir('tmp');
        mkdir('tmp/tmp');
        touch('tmp/file');
        touch('tmp/tmp/file');
        $this->assertTrue(is_dir('tmp'));
        $this->assertTrue(is_dir('tmp/tmp'));
        FileUtils::rmdir('tmp');
        $this->assertFalse(is_dir('tmp'));
    }

    /**
     * Test rmdir with a invalid paths.
     */
    public function testRmdirInvalid(): void
    {
        $this->assertFalse(FileUtils::rmdir('nope/'));
        $this->assertFalse(FileUtils::rmdir('/'));
        $this->assertFalse(FileUtils::rmdir(''));
    }
}