|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\Core\Tests\Manifest; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Core\Manifest\ManifestFileFinder; |
|
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
7
|
|
|
use SilverStripe\Core\Manifest\Module; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Tests for the {@link ManifestFileFinder} class. |
|
11
|
|
|
*/ |
|
12
|
|
|
class ManifestFileFinderTest extends SapphireTest |
|
13
|
|
|
{ |
|
14
|
|
|
protected $defaultBase; |
|
15
|
|
|
|
|
16
|
|
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->defaultBase = __DIR__ . '/fixtures/manifestfilefinder'; |
|
19
|
|
|
parent::__construct(); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Test that the finder can find the given files |
|
24
|
|
|
* |
|
25
|
|
|
* @param ManifestFileFinder $finder |
|
26
|
|
|
* @param string $base |
|
27
|
|
|
* @param array $expect |
|
28
|
|
|
* @param string $message |
|
29
|
|
|
*/ |
|
30
|
|
|
public function assertFinderFinds(ManifestFileFinder $finder, $base, $expect, $message = '') |
|
31
|
|
|
{ |
|
32
|
|
|
if (!$base) { |
|
33
|
|
|
$base = $this->defaultBase; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$found = $finder->find($base); |
|
37
|
|
|
|
|
38
|
|
|
foreach ($expect as $k => $file) { |
|
39
|
|
|
$expect[$k] = "{$base}/$file"; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
sort($expect); |
|
43
|
|
|
sort($found); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertEquals($expect, $found, $message); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testBasicOperation() |
|
49
|
|
|
{ |
|
50
|
|
|
$finder = new ManifestFileFinder(); |
|
51
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertFinderFinds( |
|
54
|
|
|
$finder, |
|
55
|
|
|
null, |
|
56
|
|
|
[ |
|
57
|
|
|
'module/module.txt', |
|
58
|
|
|
'vendor/myvendor/thismodule/module.txt', |
|
59
|
|
|
'vendor/myvendor/phpunit5module/code/logic.txt', |
|
60
|
|
|
'vendor/myvendor/phpunit9module/code/logic.txt', |
|
61
|
|
|
] |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testIgnoreTests() |
|
66
|
|
|
{ |
|
67
|
|
|
$finder = new ManifestFileFinder(); |
|
68
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
|
69
|
|
|
$finder->setOption('ignore_tests', false); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertFinderFinds( |
|
72
|
|
|
$finder, |
|
73
|
|
|
null, |
|
74
|
|
|
[ |
|
75
|
|
|
'module/module.txt', |
|
76
|
|
|
'module/tests/tests.txt', |
|
77
|
|
|
'module/code/tests/tests2.txt', |
|
78
|
|
|
'vendor/myvendor/thismodule/module.txt', |
|
79
|
|
|
'vendor/myvendor/thismodule/tests/tests.txt', |
|
80
|
|
|
'vendor/myvendor/thismodule/code/tests/tests2.txt', |
|
81
|
|
|
'vendor/myvendor/phpunit5module/code/logic.txt', |
|
82
|
|
|
'vendor/myvendor/phpunit5module/tests/phpunit5tests.txt', |
|
83
|
|
|
'vendor/myvendor/phpunit9module/code/logic.txt', |
|
84
|
|
|
'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', |
|
85
|
|
|
] |
|
86
|
|
|
); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testIgnorePHPUnit5Tests() |
|
90
|
|
|
{ |
|
91
|
|
|
$finder = new ManifestFileFinder(); |
|
92
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
|
93
|
|
|
$finder->setOption('ignore_tests', false); |
|
94
|
|
|
$finder->setOption('ignored_ci_configs', [Module::CI_PHPUNIT_FIVE]); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertFinderFinds( |
|
97
|
|
|
$finder, |
|
98
|
|
|
null, |
|
99
|
|
|
[ |
|
100
|
|
|
'module/module.txt', |
|
101
|
|
|
'module/tests/tests.txt', |
|
102
|
|
|
'module/code/tests/tests2.txt', |
|
103
|
|
|
'vendor/myvendor/thismodule/module.txt', |
|
104
|
|
|
'vendor/myvendor/thismodule/tests/tests.txt', |
|
105
|
|
|
'vendor/myvendor/thismodule/code/tests/tests2.txt', |
|
106
|
|
|
'vendor/myvendor/phpunit5module/code/logic.txt', |
|
107
|
|
|
'vendor/myvendor/phpunit9module/code/logic.txt', |
|
108
|
|
|
'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', |
|
109
|
|
|
] |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function testIgnoreNonePHPUnit9Tests() |
|
114
|
|
|
{ |
|
115
|
|
|
$finder = new ManifestFileFinder(); |
|
116
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
|
117
|
|
|
$finder->setOption('ignore_tests', false); |
|
118
|
|
|
$finder->setOption('ignored_ci_configs', [Module::CI_PHPUNIT_FIVE, Module::CI_UNKNOWN]); |
|
119
|
|
|
|
|
120
|
|
|
$this->assertFinderFinds( |
|
121
|
|
|
$finder, |
|
122
|
|
|
null, |
|
123
|
|
|
[ |
|
124
|
|
|
'module/module.txt', |
|
125
|
|
|
'module/tests/tests.txt', |
|
126
|
|
|
'module/code/tests/tests2.txt', |
|
127
|
|
|
'vendor/myvendor/thismodule/module.txt', |
|
128
|
|
|
'vendor/myvendor/phpunit5module/code/logic.txt', |
|
129
|
|
|
'vendor/myvendor/phpunit9module/code/logic.txt', |
|
130
|
|
|
'vendor/myvendor/phpunit9module/tests/phpunit9tests.txt', |
|
131
|
|
|
] |
|
132
|
|
|
); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function testIncludeThemes() |
|
136
|
|
|
{ |
|
137
|
|
|
$finder = new ManifestFileFinder(); |
|
138
|
|
|
$finder->setOption('name_regex', '/\.txt$/'); |
|
139
|
|
|
$finder->setOption('include_themes', true); |
|
140
|
|
|
|
|
141
|
|
|
$this->assertFinderFinds( |
|
142
|
|
|
$finder, |
|
143
|
|
|
null, |
|
144
|
|
|
[ |
|
145
|
|
|
'module/module.txt', |
|
146
|
|
|
'themes/themes.txt', |
|
147
|
|
|
'vendor/myvendor/thismodule/module.txt', |
|
148
|
|
|
'vendor/myvendor/phpunit5module/code/logic.txt', |
|
149
|
|
|
'vendor/myvendor/phpunit9module/code/logic.txt', |
|
150
|
|
|
] |
|
151
|
|
|
); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
public function testIncludeWithRootConfigFile() |
|
155
|
|
|
{ |
|
156
|
|
|
$finder = new ManifestFileFinder(); |
|
157
|
|
|
|
|
158
|
|
|
$this->assertFinderFinds( |
|
159
|
|
|
$finder, |
|
160
|
|
|
__DIR__ . '/fixtures/manifestfilefinder_rootconfigfile', |
|
161
|
|
|
[ 'code/code.txt' ] |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function testIncludeWithRootConfigFolder() |
|
166
|
|
|
{ |
|
167
|
|
|
$finder = new ManifestFileFinder(); |
|
168
|
|
|
|
|
169
|
|
|
$this->assertFinderFinds( |
|
170
|
|
|
$finder, |
|
171
|
|
|
__DIR__ . '/fixtures/manifestfilefinder_rootconfigfolder', |
|
172
|
|
|
[ |
|
173
|
|
|
'_config/config.yml', |
|
174
|
|
|
'code/code.txt', |
|
175
|
|
|
] |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|