|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the LGPL. For more information please see |
|
18
|
|
|
* <http://phing.info>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Phing\Test\Type; |
|
22
|
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
|
24
|
|
|
use Phing\Io\File; |
|
25
|
|
|
use Phing\Project; |
|
26
|
|
|
use Phing\Type\FileSet; |
|
27
|
|
|
use Phing\Type\Reference; |
|
28
|
|
|
use PHPUnit\Framework\TestCase; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Unit tests for AbstractFileSet. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Hans Lellelid <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
abstract class AbstractFileSetTest extends TestCase |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var Project */ |
|
38
|
|
|
private $project; |
|
39
|
|
|
|
|
40
|
|
|
public function setUp(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->project = new Project(); |
|
43
|
|
|
$this->project->setBasedir(PHING_TEST_BASE); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
final public function testEmptyElementIfIsReference(): void |
|
47
|
|
|
{ |
|
48
|
|
|
/** @var FileSet $f */ |
|
49
|
|
|
$f = $this->getInstance(); |
|
50
|
|
|
$f->setIncludes('**/*.php'); |
|
51
|
|
|
|
|
52
|
|
|
try { |
|
53
|
|
|
$f->setRefid(new Reference($this->getProject(), 'dummyref')); |
|
54
|
|
|
$this->fail( |
|
55
|
|
|
'Can add reference to ' |
|
56
|
|
|
. $f |
|
57
|
|
|
. ' with elements from setIncludes' |
|
58
|
|
|
); |
|
59
|
|
|
} catch (BuildException $be) { |
|
60
|
|
|
$this->assertEquals( |
|
61
|
|
|
'You must not specify more than one attribute ' |
|
62
|
|
|
. 'when using refid', |
|
63
|
|
|
$be->getMessage() |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$f = $this->getInstance(); |
|
68
|
|
|
$f->createPatternSet(); |
|
69
|
|
|
|
|
70
|
|
|
try { |
|
71
|
|
|
$f->setRefid(new Reference($this->getProject(), 'dummyref')); |
|
72
|
|
|
$this->fail( |
|
73
|
|
|
'Can add reference to ' |
|
74
|
|
|
. $f |
|
75
|
|
|
. ' with nested patternset element.' |
|
76
|
|
|
); |
|
77
|
|
|
} catch (BuildException $be) { |
|
78
|
|
|
$this->assertEquals( |
|
79
|
|
|
'You must not specify nested elements when ' |
|
80
|
|
|
. 'using refid', |
|
81
|
|
|
$be->getMessage() |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$f = $this->getInstance(); |
|
86
|
|
|
$f->createInclude(); |
|
87
|
|
|
|
|
88
|
|
|
try { |
|
89
|
|
|
$f->setRefid(new Reference($this->getProject(), 'dummyref')); |
|
90
|
|
|
$this->fail( |
|
91
|
|
|
'Can add reference to ' |
|
92
|
|
|
. $f |
|
93
|
|
|
. ' with nested include element.' |
|
94
|
|
|
); |
|
95
|
|
|
} catch (BuildException $be) { |
|
96
|
|
|
$this->assertEquals( |
|
97
|
|
|
'You must not specify more than one attribute ' |
|
98
|
|
|
. 'when using refid', |
|
99
|
|
|
$be->getMessage() |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$f = $this->getInstance(); |
|
104
|
|
|
$f->setRefid(new Reference($this->getProject(), 'dummyref')); |
|
105
|
|
|
|
|
106
|
|
|
try { |
|
107
|
|
|
$f->setIncludes('**/*.java'); |
|
108
|
|
|
$this->fail( |
|
109
|
|
|
'Can set includes in ' |
|
110
|
|
|
. $f |
|
111
|
|
|
. ' that is a reference.' |
|
112
|
|
|
); |
|
113
|
|
|
} catch (BuildException $be) { |
|
114
|
|
|
$this->assertEquals( |
|
115
|
|
|
'You must not specify more than one attribute ' |
|
116
|
|
|
. 'when using refid', |
|
117
|
|
|
$be->getMessage() |
|
118
|
|
|
); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
try { |
|
122
|
|
|
$f->setIncludesfile(new File('/a')); |
|
123
|
|
|
$this->fail( |
|
124
|
|
|
'Can set includesfile in ' |
|
125
|
|
|
. $f |
|
126
|
|
|
. ' that is a reference.' |
|
127
|
|
|
); |
|
128
|
|
|
} catch (BuildException $be) { |
|
129
|
|
|
$this->assertEquals( |
|
130
|
|
|
'You must not specify more than one attribute ' |
|
131
|
|
|
. 'when using refid', |
|
132
|
|
|
$be->getMessage() |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
try { |
|
137
|
|
|
$f->setExcludes('**/*.java'); |
|
138
|
|
|
$this->fail( |
|
139
|
|
|
'Can set excludes in ' |
|
140
|
|
|
. $f |
|
141
|
|
|
. ' that is a reference.' |
|
142
|
|
|
); |
|
143
|
|
|
} catch (BuildException $be) { |
|
144
|
|
|
$this->assertEquals( |
|
145
|
|
|
'You must not specify more than one attribute ' |
|
146
|
|
|
. 'when using refid', |
|
147
|
|
|
$be->getMessage() |
|
148
|
|
|
); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
try { |
|
152
|
|
|
$f->setExcludesfile(new File('/a')); |
|
153
|
|
|
$this->fail( |
|
154
|
|
|
'Can set excludesfile in ' |
|
155
|
|
|
. $f |
|
156
|
|
|
. ' that is a reference.' |
|
157
|
|
|
); |
|
158
|
|
|
} catch (BuildException $be) { |
|
159
|
|
|
$this->assertEquals( |
|
160
|
|
|
'You must not specify more than one attribute ' |
|
161
|
|
|
. 'when using refid', |
|
162
|
|
|
$be->getMessage() |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
try { |
|
167
|
|
|
$f->setDir($this->project->resolveFile('.')); |
|
168
|
|
|
$this->fail( |
|
169
|
|
|
'Can set dir in ' |
|
170
|
|
|
. $f |
|
171
|
|
|
. ' that is a reference.' |
|
172
|
|
|
); |
|
173
|
|
|
} catch (BuildException $be) { |
|
174
|
|
|
$this->assertEquals( |
|
175
|
|
|
'You must not specify more than one attribute ' |
|
176
|
|
|
. 'when using refid', |
|
177
|
|
|
$be->getMessage() |
|
178
|
|
|
); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
try { |
|
182
|
|
|
$f->setExpandSymbolicLinks(true); |
|
183
|
|
|
$this->fail( |
|
184
|
|
|
'Can expand symbolic links in ' |
|
185
|
|
|
. $f |
|
186
|
|
|
. ' that is a reference.' |
|
187
|
|
|
); |
|
188
|
|
|
} catch (BuildException $be) { |
|
189
|
|
|
$this->assertEquals( |
|
190
|
|
|
'You must not specify more than one attribute ' |
|
191
|
|
|
. 'when using refid', |
|
192
|
|
|
$be->getMessage() |
|
193
|
|
|
); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
try { |
|
197
|
|
|
$f->setFile($this->project->resolveFile(__FILE__)); |
|
198
|
|
|
$this->fail( |
|
199
|
|
|
'Can set file in ' |
|
200
|
|
|
. $f |
|
201
|
|
|
. ' that is a reference.' |
|
202
|
|
|
); |
|
203
|
|
|
} catch (BuildException $be) { |
|
204
|
|
|
$this->assertEquals( |
|
205
|
|
|
'You must not specify more than one attribute ' |
|
206
|
|
|
. 'when using refid', |
|
207
|
|
|
$be->getMessage() |
|
208
|
|
|
); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
try { |
|
212
|
|
|
$f->setCaseSensitive(true); |
|
213
|
|
|
$this->fail( |
|
214
|
|
|
'Can set case sensitive in ' |
|
215
|
|
|
. $f |
|
216
|
|
|
. ' that is a reference.' |
|
217
|
|
|
); |
|
218
|
|
|
} catch (BuildException $be) { |
|
219
|
|
|
$this->assertEquals( |
|
220
|
|
|
'You must not specify more than one attribute ' |
|
221
|
|
|
. 'when using refid', |
|
222
|
|
|
$be->getMessage() |
|
223
|
|
|
); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
try { |
|
227
|
|
|
$f->createInclude(); |
|
228
|
|
|
$this->fail( |
|
229
|
|
|
'Can add nested include in ' |
|
230
|
|
|
. $f |
|
231
|
|
|
. ' that is a reference.' |
|
232
|
|
|
); |
|
233
|
|
|
} catch (BuildException $be) { |
|
234
|
|
|
$this->assertEquals( |
|
235
|
|
|
'You must not specify nested elements when using ' |
|
236
|
|
|
. 'refid', |
|
237
|
|
|
$be->getMessage() |
|
238
|
|
|
); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
try { |
|
242
|
|
|
$f->createExclude(); |
|
243
|
|
|
$this->fail( |
|
244
|
|
|
'Can add nested exclude in ' |
|
245
|
|
|
. $f |
|
246
|
|
|
. ' that is a reference.' |
|
247
|
|
|
); |
|
248
|
|
|
} catch (BuildException $be) { |
|
249
|
|
|
$this->assertEquals( |
|
250
|
|
|
'You must not specify nested elements when using ' |
|
251
|
|
|
. 'refid', |
|
252
|
|
|
$be->getMessage() |
|
253
|
|
|
); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
try { |
|
257
|
|
|
$f->createIncludesFile(); |
|
258
|
|
|
$this->fail( |
|
259
|
|
|
'Can add nested includesfile in ' |
|
260
|
|
|
. $f |
|
261
|
|
|
. ' that is a reference.' |
|
262
|
|
|
); |
|
263
|
|
|
} catch (BuildException $be) { |
|
264
|
|
|
$this->assertEquals( |
|
265
|
|
|
'You must not specify nested elements when using ' |
|
266
|
|
|
. 'refid', |
|
267
|
|
|
$be->getMessage() |
|
268
|
|
|
); |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
try { |
|
272
|
|
|
$f->createExcludesFile(); |
|
273
|
|
|
$this->fail( |
|
274
|
|
|
'Can add nested excludesfile in ' |
|
275
|
|
|
. $f |
|
276
|
|
|
. ' that is a reference.' |
|
277
|
|
|
); |
|
278
|
|
|
} catch (BuildException $be) { |
|
279
|
|
|
$this->assertEquals( |
|
280
|
|
|
'You must not specify nested elements when using ' |
|
281
|
|
|
. 'refid', |
|
282
|
|
|
$be->getMessage() |
|
283
|
|
|
); |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
try { |
|
287
|
|
|
$f->createPatternSet(); |
|
288
|
|
|
$this->fail( |
|
289
|
|
|
'Can add nested patternset in ' |
|
290
|
|
|
. $f |
|
291
|
|
|
. ' that is a reference.' |
|
292
|
|
|
); |
|
293
|
|
|
} catch (BuildException $be) { |
|
294
|
|
|
$this->assertEquals( |
|
295
|
|
|
'You must not specify nested elements when using ' |
|
296
|
|
|
. 'refid', |
|
297
|
|
|
$be->getMessage() |
|
298
|
|
|
); |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
final public function testDoNotFailBuildOnMissingDir() |
|
303
|
|
|
{ |
|
304
|
|
|
/** @var FileSet $f */ |
|
305
|
|
|
$f = $this->getInstance(); |
|
306
|
|
|
|
|
307
|
|
|
$f->setErrorOnMissingDir(false); |
|
308
|
|
|
$f->setProject($this->getProject()); |
|
309
|
|
|
$f->setDir($this->getProject()->resolveFile('not_exists')); |
|
310
|
|
|
$ds = $f->getDirectoryScanner(); |
|
311
|
|
|
$this->assertEmpty($ds->getIncludedFiles()); |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
final public function testFailBuildOnMissingDir() |
|
315
|
|
|
{ |
|
316
|
|
|
/** @var FileSet $f */ |
|
317
|
|
|
$f = $this->getInstance(); |
|
318
|
|
|
|
|
319
|
|
|
$f->setErrorOnMissingDir(true); |
|
320
|
|
|
$f->setProject($this->getProject()); |
|
321
|
|
|
$f->setDir($this->getProject()->resolveFile('not_exists')); |
|
322
|
|
|
|
|
323
|
|
|
$this->expectException(BuildException::class); |
|
324
|
|
|
$ds = $f->getDirectoryScanner(); |
|
|
|
|
|
|
325
|
|
|
} |
|
326
|
|
|
|
|
327
|
|
|
abstract protected function getInstance(); |
|
328
|
|
|
|
|
329
|
|
|
final protected function getProject(): Project |
|
330
|
|
|
{ |
|
331
|
|
|
return $this->project; |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
|