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
|
|
|
* |
22
|
|
|
* @author Bernhard Mendl <[email protected]> |
23
|
|
|
* @package phing.tasks.ext.sonar |
24
|
|
|
*/ |
25
|
|
|
class SonarConfigurationFileParserTest extends BuildFileTest |
26
|
|
|
{ |
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
$buildXmlFile = PHING_TEST_BASE . '/etc/tasks/ext/sonar/ConfigurationFileParserTest.xml'; |
30
|
|
|
$this->configureProject($buildXmlFile); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private function initParser($fileName) |
34
|
|
|
{ |
35
|
|
|
$fullFileName = PHING_TEST_BASE . '/etc/tasks/ext/sonar/properties/' . $fileName . '.properties'; |
36
|
|
|
$parser = new SonarConfigurationFileParser($fullFileName, $this->getProject()); |
37
|
|
|
|
38
|
|
|
return $parser; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @expectedException BuildException |
43
|
|
|
*/ |
44
|
|
|
public function testConstructFileIsNullThrowsException() |
45
|
|
|
{ |
46
|
|
|
$file = null; |
47
|
|
|
|
48
|
|
|
new SonarConfigurationFileParser($file, $this->getProject()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException BuildException |
53
|
|
|
*/ |
54
|
|
|
public function testConstructFileIsEmptyFhrowsException() |
55
|
|
|
{ |
56
|
|
|
$file = ''; |
57
|
|
|
|
58
|
|
|
new SonarConfigurationFileParser($file, $this->getProject()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @expectedException BuildException |
64
|
|
|
*/ |
65
|
|
|
public function testConstructFileDoesNotExistThrowsException() |
66
|
|
|
{ |
67
|
|
|
$file = 'ThisFileDoesNotExist'; |
68
|
|
|
$parser = new SonarConfigurationFileParser($file, $this->getProject()); |
69
|
|
|
|
70
|
|
|
$parser->parse(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testEmptyFile() |
74
|
|
|
{ |
75
|
|
|
$parser = $this->initParser('test-empty-file'); |
76
|
|
|
|
77
|
|
|
$properties = $parser->parse(); |
78
|
|
|
|
79
|
|
|
if (method_exists($this, 'assertIsArray')) { |
80
|
|
|
$this->assertIsArray($properties); |
81
|
|
|
} else { |
82
|
|
|
$this->assertInternalType('array', $properties); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
$this->assertEmpty($properties); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testPropertyWithColonAndWithoutWhitespace() |
88
|
|
|
{ |
89
|
|
|
$parser = $this->initParser('test-property-with-colon-and-without-whitespace'); |
90
|
|
|
|
91
|
|
|
$properties = $parser->parse(); |
92
|
|
|
|
93
|
|
|
$this->assertArrayHasKey('foo', $properties); |
94
|
|
|
$this->assertContains('bar', $properties); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testPropertyWithColonAndWithWhitespace() |
98
|
|
|
{ |
99
|
|
|
$parser = $this->initParser('test-property-with-colon-and-with-whitespace'); |
100
|
|
|
|
101
|
|
|
$properties = $parser->parse(); |
102
|
|
|
|
103
|
|
|
$this->assertArrayHasKey('foo', $properties); |
104
|
|
|
$this->assertContains('bar', $properties); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function testPropertyWithEqualsSignAndWithoutWhitespace() |
108
|
|
|
{ |
109
|
|
|
$parser = $this->initParser('test-property-with-equals-sign-and-without-whitespace'); |
110
|
|
|
|
111
|
|
|
$properties = $parser->parse(); |
112
|
|
|
|
113
|
|
|
$this->assertArrayHasKey('foo', $properties); |
114
|
|
|
$this->assertContains('bar', $properties); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function testPropertyWithEqualsSignAndWithWhitespace() |
118
|
|
|
{ |
119
|
|
|
$parser = $this->initParser('test-property-with-equals-sign-and-with-whitespace'); |
120
|
|
|
|
121
|
|
|
$properties = $parser->parse(); |
122
|
|
|
|
123
|
|
|
$this->assertArrayHasKey('foo', $properties); |
124
|
|
|
$this->assertContains('bar', $properties); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function testCommentAtBeginOfLine() |
128
|
|
|
{ |
129
|
|
|
$parser = $this->initParser('test-property-with-comment-at-begin-of-line'); |
130
|
|
|
|
131
|
|
|
$properties = $parser->parse(); |
132
|
|
|
|
133
|
|
|
$this->assertArrayNotHasKey('comment', $properties); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function testCommentInMiddleOfLine() |
137
|
|
|
{ |
138
|
|
|
$parser = $this->initParser('test-property-with-comment-in-middle-of-line'); |
139
|
|
|
|
140
|
|
|
$properties = $parser->parse(); |
141
|
|
|
|
142
|
|
|
$this->assertArrayNotHasKey('comment', $properties); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function testPropertyHasMultiLineValue() |
146
|
|
|
{ |
147
|
|
|
$parser = $this->initParser('test-multiline-property'); |
148
|
|
|
|
149
|
|
|
$properties = $parser->parse(); |
150
|
|
|
|
151
|
|
|
$this->assertArrayHasKey('foo', $properties); |
152
|
|
|
$this->assertContains('This is a multi-line comment.', $properties); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testPropertyEndsWithABackSlash() |
156
|
|
|
{ |
157
|
|
|
$parser = $this->initParser('test-property-with-trailing-backslash'); |
158
|
|
|
|
159
|
|
|
$properties = $parser->parse(); |
160
|
|
|
|
161
|
|
|
$this->assertArrayHasKey('foo', $properties); |
162
|
|
|
$this->assertArrayHasKey('bar', $properties); |
163
|
|
|
$this->assertContains('This is not a multi-line property, but ends with a backslash\\', $properties); |
164
|
|
|
$this->assertContains('baz', $properties); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testPropertyHasMultiLineValueIntermediateLineIsEmpty() |
168
|
|
|
{ |
169
|
|
|
$parser = $this->initParser('test-multiline-property-with-empty-intermediate-line'); |
170
|
|
|
|
171
|
|
|
$properties = $parser->parse(); |
172
|
|
|
|
173
|
|
|
$this->assertArrayHasKey('foo', $properties); |
174
|
|
|
$this->assertContains('This is a multi-line comment.', $properties); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.