1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class SelectorUtilsTest |
7
|
|
|
* |
8
|
|
|
* Test cases for SelectorUtils |
9
|
|
|
*/ |
10
|
|
|
class SelectorUtilsTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var SelectorUtils |
14
|
|
|
*/ |
15
|
|
|
private $selectorUtils; |
16
|
|
|
|
17
|
|
|
protected function setUp(): void |
18
|
|
|
{ |
19
|
|
|
$this->selectorUtils = SelectorUtils::getInstance(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Inspired by @link https://www.phing.info/trac/ticket/796 |
24
|
|
|
*/ |
25
|
|
|
public function testDoNotIncludeSelfWhenMatchingSubdirectoriesAndFiles() |
26
|
|
|
{ |
27
|
|
|
$result = $this->selectorUtils->matchPath("**/*", ""); |
28
|
|
|
$this->assertFalse($result); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Inspired by @link https://www.phing.info/trac/ticket/1264 |
33
|
|
|
*/ |
34
|
|
|
public function testDoNotIncludePrefix() |
35
|
|
|
{ |
36
|
|
|
$this->assertFalse($this->selectorUtils->matchPath("**/example.php", |
37
|
|
|
"vendor/phplot/phplot/contrib/color_range.example.php")); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Inspired by @link https://github.com/phingofficial/phing/issues/593 |
42
|
|
|
*/ |
43
|
|
|
public function testIncludePathsInBase() |
44
|
|
|
{ |
45
|
|
|
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { |
46
|
|
|
$this->assertTrue($this->selectorUtils->matchPath('**\domain.ext\**', 'domain.ext\foo')); |
47
|
|
|
} else { |
48
|
|
|
$this->assertTrue($this->selectorUtils->matchPath("**/domain.ext/**", "domain.ext/foo")); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testRemoveWhitespace() |
53
|
|
|
{ |
54
|
|
|
$ret = $this->selectorUtils::removeWhitespace(" foo "); |
55
|
|
|
$this->assertEquals("foo", $ret); |
56
|
|
|
$ret = $this->selectorUtils::removeWhitespace("\tbar\t"); |
57
|
|
|
$this->assertEquals("bar", $ret); |
58
|
|
|
$ret = $this->selectorUtils::removeWhitespace("\nfoo\t"); |
59
|
|
|
$this->assertEquals("foo", $ret); |
60
|
|
|
$ret = $this->selectorUtils::removeWhitespace("\rfoo\r"); |
61
|
|
|
$this->assertEquals("foo", $ret); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Non Existing Source File Causes Out Of Date To Return False |
66
|
|
|
* |
67
|
|
|
* @return void |
68
|
|
|
*/ |
69
|
|
|
public function testNonExistingSourceFileCausesOutOfDateToReturnFalse() |
70
|
|
|
{ |
71
|
|
|
$sourceFile = new PhingFile("doesNotExist"); |
72
|
|
|
$targetFile = new PhingFile(__FILE__); |
73
|
|
|
$ret = $this->selectorUtils::isOutOfDate($sourceFile, $targetFile, 0); |
74
|
|
|
$this->assertEquals(false, $ret); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function testNonExistingTargetFileCausesOutOfDateToReturnTrue() |
78
|
|
|
{ |
79
|
|
|
$sourceFile = new PhingFile(__FILE__); |
80
|
|
|
$targetFile = new PhingFile("doesNotExist"); |
81
|
|
|
$ret = $this->selectorUtils::isOutOfDate($sourceFile, $targetFile, 0); |
82
|
|
|
$this->assertEquals(true, $ret); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Test Granularity of isOutOfDate |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function testOutOfDate() |
91
|
|
|
{ |
92
|
|
|
$source = new PhingFile(tempnam(sys_get_temp_dir(), 'src')); |
93
|
|
|
sleep(3); |
94
|
|
|
$target = new PhingFile(tempnam(sys_get_temp_dir(), 'tgt')); |
95
|
|
|
$ret = $this->selectorUtils::isOutOfDate($source, $target, 20); |
96
|
|
|
$this->assertEquals(false, $ret); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|