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 SonarTaskTest extends BuildFileTest |
26
|
|
|
{ |
27
|
|
|
protected function setUp(): void |
28
|
|
|
{ |
29
|
|
|
$buildXmlFile = PHING_TEST_BASE . '/etc/tasks/ext/sonar/SonarTaskTest.xml'; |
30
|
|
|
$this->configureProject($buildXmlFile); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private function ignoreFailureIfDueToMissingParameters(Exception $e) |
34
|
|
|
{ |
35
|
|
|
// NOTE: Execution will finally fail due to missing properties. |
36
|
|
|
// We ignore this failure, but pass ary failures that are |
37
|
|
|
// caused by other errors. |
38
|
|
|
if ( |
39
|
|
|
strpos( |
40
|
|
|
$e->getMessage(), |
41
|
|
|
'SonarQube Scanner misses some parameters. The following properties are mandatory' |
42
|
|
|
) !== false |
43
|
|
|
) { |
44
|
|
|
throw $e; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// |
49
|
|
|
// Test "executable" attribute ... |
50
|
|
|
// |
51
|
|
|
|
52
|
|
|
public function testExecutableAttributeIsMissingThrowsException() |
53
|
|
|
{ |
54
|
|
|
$this->expectBuildExceptionContaining( |
55
|
|
|
'executable-attribute-is-missing', |
56
|
|
|
'executable-attribute-is-missing', |
57
|
|
|
'You must specify the path of the SonarQube Scanner using the "executable" attribute.' |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testExecutableAttributeIsEmptyThrowsException() |
62
|
|
|
{ |
63
|
|
|
$this->expectBuildExceptionContaining( |
64
|
|
|
'executable-attribute-is-empty', |
65
|
|
|
'executable-attribute-is-empty', |
66
|
|
|
'You must specify the path of the SonarQube Scanner using the "executable" attribute.' |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testExecutablePathDoesNotExistThrowsException() |
71
|
|
|
{ |
72
|
|
|
$this->expectBuildExceptionContaining( |
73
|
|
|
'executable-path-does-not-exist', |
74
|
|
|
'executable-path-does-not-exist', |
75
|
|
|
'Cannot find SonarQube Scanner' |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* the return code of the exec command is always 0 under windows |
81
|
|
|
* @requires OS ^(?:(?!Win).)*$ |
82
|
|
|
*/ |
83
|
|
|
public function testExecutableFileIsNotExecutableThrowsException() |
84
|
|
|
{ |
85
|
|
|
$this->expectBuildExceptionContaining( |
86
|
|
|
'executable-file-is-not-executable', |
87
|
|
|
'executable-file-is-not-executable', |
88
|
|
|
'Cannot find SonarQube Scanner' |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testExecutableIsNotSonarScannerAndHasNoVersionStringThrowsException() |
93
|
|
|
{ |
94
|
|
|
$this->expectBuildExceptionContaining( |
95
|
|
|
'executable-is-not-sonar-scanner-and-has-no-version-string', |
96
|
|
|
'executable-is-not-sonar-scanner-and-has-no-version-string', |
97
|
|
|
'Cannot find SonarQube Scanner' |
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testExecutableIsNotSonarScannerAndHasVersionStringThrowsException() |
102
|
|
|
{ |
103
|
|
|
$this->expectBuildExceptionContaining( |
104
|
|
|
'executable-is-not-sonar-scanner-and-has-version-string', |
105
|
|
|
'executable-is-not-sonar-scanner-and-has-version-string', |
106
|
|
|
'Could not find name of SonarQube Scanner in version string. Executable appears not to be SonarQube Scanner' |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// |
111
|
|
|
// Test "errors" attribute ... |
112
|
|
|
// |
113
|
|
|
|
114
|
|
|
public function testErrorsAttributeIsMissing() |
115
|
|
|
{ |
116
|
|
|
try { |
117
|
|
|
$this->expectPropertySet('errors-attribute-is-missing', 'errors', 'false'); |
118
|
|
|
} catch (BuildException $e) { |
119
|
|
|
$this->ignoreFailureIfDueToMissingParameters($e); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function testErrorsAttributeIsEmpty() |
124
|
|
|
{ |
125
|
|
|
$this->expectBuildExceptionContaining( |
126
|
|
|
'errors-attribute-is-empty', |
127
|
|
|
'errors-attribute-is-empty', |
128
|
|
|
'Expected a boolean value.' |
129
|
|
|
); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testErrorsValueIsInvalid() |
133
|
|
|
{ |
134
|
|
|
$this->expectBuildExceptionContaining( |
135
|
|
|
'errors-value-is-invalid', |
136
|
|
|
'errors-value-is-invalid', |
137
|
|
|
'Expected a boolean value.' |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// |
142
|
|
|
// Test "debug" attribute ... |
143
|
|
|
// |
144
|
|
|
|
145
|
|
|
public function testDebugAttributeIsMissing() |
146
|
|
|
{ |
147
|
|
|
try { |
148
|
|
|
$this->expectPropertySet('debug-attribute-is-missing', 'debug', 'false'); |
149
|
|
|
} catch (BuildException $e) { |
150
|
|
|
$this->ignoreFailureIfDueToMissingParameters($e); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testDebugAttributeIsEmpty() |
155
|
|
|
{ |
156
|
|
|
$this->expectBuildExceptionContaining( |
157
|
|
|
'debug-attribute-is-empty', |
158
|
|
|
'debug-attribute-is-empty', |
159
|
|
|
'Expected a boolean value.' |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function testDebugValueIsInvalid() |
164
|
|
|
{ |
165
|
|
|
$this->expectBuildExceptionContaining( |
166
|
|
|
'debug-value-is-invalid', |
167
|
|
|
'debug-value-is-invalid', |
168
|
|
|
'Expected a boolean value.' |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
// |
173
|
|
|
// Test "configuration" attribute ... |
174
|
|
|
// |
175
|
|
|
|
176
|
|
|
public function testConfigurationAttributeIsMissing() |
177
|
|
|
{ |
178
|
|
|
try { |
179
|
|
|
$this->expectPropertySet('configuration-attribute-is-missing', 'configuration', null); |
180
|
|
|
} catch (BuildException $e) { |
181
|
|
|
$this->ignoreFailureIfDueToMissingParameters($e); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testConfigurationAttributeIsEmpty() |
186
|
|
|
{ |
187
|
|
|
try { |
188
|
|
|
$this->expectPropertySet('configuration-attribute-is-empty', 'configuration', ''); |
189
|
|
|
} catch (BuildException $e) { |
190
|
|
|
$this->ignoreFailureIfDueToMissingParameters($e); |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function testConfigurationPathDoesNotExist() |
195
|
|
|
{ |
196
|
|
|
$this->expectBuildExceptionContaining( |
197
|
|
|
'configuration-path-does-not-exist', |
198
|
|
|
'configuration-path-does-not-exist', |
199
|
|
|
'Cannot find configuration file' |
200
|
|
|
); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
// |
204
|
|
|
// Test "property" elements ... |
205
|
|
|
// |
206
|
|
|
|
207
|
|
|
public function testPropertyAttributesAreMissing() |
208
|
|
|
{ |
209
|
|
|
$this->expectBuildExceptionContaining( |
210
|
|
|
'attributes-are-missing', |
211
|
|
|
'attributes-are-missing', |
212
|
|
|
'Property name must not be null or empty.' |
213
|
|
|
); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function testPropertyNameIsMissing() |
217
|
|
|
{ |
218
|
|
|
$this->expectBuildExceptionContaining( |
219
|
|
|
'name-is-missing', |
220
|
|
|
'name-is-missing', |
221
|
|
|
'Property name must not be null or empty.' |
222
|
|
|
); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|