Passed
Push — master ( 7ed4ac...281a8d )
by Kyle
58s queued 10s
created

testGetAbsolutePathShouldReturnNullForIrregularStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PHPMD\Utility;
4
5
use PHPMD\AbstractTest;
6
use RuntimeException;
7
8
/**
9
 * @coversDefaultClass \PHPMD\Utility\Paths
10
 */
11
class PathsTest extends AbstractTest
12
{
13
    /**
14
     * @covers ::concat
15
     */
16
    public function testConcatShouldConcatTwoPaths()
17
    {
18
        static::assertSame('/foo/bar', Paths::concat('/foo', '/bar'));
19
    }
20
21
    /**
22
     * @covers ::concat
23
     */
24
    public function testConcatShouldDeduplicateSlashes()
25
    {
26
        static::assertSame('/foo/bar', Paths::concat('/foo/', '/bar'));
27
    }
28
29
    /**
30
     * @covers ::concat
31
     */
32
    public function testConcatShouldForwardAllSlashes()
33
    {
34
        static::assertSame('/foo/bar/text.txt', Paths::concat('/foo\\', '/bar\\text.txt'));
35
    }
36
37
    /**
38
     * @covers ::getRelativePath
39
     */
40
    public function testGetRelativePathShouldSubtractBasePath()
41
    {
42
        static::assertSame('bar/', Paths::getRelativePath('/foo', '/foo/bar/'));
43
    }
44
45
    /**
46
     * @covers ::getRelativePath
47
     */
48
    public function testGetRelativePathShouldTreatForwardAndBackwardSlashes()
49
    {
50
        static::assertSame('text.txt', Paths::getRelativePath('\\foo/bar\\', '/foo\\bar/text.txt'));
51
    }
52
53
    /**
54
     * @covers ::getRelativePath
55
     */
56
    public function testGetRelativePathShouldNotSubtractOnInfixPath()
57
    {
58
        static::assertSame('/foo/bar/text.txt', Paths::getRelativePath('/bar', '/foo/bar/text.txt'));
59
    }
60
61
    /**
62
     * @covers ::getAbsolutePath
63
     * @expectedException RuntimeException
64
     */
65
    public function testGetAbsolutePathShouldReturnNullForIrregularStream()
66
    {
67
        Paths::getAbsolutePath(fopen('php://stdout', 'wb'));
68
    }
69
70
    /**
71
     * @covers ::getAbsolutePath
72
     */
73
    public function testGetAbsolutePathShouldReturnPath()
74
    {
75
        $path = static::createResourceUriForTest('resource.txt');
76
        static::assertSame(realpath($path), Paths::getAbsolutePath(fopen($path, 'rb')));
77
    }
78
79
    /**
80
     * @covers ::getRealPath
81
     */
82
    public function testGetRealPathShouldReturnTheRealPath()
83
    {
84
        $path = static::createResourceUriForTest('resource.txt');
85
        static::assertSame(realpath($path), Paths::getRealPath($path));
86
    }
87
88
    /**
89
     * @covers ::getRealPath
90
     * @expectedException RuntimeException
91
     */
92
    public function testGetRealPathShouldThrowExceptionOnFailure()
93
    {
94
        Paths::getRealPath('unknown/path');
95
    }
96
}
97