|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* |
|
5
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
6
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
7
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
8
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
9
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
10
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
11
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
12
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
13
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
14
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
15
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
16
|
|
|
* |
|
17
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
18
|
|
|
* and is licensed under the LGPL. For more information please see |
|
19
|
|
|
* <http://phing.info>. |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Unit test for mappers. |
|
24
|
|
|
* |
|
25
|
|
|
* @author Hans Lellelid <[email protected]> |
|
26
|
|
|
* @author Stefan Bodewig <[email protected]> (Ant) |
|
27
|
|
|
* @package phing.types |
|
28
|
|
|
*/ |
|
29
|
|
|
class MapperTest extends \PHPUnit\Framework\TestCase |
|
30
|
|
|
{ |
|
31
|
|
|
private $project; |
|
32
|
|
|
|
|
33
|
|
|
public function setUp(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->project = new Project(); |
|
36
|
|
|
$this->project->setBasedir(__DIR__); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testEmptyElementIfIsReference() |
|
40
|
|
|
{ |
|
41
|
|
|
$m = new Mapper($this->project); |
|
42
|
|
|
$m->setFrom("*.java"); |
|
43
|
|
|
try { |
|
44
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
45
|
|
|
$this->fail("Can add reference to Mapper with from attribute set"); |
|
46
|
|
|
} catch (BuildException $be) { |
|
47
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$m = new Mapper($this->project); |
|
51
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
52
|
|
|
try { |
|
53
|
|
|
$m->setFrom("*.java"); |
|
54
|
|
|
$this->fail("Can set from in Mapper that is a reference."); |
|
55
|
|
|
} catch (BuildException $be) { |
|
56
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$m = new Mapper($this->project); |
|
60
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
61
|
|
|
try { |
|
62
|
|
|
$m->setTo("*.java"); |
|
63
|
|
|
$this->fail("Can set to in Mapper that is a reference."); |
|
64
|
|
|
} catch (BuildException $be) { |
|
65
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
|
66
|
|
|
} |
|
67
|
|
|
try { |
|
68
|
|
|
$m = new Mapper($this->project); |
|
69
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
70
|
|
|
$m->setType("glob"); |
|
71
|
|
|
$this->fail("Can set type in Mapper that is a reference."); |
|
72
|
|
|
} catch (BuildException $be) { |
|
73
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testCircularReferenceCheck() |
|
78
|
|
|
{ |
|
79
|
|
|
$m = new Mapper($this->project); |
|
80
|
|
|
$this->project->addReference("dummy", $m); |
|
81
|
|
|
$m->setRefid(new Reference($this->project, "dummy")); |
|
82
|
|
|
try { |
|
83
|
|
|
$m->getImplementation(); |
|
84
|
|
|
$this->fail("Can make Mapper a Reference to itself."); |
|
85
|
|
|
} catch (BuildException $be) { |
|
86
|
|
|
$this->assertEquals("This data type contains a circular reference.", $be->getMessage()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
// dummy1 --> dummy2 --> dummy3 --> dummy1 |
|
90
|
|
|
$m1 = new Mapper($this->project); |
|
91
|
|
|
$this->project->addReference("dummy1", $m1); |
|
92
|
|
|
$m1->setRefid(new Reference($this->project, "dummy2")); |
|
93
|
|
|
$m2 = new Mapper($this->project); |
|
94
|
|
|
$this->project->addReference("dummy2", $m2); |
|
95
|
|
|
$m2->setRefid(new Reference($this->project, "dummy3")); |
|
96
|
|
|
$m3 = new Mapper($this->project); |
|
97
|
|
|
$this->project->addReference("dummy3", $m3); |
|
98
|
|
|
$m3->setRefid(new Reference($this->project, "dummy1")); |
|
99
|
|
|
try { |
|
100
|
|
|
$m1->getImplementation(); |
|
101
|
|
|
$this->fail("Can make circular reference."); |
|
102
|
|
|
} catch (BuildException $be) { |
|
103
|
|
|
$this->assertEquals("This data type contains a circular reference.", $be->getMessage()); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// dummy1 --> dummy2 --> dummy3 |
|
107
|
|
|
// (which holds a glob mapper from "*.java" to "*.class" |
|
108
|
|
|
$m1 = new Mapper($this->project); |
|
109
|
|
|
$this->project->addReference("dummy1", $m1); |
|
110
|
|
|
$m1->setRefid(new Reference($this->project, "dummy2")); |
|
111
|
|
|
$m2 = new Mapper($this->project); |
|
112
|
|
|
$this->project->addReference("dummy2", $m2); |
|
113
|
|
|
$m2->setRefid(new Reference($this->project, "dummy3")); |
|
114
|
|
|
$m3 = new Mapper($this->project); |
|
115
|
|
|
$this->project->addReference("dummy3", $m3); |
|
116
|
|
|
|
|
117
|
|
|
$m3->setType("glob"); |
|
118
|
|
|
$m3->setFrom("*.java"); |
|
119
|
|
|
$m3->setTo("*.class"); |
|
120
|
|
|
|
|
121
|
|
|
$fmm = $m1->getImplementation(); |
|
122
|
|
|
$this->assertTrue($fmm instanceof GlobMapper, "Should be instance of GlobMapper"); |
|
123
|
|
|
$result = $fmm->main("a.java"); |
|
124
|
|
|
$this->assertEquals(1, count($result)); |
|
125
|
|
|
$this->assertEquals("a.class", $result[0]); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function testCopyTaskWithTwoFilesets() |
|
129
|
|
|
{ |
|
130
|
|
|
$t = new TaskdefForCopyTest("test1"); |
|
131
|
|
|
try { |
|
132
|
|
|
$t->setUp(); |
|
133
|
|
|
$t->test1(); |
|
134
|
|
|
$t->tearDown(); |
|
135
|
|
|
} catch (Exception $e) { |
|
136
|
|
|
$t->tearDown(); |
|
137
|
|
|
throw $e; |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testSetClasspathThrowsExceptionIfReferenceSetAlready() |
|
142
|
|
|
{ |
|
143
|
|
|
$m = new Mapper($this->project); |
|
144
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
145
|
|
|
$p = new Path($this->project); |
|
146
|
|
|
$this->expectException(BuildException::class); |
|
147
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
|
148
|
|
|
$m->setClasspath($p); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function testSetClasspath() |
|
152
|
|
|
{ |
|
153
|
|
|
$m = new Mapper($this->project); |
|
154
|
|
|
$p = new Path($this->project); |
|
155
|
|
|
$m->setClasspath($p); |
|
156
|
|
|
$f = $m->createClasspath(); |
|
157
|
|
|
$class = get_class($f); |
|
158
|
|
|
$this->assertEquals("Path", $class); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function testCreateClasspathThrowsExceptionIfReferenceAlreadySet() |
|
162
|
|
|
{ |
|
163
|
|
|
$m = new Mapper($this->project); |
|
164
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
165
|
|
|
$p = new Path($this->project); |
|
|
|
|
|
|
166
|
|
|
$this->expectException(BuildException::class); |
|
167
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
|
168
|
|
|
$f = $m->createClasspath(); |
|
|
|
|
|
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function testCallingsetClasspathRefThrowsExceptionIfReferenceAlreadySet() |
|
172
|
|
|
{ |
|
173
|
|
|
$m = new Mapper($this->project); |
|
174
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
175
|
|
|
$r2 = new Reference($this->project, "dummyref1"); |
|
176
|
|
|
$this->expectException(BuildException::class); |
|
177
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
|
178
|
|
|
$m->setClasspathRef($r2); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function testSetClassnameThrowsExceptionIfReferenceIsSet() |
|
182
|
|
|
{ |
|
183
|
|
|
$m = new Mapper($this->project); |
|
184
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
|
185
|
|
|
$this->expectException(BuildException::class); |
|
186
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
|
187
|
|
|
$m->setClassname("mapper1"); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* @package phing.mappers |
|
193
|
|
|
*/ |
|
194
|
|
|
class TaskdefForCopyTest extends BuildFileTest |
|
195
|
|
|
{ |
|
196
|
|
|
public function setUp(): void |
|
197
|
|
|
{ |
|
198
|
|
|
$this->configureProject(PHING_TEST_BASE . "/etc/types/mapper.xml"); |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function tearDown(): void |
|
202
|
|
|
{ |
|
203
|
|
|
$this->executeTarget("cleanup"); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function test1() |
|
207
|
|
|
{ |
|
208
|
|
|
$this->executeTarget("test1"); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public function test2() |
|
212
|
|
|
{ |
|
213
|
|
|
$this->executeTarget("test2"); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function test3() |
|
217
|
|
|
{ |
|
218
|
|
|
$this->executeTarget("test3"); |
|
219
|
|
|
$this->assertInLogs('php1'); |
|
220
|
|
|
$this->assertInLogs('php2'); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
public function test4() |
|
224
|
|
|
{ |
|
225
|
|
|
$this->executeTarget("test4"); |
|
226
|
|
|
$this->assertNotInLogs('.php1'); |
|
227
|
|
|
$this->assertInLogs('.php2'); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function testCutDirsMapper() |
|
231
|
|
|
{ |
|
232
|
|
|
$this->executeTarget("testCutDirsMapper"); |
|
233
|
|
|
$outputDir = $this->getProject()->getProperty('output'); |
|
234
|
|
|
$this->assertFileExists($outputDir . '/D'); |
|
235
|
|
|
$this->assertFileExists($outputDir . '/c/E'); |
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
|