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\Test\Type; |
21
|
|
|
|
22
|
|
|
use Exception; |
23
|
|
|
use Phing\Exception\BuildException; |
24
|
|
|
use Phing\Mapper\GlobMapper; |
25
|
|
|
use Phing\Project; |
26
|
|
|
use Phing\Type\Mapper; |
27
|
|
|
use Phing\Type\Path; |
28
|
|
|
use Phing\Type\Reference; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Unit test for mappers. |
32
|
|
|
* |
33
|
|
|
* @author Hans Lellelid <[email protected]> |
34
|
|
|
* @author Stefan Bodewig <[email protected]> (Ant) |
35
|
|
|
*/ |
36
|
|
|
class MapperTest extends \PHPUnit\Framework\TestCase |
37
|
|
|
{ |
38
|
|
|
private $project; |
39
|
|
|
|
40
|
|
|
public function setUp(): void |
41
|
|
|
{ |
42
|
|
|
$this->project = new Project(); |
43
|
|
|
$this->project->setBasedir(__DIR__); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testEmptyElementIfIsReference() |
47
|
|
|
{ |
48
|
|
|
$m = new Mapper($this->project); |
49
|
|
|
$m->setFrom("*.java"); |
50
|
|
|
try { |
51
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
52
|
|
|
$this->fail("Can add reference to Mapper with from attribute set"); |
53
|
|
|
} catch (BuildException $be) { |
54
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$m = new Mapper($this->project); |
58
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
59
|
|
|
try { |
60
|
|
|
$m->setFrom("*.java"); |
61
|
|
|
$this->fail("Can set from in Mapper that is a reference."); |
62
|
|
|
} catch (BuildException $be) { |
63
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$m = new Mapper($this->project); |
67
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
68
|
|
|
try { |
69
|
|
|
$m->setTo("*.java"); |
70
|
|
|
$this->fail("Can set to in Mapper that is a reference."); |
71
|
|
|
} catch (BuildException $be) { |
72
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
73
|
|
|
} |
74
|
|
|
try { |
75
|
|
|
$m = new Mapper($this->project); |
76
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
77
|
|
|
$m->setType("glob"); |
78
|
|
|
$this->fail("Can set type in Mapper that is a reference."); |
79
|
|
|
} catch (BuildException $be) { |
80
|
|
|
$this->assertEquals("You must not specify more than one attribute when using refid", $be->getMessage()); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testCircularReferenceCheck() |
85
|
|
|
{ |
86
|
|
|
$m = new Mapper($this->project); |
87
|
|
|
$this->project->addReference("dummy", $m); |
88
|
|
|
$m->setRefid(new Reference($this->project, "dummy")); |
89
|
|
|
try { |
90
|
|
|
$m->getImplementation(); |
91
|
|
|
$this->fail("Can make Mapper a Reference to itself."); |
92
|
|
|
} catch (BuildException $be) { |
93
|
|
|
$this->assertEquals("This data type contains a circular reference.", $be->getMessage()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// dummy1 --> dummy2 --> dummy3 --> dummy1 |
97
|
|
|
$m1 = new Mapper($this->project); |
98
|
|
|
$this->project->addReference("dummy1", $m1); |
99
|
|
|
$m1->setRefid(new Reference($this->project, "dummy2")); |
100
|
|
|
$m2 = new Mapper($this->project); |
101
|
|
|
$this->project->addReference("dummy2", $m2); |
102
|
|
|
$m2->setRefid(new Reference($this->project, "dummy3")); |
103
|
|
|
$m3 = new Mapper($this->project); |
104
|
|
|
$this->project->addReference("dummy3", $m3); |
105
|
|
|
$m3->setRefid(new Reference($this->project, "dummy1")); |
106
|
|
|
try { |
107
|
|
|
$m1->getImplementation(); |
108
|
|
|
$this->fail("Can make circular reference."); |
109
|
|
|
} catch (BuildException $be) { |
110
|
|
|
$this->assertEquals("This data type contains a circular reference.", $be->getMessage()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// dummy1 --> dummy2 --> dummy3 |
114
|
|
|
// (which holds a glob mapper from "*.java" to "*.class" |
115
|
|
|
$m1 = new Mapper($this->project); |
116
|
|
|
$this->project->addReference("dummy1", $m1); |
117
|
|
|
$m1->setRefid(new Reference($this->project, "dummy2")); |
118
|
|
|
$m2 = new Mapper($this->project); |
119
|
|
|
$this->project->addReference("dummy2", $m2); |
120
|
|
|
$m2->setRefid(new Reference($this->project, "dummy3")); |
121
|
|
|
$m3 = new Mapper($this->project); |
122
|
|
|
$this->project->addReference("dummy3", $m3); |
123
|
|
|
|
124
|
|
|
$m3->setType("glob"); |
125
|
|
|
$m3->setFrom("*.java"); |
126
|
|
|
$m3->setTo("*.class"); |
127
|
|
|
|
128
|
|
|
$fmm = $m1->getImplementation(); |
129
|
|
|
$this->assertTrue($fmm instanceof GlobMapper, "Should be instance of GlobMapper"); |
130
|
|
|
$result = $fmm->main("a.java"); |
131
|
|
|
$this->assertEquals(1, count($result)); |
132
|
|
|
$this->assertEquals("a.class", $result[0]); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testCopyTaskWithTwoFilesets() |
136
|
|
|
{ |
137
|
|
|
$this->expectNotToPerformAssertions(); |
138
|
|
|
$t = new TaskdefForCopyTest("test1"); |
139
|
|
|
try { |
140
|
|
|
$t->setUp(); |
141
|
|
|
$t->test1(); |
142
|
|
|
$t->tearDown(); |
143
|
|
|
} catch (Exception $e) { |
144
|
|
|
$t->tearDown(); |
145
|
|
|
throw $e; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function testSetClasspathThrowsExceptionIfReferenceSetAlready() |
150
|
|
|
{ |
151
|
|
|
$m = new Mapper($this->project); |
152
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
153
|
|
|
$p = new Path($this->project); |
154
|
|
|
$this->expectException(BuildException::class); |
155
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
156
|
|
|
$m->setClasspath($p); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testSetClasspath() |
160
|
|
|
{ |
161
|
|
|
$m = new Mapper($this->project); |
162
|
|
|
$p = new Path($this->project); |
163
|
|
|
$m->setClasspath($p); |
164
|
|
|
$f = $m->createClasspath(); |
165
|
|
|
$class = get_class($f); |
166
|
|
|
$this->assertEquals(Path::class, $class); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function testCreateClasspathThrowsExceptionIfReferenceAlreadySet() |
170
|
|
|
{ |
171
|
|
|
$m = new Mapper($this->project); |
172
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
173
|
|
|
$p = new Path($this->project); |
|
|
|
|
174
|
|
|
$this->expectException(BuildException::class); |
175
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
176
|
|
|
$f = $m->createClasspath(); |
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
public function testCallingsetClasspathRefThrowsExceptionIfReferenceAlreadySet() |
180
|
|
|
{ |
181
|
|
|
$m = new Mapper($this->project); |
182
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
183
|
|
|
$r2 = new Reference($this->project, "dummyref1"); |
184
|
|
|
$this->expectException(BuildException::class); |
185
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
186
|
|
|
$m->setClasspathRef($r2); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
public function testSetClassnameThrowsExceptionIfReferenceIsSet() |
190
|
|
|
{ |
191
|
|
|
$m = new Mapper($this->project); |
192
|
|
|
$m->setRefid(new Reference($this->project, "dummyref")); |
193
|
|
|
$this->expectException(BuildException::class); |
194
|
|
|
$this->expectExceptionMessage('You must not specify more than one attribute when using refid'); |
195
|
|
|
$m->setClassname("mapper1"); |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|