Passed
Push — master ( 3c0a3b...680cfc )
by Petr
07:40
created

PathTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 30
c 1
b 0
f 0
dl 0
loc 54
rs 10
1
<?php
2
3
namespace BasicTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_paths\ArrayPath;
8
use kalanis\kw_paths\Path;
9
use kalanis\kw_paths\PathsException;
10
11
12
class PathTest extends CommonTestClass
13
{
14
    public function testBasic(): void
15
    {
16
        $path = new Path();
17
        $path->setDocumentRoot('/abc/def/ghi/jkl');
18
        $path->setPathToSystemRoot('../mno/pqr');
19
        $this->assertEquals(implode(DIRECTORY_SEPARATOR, ['', 'abc', 'def', 'ghi', 'jkl']), $path->getDocumentRoot());
20
        $this->assertEquals(implode(DIRECTORY_SEPARATOR, ['..', 'mno', 'pqr']), $path->getPathToSystemRoot());
21
    }
22
23
    /**
24
     * @throws PathsException
25
     */
26
    public function testArrayPath1(): void
27
    {
28
        $path = new ArrayPath();
29
        $path->setString(implode(DIRECTORY_SEPARATOR, ['', 'abc', '..', 'def.ghi', '.', 'jkl', '', 'mno.pqr']));
30
        $this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl', 'mno.pqr']), (string) $path);
31
        $this->assertEquals('mno.pqr', $path->getFileName());
32
        $this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl']), $path->getStringDirectory());
33
        $this->assertEquals(implode(DIRECTORY_SEPARATOR, ['abc', 'def.ghi', 'jkl', 'mno.pqr']), $path->getString());
34
        $this->assertEquals(['abc', 'def.ghi', 'jkl'], $path->getArrayDirectory());
35
        $this->assertEquals(['abc', 'def.ghi', 'jkl', 'mno.pqr'], $path->getArray());
36
    }
37
38
    /**
39
     * @throws PathsException
40
     */
41
    public function testArrayPath2(): void
42
    {
43
        $path = new ArrayPath();
44
        $path->setArray(['', '.', '..', '.', '']); // content NOPE!
45
        $this->assertEquals('', (string) $path);
46
        $this->assertEquals('', $path->getFileName());
47
        $this->assertEquals('', $path->getStringDirectory());
48
        $this->assertEquals('', $path->getString());
49
        $this->assertEquals([], $path->getArrayDirectory());
50
        $this->assertEquals([], $path->getArray());
51
    }
52
53
    /**
54
     * @throws PathsException
55
     */
56
    public function testArrayPath3(): void
57
    {
58
        $path = new ArrayPath();
59
        $path->setString('abcdef');
60
        $this->assertEquals('abcdef', (string) $path);
61
        $this->assertEquals('abcdef', $path->getFileName());
62
        $this->assertEquals('', $path->getStringDirectory());
63
        $this->assertEquals('abcdef', $path->getString());
64
        $this->assertEquals([], $path->getArrayDirectory());
65
        $this->assertEquals(['abcdef'], $path->getArray());
66
    }
67
}
68