1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Core\Tests\Manifest; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Core\Manifest\ManifestFileFinder; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests for the {@link ManifestFileFinder} class. |
10
|
|
|
*/ |
11
|
|
|
class ManifestFileFinderTest extends SapphireTest |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
protected $base; |
15
|
|
|
|
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->defaultBase = dirname(__FILE__) . '/fixtures/manifestfilefinder'; |
|
|
|
|
19
|
|
|
parent::__construct(); |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function assertFinderFinds($finder, $base, $expect, $message = null) |
23
|
|
|
{ |
24
|
|
|
if (!$base) { |
25
|
|
|
$base = $this->defaultBase; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$found = $finder->find($base); |
29
|
|
|
|
30
|
|
|
foreach ($expect as $k => $file) { |
31
|
|
|
$expect[$k] = "{$base}/$file"; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
sort($expect); |
35
|
|
|
sort($found); |
36
|
|
|
|
37
|
|
|
$this->assertEquals($expect, $found, $message); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testBasicOperation() |
41
|
|
|
{ |
42
|
|
|
$finder = new ManifestFileFinder(); |
43
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
44
|
|
|
|
45
|
|
|
$this->assertFinderFinds( |
46
|
|
|
$finder, |
47
|
|
|
null, |
48
|
|
|
array( |
49
|
|
|
'module/module.txt' |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function testIgnoreTests() |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$finder = new ManifestFileFinder(); |
57
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
58
|
|
|
$finder->setOption('ignore_tests', false); |
59
|
|
|
|
60
|
|
|
$this->assertFinderFinds( |
61
|
|
|
$finder, |
62
|
|
|
null, |
63
|
|
|
array( |
64
|
|
|
'module/module.txt', |
65
|
|
|
'module/tests/tests.txt', |
66
|
|
|
'module/code/tests/tests2.txt' |
67
|
|
|
) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function testIncludeThemes() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$finder = new ManifestFileFinder(); |
74
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
75
|
|
|
$finder->setOption('include_themes', true); |
76
|
|
|
|
77
|
|
|
$this->assertFinderFinds( |
78
|
|
|
$finder, |
79
|
|
|
null, |
80
|
|
|
array( |
81
|
|
|
'module/module.txt', |
82
|
|
|
'themes/themes.txt' |
83
|
|
|
) |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testIncludeWithRootConfigFile() |
88
|
|
|
{ |
89
|
|
|
$finder = new ManifestFileFinder(); |
90
|
|
|
|
91
|
|
|
$this->assertFinderFinds( |
92
|
|
|
$finder, |
93
|
|
|
dirname(__FILE__) . '/fixtures/manifestfilefinder_rootconfigfile', |
94
|
|
|
array( |
95
|
|
|
'code/code.txt', |
96
|
|
|
) |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testIncludeWithRootConfigFolder() |
101
|
|
|
{ |
102
|
|
|
$finder = new ManifestFileFinder(); |
103
|
|
|
|
104
|
|
|
$this->assertFinderFinds( |
105
|
|
|
$finder, |
106
|
|
|
dirname(__FILE__) . '/fixtures/manifestfilefinder_rootconfigfolder', |
107
|
|
|
array( |
108
|
|
|
'_config/config.yml', |
109
|
|
|
'code/code.txt', |
110
|
|
|
) |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: