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
|
|
|
/** |
21
|
|
|
* Tests the SubPhing Task |
22
|
|
|
* |
23
|
|
|
* @author Siad Ardroumli <[email protected]> |
24
|
|
|
* @package phing.tasks.system |
25
|
|
|
*/ |
26
|
|
|
class SubPhingTest extends BuildFileTest |
27
|
|
|
{ |
28
|
|
|
public function setUp(): void |
29
|
|
|
{ |
30
|
|
|
$this->configureProject( |
31
|
|
|
PHING_TEST_BASE . '/etc/tasks/system/subphing.xml' |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testNoDirs(): void |
36
|
|
|
{ |
37
|
|
|
$this->expectLog(__FUNCTION__, 'No sub-builds to iterate on'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGenericPhingFile(): void |
41
|
|
|
{ |
42
|
|
|
$dir1 = $this->getProject()->resolveFile('.'); |
43
|
|
|
$dir2 = $this->getProject()->resolveFile('subphing/subphing-test1'); |
44
|
|
|
$dir3 = $this->getProject()->resolveFile('subphing/subphing-test2'); |
45
|
|
|
|
46
|
|
|
$this->baseDirs( |
47
|
|
|
__FUNCTION__, |
48
|
|
|
[ |
49
|
|
|
$dir1->getAbsolutePath(), |
50
|
|
|
$dir2->getAbsolutePath(), |
51
|
|
|
$dir3->getAbsolutePath() |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testPhingFile(): void |
57
|
|
|
{ |
58
|
|
|
$dir1 = $this->getProject()->resolveFile('.'); |
59
|
|
|
// basedir of subphing/subphing-test1/subphing.xml is .. |
60
|
|
|
// therefore we expect here the subphing/subphing-test1 subdirectory |
61
|
|
|
$dir2 = $this->getProject()->resolveFile('subphing/subphing-test1'); |
62
|
|
|
// basedir of subphing/subphing-test2/subphing.xml is .. |
63
|
|
|
// therefore we expect here the subphing subdirectory |
64
|
|
|
$dir3 = $this->getProject()->resolveFile('subphing'); |
65
|
|
|
|
66
|
|
|
$this->baseDirs( |
67
|
|
|
__FUNCTION__, |
68
|
|
|
[ |
69
|
|
|
$dir1->getAbsolutePath(), |
70
|
|
|
$dir2->getAbsolutePath(), |
71
|
|
|
$dir3->getAbsolutePath() |
72
|
|
|
] |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testPhingVersion() |
77
|
|
|
{ |
78
|
|
|
$this->executeTarget(__FUNCTION__); |
79
|
|
|
$this->assertPropertySet('version'); |
80
|
|
|
$this->assertPropertySet('home'); |
81
|
|
|
$this->assertPropertySet('classpath'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @param string $target |
86
|
|
|
* @param array $dirs |
87
|
|
|
*/ |
88
|
|
|
private function baseDirs(string $target, array $dirs): void |
89
|
|
|
{ |
90
|
|
|
$bc = new class ($dirs) implements BuildListener { |
91
|
|
|
private $expectedBasedirs; |
92
|
|
|
private $calls = 0; |
93
|
|
|
private $error; |
94
|
|
|
|
95
|
|
|
public function __construct(array $dirs) |
96
|
|
|
{ |
97
|
|
|
$this->expectedBasedirs = $dirs; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function buildStarted(BuildEvent $event) |
101
|
|
|
{ |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function buildFinished(BuildEvent $event) |
105
|
|
|
{ |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function targetFinished(BuildEvent $event) |
109
|
|
|
{ |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function taskStarted(BuildEvent $event) |
113
|
|
|
{ |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function taskFinished(BuildEvent $event) |
117
|
|
|
{ |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function messageLogged(BuildEvent $event) |
121
|
|
|
{ |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function targetStarted(BuildEvent $event) |
125
|
|
|
{ |
126
|
|
|
if ($event->getTarget()->getName() === '') { |
127
|
|
|
return; |
128
|
|
|
} |
129
|
|
|
if ($this->error === null) { |
130
|
|
|
try { |
131
|
|
|
BuildFileTest::assertEquals( |
132
|
|
|
$this->expectedBasedirs[$this->calls++], |
133
|
|
|
$event->getProject()->getBaseDir()->getAbsolutePath() |
134
|
|
|
); |
135
|
|
|
} catch (AssertionError $e) { |
136
|
|
|
$this->error = $e; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function getError() |
142
|
|
|
{ |
143
|
|
|
return $this->error; |
144
|
|
|
} |
145
|
|
|
}; |
146
|
|
|
$this->getProject()->addBuildListener($bc); |
147
|
|
|
$this->executeTarget($target); |
148
|
|
|
$ae = $bc->getError(); |
149
|
|
|
if ($ae !== null) { |
150
|
|
|
throw $ae; |
151
|
|
|
} |
152
|
|
|
$this->getProject()->removeBuildListener($bc); |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|