1
|
|
|
<?php |
2
|
|
|
App::uses('SoapSource', 'VatNumberCheck.Model/Datasource'); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Test Soap Source class. |
6
|
|
|
* |
7
|
|
|
*/ |
8
|
|
|
class TestSoapSource extends SoapSource { |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Test double of `parent::_parseConfig`. |
13
|
|
|
* |
14
|
|
|
* @return bool|array |
15
|
|
|
*/ |
16
|
|
|
// @codingStandardsIgnoreStart |
17
|
|
|
public function _parseConfig() { |
18
|
|
|
// @codingStandardsIgnoreEnd |
19
|
|
|
return parent::_parseConfig(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Soap Source Test class. |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
class SoapSourceTest extends CakeTestCase { |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* testParseConfigNoConfig method. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function testParseConfigNoConfig() { |
36
|
|
|
$expected = ['trace' => true]; |
37
|
|
|
|
38
|
|
|
// Get mock, without the constructor being called |
39
|
|
|
$Source = $this->getMockBuilder('TestSoapSource')->disableOriginalConstructor()->getMock(); |
40
|
|
|
|
41
|
|
|
// Now call _parseConfig |
42
|
|
|
$reflectedClass = new ReflectionClass('TestSoapSource'); |
43
|
|
|
$parseConfig = $reflectedClass->getMethod('_parseConfig'); |
44
|
|
|
$result = $parseConfig->invoke($Source); |
45
|
|
|
|
46
|
|
|
$this->assertEquals($expected, $result); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* testParseConfigWithConfig method. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function testParseConfigWithConfig() { |
55
|
|
|
$expected = [ |
56
|
|
|
'trace' => true, |
57
|
|
|
'location' => 'http://www.example.org/location', |
58
|
|
|
'uri' => 'http://www.example.org/uri', |
59
|
|
|
'login' => 'username', |
60
|
|
|
'password' => 'welcome123', |
61
|
|
|
'authentication' => 'simple', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
// Get mock, without the constructor being called |
65
|
|
|
$Source = $this->getMockBuilder('TestSoapSource')->disableOriginalConstructor()->getMock(); |
66
|
|
|
$Source->config = $expected; |
67
|
|
|
|
68
|
|
|
// Now call _parseConfig |
69
|
|
|
$reflectedClass = new ReflectionClass('TestSoapSource'); |
70
|
|
|
$parseConfig = $reflectedClass->getMethod('_parseConfig'); |
71
|
|
|
$result = $parseConfig->invoke($Source); |
72
|
|
|
|
73
|
|
|
$this->assertEquals($expected, $result); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* testConstructConnectFailed method. |
78
|
|
|
* |
79
|
|
|
* @return void |
80
|
|
|
*/ |
81
|
|
|
public function testConstructConnectFailed() { |
82
|
|
|
// Get mock, without the constructor being called |
83
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
84
|
|
|
|
85
|
|
|
// Set expectations for constructor calls |
86
|
|
|
$Source->expects($this->once())->method('connect')->will($this->returnValue(false)); |
87
|
|
|
|
88
|
|
|
// Now call the constructor |
89
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
90
|
|
|
$constructor = $reflectedClass->getConstructor(); |
91
|
|
|
$constructor->invoke($Source); |
92
|
|
|
|
93
|
|
|
$this->assertFalse($Source->connected); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* testConstructConnectSucceeded method. |
98
|
|
|
* |
99
|
|
|
* @return void |
100
|
|
|
*/ |
101
|
|
|
public function testConstructConnectSucceeded() { |
102
|
|
|
// Get mock, without the constructor being called |
103
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
104
|
|
|
|
105
|
|
|
// Set expectations for constructor calls |
106
|
|
|
$Source->expects($this->once())->method('connect')->will($this->returnValue(true)); |
107
|
|
|
|
108
|
|
|
// Now call the constructor |
109
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
110
|
|
|
$constructor = $reflectedClass->getConstructor(); |
111
|
|
|
$constructor->invoke($Source); |
112
|
|
|
|
113
|
|
|
$this->assertTrue($Source->connected); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* testConnectNoConfig method. |
118
|
|
|
* |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
public function testConnectNoConfig() { |
122
|
|
|
// Get mock, without the constructor being called |
123
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
124
|
|
|
|
125
|
|
|
// Now call connect |
126
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
127
|
|
|
$connect = $reflectedClass->getMethod('connect'); |
128
|
|
|
$result = $connect->invoke($Source); |
129
|
|
|
|
130
|
|
|
$this->assertFalse($result); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* testClose method. |
135
|
|
|
* |
136
|
|
|
* @return void |
137
|
|
|
*/ |
138
|
|
|
public function testClose() { |
139
|
|
|
// Get mock, without the constructor being called |
140
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
141
|
|
|
|
142
|
|
|
// Now call close |
143
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
144
|
|
|
$close = $reflectedClass->getMethod('close'); |
145
|
|
|
$result = $close->invoke($Source); |
146
|
|
|
|
147
|
|
|
$this->assertTrue($result); |
148
|
|
|
$this->assertNull($Source->client); |
149
|
|
|
$this->assertFalse($Source->connected); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* testListSources method. |
154
|
|
|
* |
155
|
|
|
* @return void |
156
|
|
|
*/ |
157
|
|
|
public function testListSources() { |
158
|
|
|
// Get mock, without the constructor being called |
159
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
160
|
|
|
$Source->client = $this->getMockBuilder('SoapClient')->disableOriginalConstructor()->getMock(); |
161
|
|
|
|
162
|
|
|
$Source->client->expects($this->once())->method('__getFunctions')->will($this->returnValue([])); |
163
|
|
|
$Source->expects($this->never())->method('connect'); |
164
|
|
|
|
165
|
|
|
// Now call listSources |
166
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
167
|
|
|
$listSources = $reflectedClass->getMethod('listSources'); |
168
|
|
|
$result = $listSources->invoke($Source); |
169
|
|
|
|
170
|
|
|
$this->assertEquals([], $result); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* testQueryNotConnected method. |
175
|
|
|
* |
176
|
|
|
* @return void |
177
|
|
|
*/ |
178
|
|
|
public function testQueryNotConnected() { |
179
|
|
|
// Get mock, without the constructor being called |
180
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
181
|
|
|
|
182
|
|
|
// Now call query |
183
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
184
|
|
|
$query = $reflectedClass->getMethod('query'); |
185
|
|
|
$result = $query->invoke($Source, 'test'); |
186
|
|
|
|
187
|
|
|
$this->assertFalse($result); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* testQueryConnected method. |
192
|
|
|
* |
193
|
|
|
* @return void |
194
|
|
|
*/ |
195
|
|
|
public function testQueryConnected() { |
196
|
|
|
// Get mock, without the constructor being called |
197
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
198
|
|
|
$Source->client = $this->getMockBuilder('SoapClient')->disableOriginalConstructor()->getMock(); |
199
|
|
|
$Source->connected = true; |
200
|
|
|
|
201
|
|
|
$expected = [345]; |
202
|
|
|
$method = 'test'; |
203
|
|
|
$params = 7; |
204
|
|
|
$Source->client->expects($this->once())->method('__soapCall')->with($method, [$params]) |
205
|
|
|
->will($this->returnValue($expected)); |
206
|
|
|
$Source->expects($this->never())->method('connect'); |
207
|
|
|
|
208
|
|
|
// Now call query |
209
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
210
|
|
|
$query = $reflectedClass->getMethod('query'); |
211
|
|
|
$result = $query->invoke($Source, $method, $params); |
212
|
|
|
|
213
|
|
|
$this->assertEquals($expected, $result); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* testQuerySoapFault method. |
218
|
|
|
* |
219
|
|
|
* @return void |
220
|
|
|
*/ |
221
|
|
|
public function testQuerySoapFault() { |
222
|
|
|
// Get mock, without the constructor being called |
223
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
224
|
|
|
$Source->client = $this->getMockBuilder('SoapClient')->disableOriginalConstructor()->getMock(); |
225
|
|
|
$Source->connected = true; |
226
|
|
|
|
227
|
|
|
$method = 'test'; |
228
|
|
|
$params = 7; |
229
|
|
|
$Source->client->expects($this->once())->method('__soapCall')->with($method, [$params]) |
230
|
|
|
->will($this->throwException(new SoapFault('1', 'Error message!'))); |
231
|
|
|
$Source->expects($this->never())->method('connect'); |
232
|
|
|
|
233
|
|
|
// Now call query |
234
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
235
|
|
|
$query = $reflectedClass->getMethod('query'); |
236
|
|
|
$result = $query->invoke($Source, $method, $params); |
237
|
|
|
|
238
|
|
|
$this->assertFalse($result); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* testGetResponse method. |
243
|
|
|
* |
244
|
|
|
* @return void |
245
|
|
|
*/ |
246
|
|
|
public function testGetResponse() { |
247
|
|
|
$expected = 'response'; |
248
|
|
|
|
249
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
250
|
|
|
$Source->client = $this->getMockBuilder('SoapClient')->disableOriginalConstructor()->getMock(); |
251
|
|
|
|
252
|
|
|
$Source->client->expects($this->once())->method('__getLastResponse')->will($this->returnValue($expected)); |
253
|
|
|
|
254
|
|
|
// Now call getResponse |
255
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
256
|
|
|
$getResponse = $reflectedClass->getMethod('getResponse'); |
257
|
|
|
$result = $getResponse->invoke($Source); |
258
|
|
|
|
259
|
|
|
$this->assertEquals($expected, $result); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* testGetRequest method. |
264
|
|
|
* |
265
|
|
|
* @return void |
266
|
|
|
*/ |
267
|
|
|
public function testGetRequest() { |
268
|
|
|
$expected = 'request'; |
269
|
|
|
|
270
|
|
|
$Source = $this->getMockBuilder('SoapSource')->disableOriginalConstructor()->getMock(); |
271
|
|
|
$Source->client = $this->getMockBuilder('SoapClient')->disableOriginalConstructor()->getMock(); |
272
|
|
|
|
273
|
|
|
$Source->client->expects($this->once())->method('__getLastRequest')->will($this->returnValue($expected)); |
274
|
|
|
|
275
|
|
|
// Now call getRequest |
276
|
|
|
$reflectedClass = new ReflectionClass('SoapSource'); |
277
|
|
|
$getRequest = $reflectedClass->getMethod('getRequest'); |
278
|
|
|
$result = $getRequest->invoke($Source); |
279
|
|
|
|
280
|
|
|
$this->assertEquals($expected, $result); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
} |
284
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths