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\Task\System; |
22
|
|
|
|
23
|
|
|
use Phing\Exception\BuildException; |
24
|
|
|
use Phing\Test\Support\BuildFileTest; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @author Hans Lellelid (Phing) |
28
|
|
|
* @author Conor MacNeill (Ant) |
29
|
|
|
* |
30
|
|
|
* @internal |
31
|
|
|
*/ |
32
|
|
|
class PropertyTaskTest extends BuildFileTest |
33
|
|
|
{ |
34
|
|
|
public function setUp(): void |
35
|
|
|
{ |
36
|
|
|
$this->configureProject(PHING_TEST_BASE . '/etc/tasks/property.xml'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function test1(): void |
40
|
|
|
{ |
41
|
|
|
// should get no output at all |
42
|
|
|
$this->expectOutputAndError('test1', '', ''); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function test2(): void |
46
|
|
|
{ |
47
|
|
|
$this->expectLog('test2', 'testprop1=aa, testprop3=xxyy, testprop4=aazz'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testPropertyInFileShouldShadowExistingPropertyWithSameName(): void |
51
|
|
|
{ |
52
|
|
|
$this->expectLog(__FUNCTION__, 'http.url is http://localhost:80'); |
53
|
|
|
$this->assertPropertyEquals('http.port', '999'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testOverrideExistingPropertyWithNewProperty(): void |
57
|
|
|
{ |
58
|
|
|
$this->executeTarget(__FUNCTION__); |
59
|
|
|
$this->assertPropertyEquals('http.port', '80'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testOverrideExistingPropertyWithNewPropertyFromFile(): void |
63
|
|
|
{ |
64
|
|
|
$this->executeTarget(__FUNCTION__); |
65
|
|
|
$this->assertPropertyEquals('http.port', '80'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testPrefixSuccess(): void |
69
|
|
|
{ |
70
|
|
|
$this->executeTarget('prefix.success'); |
71
|
|
|
$this->assertEquals('80', $this->project->getProperty('server1.http.port')); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testPrefixFailure(): void |
75
|
|
|
{ |
76
|
|
|
$this->expectException(BuildException::class); |
77
|
|
|
$this->expectExceptionMessageMatches('/Prefix is only valid/'); |
78
|
|
|
|
79
|
|
|
$this->executeTarget('prefix.fail'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testFilterChain(): void |
83
|
|
|
{ |
84
|
|
|
$this->executeTarget(__FUNCTION__); |
85
|
|
|
$this->assertEquals('World', $this->project->getProperty('filterchain.test')); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function circularDefinitionTargets(): array |
89
|
|
|
{ |
90
|
|
|
return [ |
91
|
|
|
['test3'], |
92
|
|
|
['testCircularDefinition1'], |
93
|
|
|
['testCircularDefinition2'], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @dataProvider circularDefinitionTargets |
99
|
|
|
* |
100
|
|
|
* @param mixed $target |
101
|
|
|
*/ |
102
|
|
|
public function testCircularDefinitionDetection($target): void |
103
|
|
|
{ |
104
|
|
|
$this->expectException(BuildException::class); |
105
|
|
|
$this->expectExceptionMessageMatches('/was circularly defined/'); |
106
|
|
|
|
107
|
|
|
$this->executeTarget($target); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testToString(): void |
111
|
|
|
{ |
112
|
|
|
$this->expectLog(__FUNCTION__, 'sourcefiles = filehash.bin'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Inspired by @see http://www.phing.info/trac/ticket/1118 |
117
|
|
|
* This test should not throw exceptions. |
118
|
|
|
*/ |
119
|
|
|
public function testUsingPropertyTwiceInPropertyValueShouldNotThrowException(): void |
120
|
|
|
{ |
121
|
|
|
$this->expectNotToPerformAssertions(); |
122
|
|
|
$this->executeTarget(__FUNCTION__); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testRequired(): void |
126
|
|
|
{ |
127
|
|
|
$this->expectBuildException(__FUNCTION__, 'Unable to find property file.'); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|