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
|
|
|
|