FileTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 9
eloc 27
c 4
b 0
f 0
dl 0
loc 93
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testPathWindows() 0 5 1
A testRelativePathFail() 0 6 1
A testGetSegments() 0 5 1
A testIsChildWithDifferentRoots() 0 4 1
A testIsInDirectory() 0 7 1
A testGetDirectory() 0 4 1
A testFactoryDoesNotExists() 0 6 1
A testFactoryIsDirectory() 0 6 1
A testFactoryExists() 0 4 1
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');
30
        $this->assertEmpty($file);
31
    }
32
33
    /**
34
     * Tests File::isInDirectory
35
     */
36
    public function testIsChildWithDifferentRoots(): void
37
    {
38
        $file = new File('C:\\foo\\bar.txt');
39
        $this->assertFalse($file->isInDirectory(new Directory('D:\\foo')));
40
    }
41
42
    /**
43
     * Tests File::getSegments
44
     */
45
    public function testGetSegments(): void
46
    {
47
        $this->assertCount(3, (new File('/foo/bar/baz.txt'))->getSegments());
48
        $this->assertCount(2, (new File('/foo/bar.txt'))->getSegments());
49
        $this->assertCount(1, (new File('/foo.txt'))->getSegments());
50
    }
51
52
    /**
53
     * Tests File::getPath
54
     */
55
    public function testGetDirectory(): void
56
    {
57
        $file = new File('/foo/bar/baz.txt');
58
        $this->assertEquals('/foo/bar', $file->getDirectory()->getPath());
59
    }
60
61
    /**
62
     * Tests File::getPath
63
     */
64
    public function testPathWindows(): void
65
    {
66
        $file = new File('c:\\foo\\bar\\baz');
67
        $this->assertEquals('c:\\foo\\bar\\baz', $file->getPath());
68
        $this->assertEquals(3, $file->getDepth());
69
    }
70
71
    /**
72
     * Tests File::isInDirectory
73
     */
74
    public function testIsInDirectory(): void
75
    {
76
        $file = new File('/foo/bar/baz.txt');
77
        $this->assertTrue($file->isInDirectory(new Directory('/foo')));
78
        $this->assertTrue($file->isInDirectory(new Directory('/foo/bar')));
79
        $this->assertFalse($file->isInDirectory(new Directory('/fiz')));
80
        $this->assertFalse($file->isInDirectory(new Directory('/foo/bar/buz')));
81
    }
82
83
    /**
84
     * Tests File::create
85
     */
86
    public function testFactoryExists(): void
87
    {
88
        $file = File::create(__FILE__);
89
        $this->assertEquals(__FILE__, $file->getPath());
90
    }
91
92
    /**
93
     * Tests File::create
94
     */
95
    public function testFactoryDoesNotExists(): void
96
    {
97
        $this->expectException(Exception::class);
98
99
        $file = File::create('./foo');
100
        $this->assertEquals('should-not-be-tested', $file->getPath());
101
    }
102
103
104
    /**
105
     * Tests File::create
106
     */
107
    public function testFactoryIsDirectory(): void
108
    {
109
        $this->expectException(Exception::class);
110
111
        $file = File::create(__DIR__);
112
        $this->assertEquals('should-not-be-tested', $file->getPath());
113
    }
114
}
115