1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the LGPL. For more information please see |
17
|
|
|
* <http://phing.info>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Phing\Type; |
21
|
|
|
|
22
|
|
|
use Phing\Exception\BuildException; |
23
|
|
|
use Phing\Io\File; |
24
|
|
|
use Phing\Project; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Unit tests for AbstractFileSet. |
28
|
|
|
* |
29
|
|
|
* @author Hans Lellelid <[email protected]> |
30
|
|
|
* @package phing.types |
31
|
|
|
*/ |
32
|
|
|
abstract class AbstractFileSetTest extends \PHPUnit\Framework\TestCase |
33
|
|
|
{ |
34
|
|
|
/** @var Project */ |
35
|
|
|
private $project; |
36
|
|
|
|
37
|
|
|
public function setUp(): void |
38
|
|
|
{ |
39
|
|
|
$this->project = new Project(); |
40
|
|
|
$this->project->setBasedir(PHING_TEST_BASE); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
abstract protected function getInstance(); |
44
|
|
|
|
45
|
|
|
final protected function getProject() |
46
|
|
|
{ |
47
|
|
|
return $this->project; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
final public function testEmptyElementIfIsReference() |
51
|
|
|
{ |
52
|
|
|
/** @var FileSet $f */ |
53
|
|
|
$f = $this->getInstance(); |
54
|
|
|
$f->setIncludes("**/*.php"); |
55
|
|
|
try { |
56
|
|
|
$f->setRefid(new Reference($this->getProject(), "dummyref")); |
57
|
|
|
$this->fail( |
58
|
|
|
"Can add reference to " |
59
|
|
|
. $f |
60
|
|
|
. " with elements from setIncludes" |
61
|
|
|
); |
62
|
|
|
} catch (BuildException $be) { |
63
|
|
|
$this->assertEquals( |
64
|
|
|
"You must not specify more than one attribute " |
65
|
|
|
. "when using refid", |
66
|
|
|
$be->getMessage() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$f = $this->getInstance(); |
71
|
|
|
$f->createPatternSet(); |
72
|
|
|
try { |
73
|
|
|
$f->setRefid(new Reference($this->getProject(), "dummyref")); |
74
|
|
|
$this->fail( |
75
|
|
|
"Can add reference to " |
76
|
|
|
. $f |
77
|
|
|
. " with nested patternset element." |
78
|
|
|
); |
79
|
|
|
} catch (BuildException $be) { |
80
|
|
|
$this->assertEquals( |
81
|
|
|
"You must not specify nested elements when " |
82
|
|
|
. "using refid", |
83
|
|
|
$be->getMessage() |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$f = $this->getInstance(); |
88
|
|
|
$f->createInclude(); |
89
|
|
|
try { |
90
|
|
|
$f->setRefid(new Reference($this->getProject(), "dummyref")); |
91
|
|
|
$this->fail( |
92
|
|
|
"Can add reference to " |
93
|
|
|
. $f |
94
|
|
|
. " with nested include element." |
95
|
|
|
); |
96
|
|
|
} catch (BuildException $be) { |
97
|
|
|
$this->assertEquals( |
98
|
|
|
"You must not specify more than one attribute " |
99
|
|
|
. "when using refid", |
100
|
|
|
$be->getMessage() |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$f = $this->getInstance(); |
105
|
|
|
$f->setRefid(new Reference($this->getProject(), "dummyref")); |
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
|
|
|
try { |
271
|
|
|
$f->createExcludesFile(); |
272
|
|
|
$this->fail( |
273
|
|
|
"Can add nested excludesfile in " |
274
|
|
|
. $f |
275
|
|
|
. " that is a reference." |
276
|
|
|
); |
277
|
|
|
} catch (BuildException $be) { |
278
|
|
|
$this->assertEquals( |
279
|
|
|
"You must not specify nested elements when using " |
280
|
|
|
. "refid", |
281
|
|
|
$be->getMessage() |
282
|
|
|
); |
283
|
|
|
} |
284
|
|
|
try { |
285
|
|
|
$f->createPatternSet(); |
286
|
|
|
$this->fail( |
287
|
|
|
"Can add nested patternset in " |
288
|
|
|
. $f |
289
|
|
|
. " that is a reference." |
290
|
|
|
); |
291
|
|
|
} catch (BuildException $be) { |
292
|
|
|
$this->assertEquals( |
293
|
|
|
"You must not specify nested elements when using " |
294
|
|
|
. "refid", |
295
|
|
|
$be->getMessage() |
296
|
|
|
); |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|