Passed
Push — master ( 864d7f...a4d677 )
by Sebastian
02:02
created

FileTest::testGetSegments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * This file is part of Camino.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\Camino\Path;
11
12
use Exception;
13
use PHPUnit\Framework\TestCase;
14
15
/**
16
 * Class FileTest
17
 *
18
 * @package SebastianFeldmann\Camino
19
 */
20
class FileTest extends TestCase
21
{
22
    /**
23
     * Tests File::__construct
24
     */
25
    public function testRelativePathFail(): void
26
    {
27
        $this->expectException(Exception::class);
28
29
        $file = new File('bar.txt');
0 ignored issues
show
Unused Code introduced by
The assignment to $file is dead and can be removed.
Loading history...
30
    }
31
32
    /**
33
     * Tests File::isInDirectory
34
     */
35
    public function testIsChildWithDifferentRoots(): void
36
    {
37
        $file = new File('C:\\foo\\bar.txt');
38
        $this->assertFalse($file->isInDirectory(new Directory('D:\\foo')));
39
    }
40
41
    /**
42
     * Tests File::getSegments
43
     */
44
    public function testGetSegments(): void
45
    {
46
        $this->assertCount(3, (new File('/foo/bar/baz.txt'))->getSegments());
47
        $this->assertCount(2, (new File('/foo/bar.txt'))->getSegments());
48
        $this->assertCount(1, (new File('/foo.txt'))->getSegments());
49
    }
50
51
    /**
52
     * Tests File::getPath
53
     */
54
    public function testGetDirectory(): void
55
    {
56
        $file = new File('/foo/bar/baz.txt');
57
        $this->assertEquals('/foo/bar', $file->getDirectory()->getPath());
58
    }
59
60
    /**
61
     * Tests File::getPath
62
     */
63
    public function testPathWindows(): void
64
    {
65
        $file = new File('c:\\foo\\bar\\baz');
66
        $this->assertEquals('c:\\foo\\bar\\baz', $file->getPath());
67
        $this->assertEquals(3, $file->getDepth());
68
    }
69
70
    /**
71
     * Tests File::isInDirectory
72
     */
73
    public function testIsInDirectory(): void
74
    {
75
        $file = new File('/foo/bar/baz.txt');
76
        $this->assertTrue($file->isInDirectory(new Directory('/foo')));
77
        $this->assertTrue($file->isInDirectory(new Directory('/foo/bar')));
78
        $this->assertFalse($file->isInDirectory(new Directory('/fiz')));
79
        $this->assertFalse($file->isInDirectory(new Directory('/foo/bar/buz')));
80
    }
81
}
82