1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Radowoj\Yaah;
|
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase;
|
6
|
|
|
use Radowoj\Yaah\Field;
|
7
|
|
|
use SoapClient;
|
8
|
|
|
|
9
|
|
|
class HelperTest extends TestCase
|
10
|
|
|
{
|
11
|
|
|
protected $config = null;
|
12
|
|
|
|
13
|
|
|
protected $soapClient = null;
|
14
|
|
|
|
15
|
|
|
public function setUp()
|
16
|
|
|
{
|
17
|
|
|
$this->config = $this->getMockBuilder(Config::class)
|
18
|
|
|
->setMethods(['getApiKey'])
|
19
|
|
|
->disableOriginalConstructor()
|
20
|
|
|
->getMock();
|
21
|
|
|
|
22
|
|
|
$this->config->expects($this->any())
|
23
|
|
|
->method('getApiKey')
|
24
|
|
|
->willReturn('someApiKey');
|
25
|
|
|
|
26
|
|
|
$this->soapClient = $this->getMockBuilder(SoapClient::class)
|
27
|
|
|
->disableOriginalConstructor()
|
28
|
|
|
->setMethods(['doNewAuctionExt', 'doVerifyItem', 'doQuerySysStatus', 'doLogin', 'doSomethingNotImplementedInHelper'])
|
29
|
|
|
->getMock();
|
30
|
|
|
}
|
31
|
|
|
|
32
|
|
|
|
33
|
|
|
public function testNewAuction()
|
34
|
|
|
{
|
35
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
36
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
37
|
|
|
->setMethods(['doNewAuctionExt', 'doVerifyItem'])
|
38
|
|
|
->getMock();
|
39
|
|
|
|
40
|
|
|
$apiClient->expects($this->once())
|
41
|
|
|
->method('doNewAuctionExt')
|
42
|
|
|
->with($this->equalTo([
|
43
|
|
|
'fields' => [
|
44
|
|
|
[
|
45
|
|
|
'fvalueString' => 'test title',
|
46
|
|
|
'fid' => 1,
|
47
|
|
|
'fvalueInt' => 0,
|
48
|
|
|
'fvalueFloat' => 0,
|
49
|
|
|
'fvalueImage' => '',
|
50
|
|
|
'fvalueDate' => '',
|
51
|
|
|
'fvalueDatetime' => 0,
|
52
|
|
|
'fvalueRangeInt' => [
|
53
|
|
|
'fvalueRangeIntMin' => 0,
|
54
|
|
|
'fvalueRangeIntMax' => 0,
|
55
|
|
|
],
|
56
|
|
|
'fvalueRangeFloat' => [
|
57
|
|
|
'fvalueRangeFloatMin' => 0,
|
58
|
|
|
'fvalueRangeFloatMax' => 0,
|
59
|
|
|
],
|
60
|
|
|
'fvalueRangeDate' => [
|
61
|
|
|
'fvalueRangeDateMin' => '',
|
62
|
|
|
'fvalueRangeDateMax' => '',
|
63
|
|
|
]
|
64
|
|
|
]
|
65
|
|
|
],
|
66
|
|
|
'localId' => 1
|
67
|
|
|
]));
|
68
|
|
|
|
69
|
|
|
$apiClient->expects($this->once())
|
70
|
|
|
->method('doVerifyItem')
|
71
|
|
|
->willReturn((object)['itemId' => 1234]);
|
72
|
|
|
|
73
|
|
|
$helper = new Helper($apiClient);
|
74
|
|
|
|
75
|
|
|
$result = $helper->newAuction(new Auction([1 => 'test title']), 1);
|
76
|
|
|
|
77
|
|
|
$this->assertSame(1234, $result);
|
78
|
|
|
}
|
79
|
|
|
|
80
|
|
|
/**
|
81
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
82
|
|
|
* @expectedExceptionMessage Auction has not been created
|
83
|
|
|
*/
|
84
|
|
|
public function testExceptionOnInvalidNewAuctionResponse()
|
85
|
|
|
{
|
86
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
87
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
88
|
|
|
->setMethods(['doNewAuctionExt', 'doVerifyItem'])
|
89
|
|
|
->getMock();
|
90
|
|
|
|
91
|
|
|
$apiClient->expects($this->once())
|
92
|
|
|
->method('doNewAuctionExt')
|
93
|
|
|
->willReturn((object)['whatever' => 1]);
|
94
|
|
|
|
95
|
|
|
$apiClient->expects($this->once())
|
96
|
|
|
->method('doVerifyItem')
|
97
|
|
|
->willReturn((object)['definitelyNotItemId' => 1234]);
|
98
|
|
|
|
99
|
|
|
$helper = new Helper($apiClient);
|
100
|
|
|
$helper->newAuction(new Auction([1 => 'test title']), 1);
|
101
|
|
|
}
|
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testDirectWebapiCall()
|
105
|
|
|
{
|
106
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
107
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
108
|
|
|
->setMethods(['doSomethingNotImplementedInHelper'])
|
109
|
|
|
->getMock();
|
110
|
|
|
|
111
|
|
|
$apiClient->expects($this->once())
|
112
|
|
|
->method('doSomethingNotImplementedInHelper')
|
113
|
|
|
->with($this->equalTo([
|
114
|
|
|
'param1' => 1,
|
115
|
|
|
'param2' => 2,
|
116
|
|
|
]))
|
117
|
|
|
->willReturn(42);
|
118
|
|
|
|
119
|
|
|
$helper = new Helper($apiClient);
|
120
|
|
|
$result = $helper->doSomethingNotImplementedInHelper([
|
|
|
|
|
121
|
|
|
'param1' => 1,
|
122
|
|
|
'param2' => 2,
|
123
|
|
|
]);
|
124
|
|
|
|
125
|
|
|
$this->assertSame(42, $result);
|
126
|
|
|
}
|
127
|
|
|
|
128
|
|
|
|
129
|
|
|
/**
|
130
|
|
|
* This test checks if call of a method not implemented in helper is correctly passed via WebAPI client to soapClient
|
131
|
|
|
* (extended by WebAPI request param - just one is tested here, as all required params are tested in ClientTest)
|
132
|
|
|
*/
|
133
|
|
|
public function testDirectWebapiCallFromSoapClient()
|
134
|
|
|
{
|
135
|
|
|
$this->soapClient->expects($this->once())
|
136
|
|
|
->method('doQuerySysStatus')
|
137
|
|
|
->willReturn((object)['verKey' => 'someVersionKey']);
|
138
|
|
|
|
139
|
|
|
$this->soapClient->expects($this->once())
|
140
|
|
|
->method('doLogin')
|
141
|
|
|
->willReturn((object)['sessionHandlePart' => 'foo', 'userId' => 'bar']);
|
142
|
|
|
|
143
|
|
|
$this->soapClient->expects($this->once())
|
144
|
|
|
->method('doSomethingNotImplementedInHelper')
|
145
|
|
|
->with(
|
146
|
|
|
$this->callback(function($params){
|
147
|
|
|
return array_key_exists('param1', $params)
|
148
|
|
|
&& array_key_exists('webapiKey', $params)
|
149
|
|
|
&& $params['param1'] == 1337
|
150
|
|
|
&& $params['webapiKey'] == 'someApiKey';
|
151
|
|
|
})
|
152
|
|
|
)
|
153
|
|
|
->willReturn(42);
|
154
|
|
|
|
155
|
|
|
$apiClient = new Client($this->config, $this->soapClient);
|
156
|
|
|
|
157
|
|
|
$helper = new Helper($apiClient);
|
158
|
|
|
$result = $helper->doSomethingNotImplementedInHelper([
|
|
|
|
|
159
|
|
|
'param1' => 1337
|
160
|
|
|
]);
|
161
|
|
|
|
162
|
|
|
$this->assertSame(42, $result);
|
163
|
|
|
}
|
164
|
|
|
|
165
|
|
|
|
166
|
|
|
|
167
|
|
|
public function providerFinishAuctions()
|
168
|
|
|
{
|
169
|
|
|
return [
|
170
|
|
|
'do not cancel all bids, no reason' => [
|
171
|
|
|
0,
|
172
|
|
|
''
|
173
|
|
|
],
|
174
|
|
|
'cancel all bids, no reason' => [
|
175
|
|
|
1,
|
176
|
|
|
''
|
177
|
|
|
],
|
178
|
|
|
'do not cancel all bids, some reason' => [
|
179
|
|
|
0,
|
180
|
|
|
'some reason'
|
181
|
|
|
],
|
182
|
|
|
'cancel all bids, some reason' => [
|
183
|
|
|
1,
|
184
|
|
|
'some reason'
|
185
|
|
|
],
|
186
|
|
|
|
187
|
|
|
];
|
188
|
|
|
}
|
189
|
|
|
|
190
|
|
|
/**
|
191
|
|
|
* @dataProvider providerFinishAuctions
|
192
|
|
|
*/
|
193
|
|
|
public function testFinishAuctions($finishCancelAllBids, $finishCancelReason)
|
194
|
|
|
{
|
195
|
|
|
$auctionIds = [31337, 1337, 42];
|
196
|
|
|
|
197
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
198
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
199
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doFinishItems'])
|
200
|
|
|
->getMock();
|
201
|
|
|
|
202
|
|
|
$apiClient->expects($this->once())
|
203
|
|
|
->method('doFinishItems')
|
204
|
|
|
->with($this->equalTo([
|
205
|
|
|
'finishItemsList' => [
|
206
|
|
|
[
|
207
|
|
|
'finishItemId' => 31337,
|
208
|
|
|
'finishCancelAllBids' => $finishCancelAllBids,
|
209
|
|
|
'finishCancelReason' => $finishCancelReason
|
210
|
|
|
],
|
211
|
|
|
[
|
212
|
|
|
'finishItemId' => 1337,
|
213
|
|
|
'finishCancelAllBids' => $finishCancelAllBids,
|
214
|
|
|
'finishCancelReason' => $finishCancelReason
|
215
|
|
|
],
|
216
|
|
|
[
|
217
|
|
|
'finishItemId' => 42,
|
218
|
|
|
'finishCancelAllBids' => $finishCancelAllBids,
|
219
|
|
|
'finishCancelReason' => $finishCancelReason
|
220
|
|
|
],
|
221
|
|
|
]
|
222
|
|
|
]));
|
223
|
|
|
|
224
|
|
|
$helper = new Helper($apiClient);
|
225
|
|
|
|
226
|
|
|
$result = $helper->finishAuctions($auctionIds, $finishCancelAllBids, $finishCancelReason);
|
|
|
|
|
227
|
|
|
}
|
228
|
|
|
|
229
|
|
|
/**
|
230
|
|
|
* @dataProvider providerFinishAuctions
|
231
|
|
|
*/
|
232
|
|
|
public function testFinishAuction($finishCancelAllBids, $finishCancelReason)
|
233
|
|
|
{
|
234
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
235
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
236
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doFinishItems'])
|
237
|
|
|
->getMock();
|
238
|
|
|
|
239
|
|
|
$apiClient->expects($this->once())
|
240
|
|
|
->method('doFinishItems')
|
241
|
|
|
->with($this->equalTo([
|
242
|
|
|
'finishItemsList' => [
|
243
|
|
|
[
|
244
|
|
|
'finishItemId' => 31337,
|
245
|
|
|
'finishCancelAllBids' => $finishCancelAllBids,
|
246
|
|
|
'finishCancelReason' => $finishCancelReason
|
247
|
|
|
],
|
248
|
|
|
]
|
249
|
|
|
]));
|
250
|
|
|
|
251
|
|
|
$helper = new Helper($apiClient);
|
252
|
|
|
|
253
|
|
|
$result = $helper->finishAuction(31337, $finishCancelAllBids, $finishCancelReason);
|
|
|
|
|
254
|
|
|
}
|
255
|
|
|
|
256
|
|
|
|
257
|
|
|
public function testChangeQuantity()
|
258
|
|
|
{
|
259
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
260
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
261
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doChangeQuantityItem'])
|
262
|
|
|
->getMock();
|
263
|
|
|
|
264
|
|
|
$apiClient->expects($this->once())
|
265
|
|
|
->method('doChangeQuantityItem')
|
266
|
|
|
->with($this->equalTo([
|
267
|
|
|
'itemId' => 1337,
|
268
|
|
|
'newItemQuantity' => 42
|
269
|
|
|
]));
|
270
|
|
|
|
271
|
|
|
$helper = new Helper($apiClient);
|
272
|
|
|
$helper->changeQuantity(1337, 42);
|
273
|
|
|
}
|
274
|
|
|
|
275
|
|
|
|
276
|
|
|
/**
|
277
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
278
|
|
|
* @expectedExceptionMessage Method nonexistentMethodWithoutWebApiDoPrefix is not implemented
|
279
|
|
|
*/
|
280
|
|
View Code Duplication |
public function testExceptionOnNonexistentMethodWithoutDoPrefix()
|
|
|
|
|
281
|
|
|
{
|
282
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
283
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
284
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doChangeQuantityItem'])
|
285
|
|
|
->getMock();
|
286
|
|
|
|
287
|
|
|
$helper = new Helper($apiClient);
|
288
|
|
|
$helper->nonexistentMethodWithoutWebApiDoPrefix();
|
|
|
|
|
289
|
|
|
}
|
290
|
|
|
|
291
|
|
|
|
292
|
|
|
/**
|
293
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
294
|
|
|
* @expectedExceptionMessage Invalid WebAPI response
|
295
|
|
|
*/
|
296
|
|
View Code Duplication |
public function testExceptionOnInvalidApiResponseFromGetFieldsByCategory()
|
|
|
|
|
297
|
|
|
{
|
298
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
299
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
300
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doGetSellFormFieldsForCategory'])
|
301
|
|
|
->getMock();
|
302
|
|
|
|
303
|
|
|
$helper = new Helper($apiClient);
|
304
|
|
|
$helper->getFieldsByCategory(42);
|
305
|
|
|
}
|
306
|
|
|
|
307
|
|
|
|
308
|
|
|
public function testGetFieldsByCategory()
|
309
|
|
|
{
|
310
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
311
|
|
|
->setConstructorArgs([$this->config, $this->soapClient])
|
312
|
|
|
->setMethods(['getLocalVersionKey', 'login', 'doGetSellFormFieldsForCategory'])
|
313
|
|
|
->getMock();
|
314
|
|
|
|
315
|
|
|
$apiClient->expects($this->once())
|
316
|
|
|
->method('doGetSellFormFieldsForCategory')
|
317
|
|
|
->willReturn((object)[
|
318
|
|
|
'sellFormFieldsForCategory' => (object)[
|
319
|
|
|
'sellFormFieldsList' => (object)[
|
320
|
|
|
'item' => [
|
321
|
|
|
(object)[
|
322
|
|
|
'sellFormId' => 1,
|
323
|
|
|
'sellFormTitle' => 'Some field title',
|
324
|
|
|
'sellFormOpt' => 1,
|
325
|
|
|
'sellFormOptsValues' => '0|1',
|
326
|
|
|
'sellFormDesc' => 'Some sell form description',
|
327
|
|
|
],
|
328
|
|
|
(object)[
|
329
|
|
|
'sellFormId' => 2,
|
330
|
|
|
'sellFormTitle' => 'Some other field title',
|
331
|
|
|
'sellFormOpt' => 8,
|
332
|
|
|
'sellFormOptsValues' => '0|1|2',
|
333
|
|
|
'sellFormDesc' => 'Some other sell form description',
|
334
|
|
|
]
|
335
|
|
|
]
|
336
|
|
|
]
|
337
|
|
|
]
|
338
|
|
|
]);
|
339
|
|
|
|
340
|
|
|
$helper = new Helper($apiClient);
|
341
|
|
|
$result = $helper->getFieldsByCategory(42);
|
342
|
|
|
|
343
|
|
|
$this->assertSame([
|
344
|
|
|
[
|
345
|
|
|
'fid' => 1,
|
346
|
|
|
'title' => 'Some field title',
|
347
|
|
|
'required' => true,
|
348
|
|
|
'options' => '0|1',
|
349
|
|
|
'optionsDesc' => 'Some sell form description',
|
350
|
|
|
],
|
351
|
|
|
[
|
352
|
|
|
'fid' => 2,
|
353
|
|
|
'title' => 'Some other field title',
|
354
|
|
|
'required' => false,
|
355
|
|
|
'options' => '0|1|2',
|
356
|
|
|
'optionsDesc' => 'Some other sell form description',
|
357
|
|
|
],
|
358
|
|
|
|
359
|
|
|
], $result);
|
360
|
|
|
}
|
361
|
|
|
|
362
|
|
|
/**
|
363
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
364
|
|
|
* @expectedExceptionMessage Unable to get site journal deals
|
365
|
|
|
*/
|
366
|
|
|
public function testGetSiteJournalDealsExceptionOnFailure()
|
367
|
|
|
{
|
368
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
369
|
|
|
->disableOriginalConstructor()
|
370
|
|
|
->getMock();
|
371
|
|
|
|
372
|
|
|
$helper = new Helper($apiClient);
|
373
|
|
|
|
374
|
|
|
$helper->getSiteJournalDeals();
|
375
|
|
|
}
|
376
|
|
|
|
377
|
|
|
|
378
|
|
|
|
379
|
|
View Code Duplication |
public function testGetSiteJournalDealsWithDefaultParams()
|
|
|
|
|
380
|
|
|
{
|
381
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
382
|
|
|
->disableOriginalConstructor()
|
383
|
|
|
->setMethods(['doGetSiteJournalDeals'])
|
384
|
|
|
->getMock();
|
385
|
|
|
|
386
|
|
|
$apiClient->expects($this->once())
|
387
|
|
|
->method('doGetSiteJournalDeals')
|
388
|
|
|
->with($this->equalTo([
|
389
|
|
|
'journalStart' => 0,
|
390
|
|
|
]))
|
391
|
|
|
->willReturn((object)[
|
392
|
|
|
'siteJournalDeals' => (object)[
|
393
|
|
|
'item' => [
|
394
|
|
|
(object)[
|
395
|
|
|
'dealEventId' => 42
|
396
|
|
|
]
|
397
|
|
|
]
|
398
|
|
|
]
|
399
|
|
|
]);
|
400
|
|
|
|
401
|
|
|
$helper = new Helper($apiClient);
|
402
|
|
|
$deals = $helper->getSiteJournalDeals();
|
403
|
|
|
|
404
|
|
|
$this->assertContainsOnly('Radowoj\Yaah\Journal\Deal', $deals);
|
405
|
|
|
}
|
406
|
|
|
|
407
|
|
|
|
408
|
|
View Code Duplication |
public function testGetSiteJournalDealsWithNonzeroStart()
|
|
|
|
|
409
|
|
|
{
|
410
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
411
|
|
|
->disableOriginalConstructor()
|
412
|
|
|
->setMethods(['doGetSiteJournalDeals'])
|
413
|
|
|
->getMock();
|
414
|
|
|
|
415
|
|
|
$apiClient->expects($this->once())
|
416
|
|
|
->method('doGetSiteJournalDeals')
|
417
|
|
|
->with($this->equalTo([
|
418
|
|
|
'journalStart' => 71830,
|
419
|
|
|
]))
|
420
|
|
|
->willReturn((object)[
|
421
|
|
|
'siteJournalDeals' => (object)[
|
422
|
|
|
'item' => [
|
423
|
|
|
(object)[
|
424
|
|
|
'dealEventId' => 42
|
425
|
|
|
]
|
426
|
|
|
]
|
427
|
|
|
]
|
428
|
|
|
]);
|
429
|
|
|
|
430
|
|
|
$helper = new Helper($apiClient);
|
431
|
|
|
$deals = $helper->getSiteJournalDeals(71830);
|
432
|
|
|
|
433
|
|
|
$this->assertContainsOnly('Radowoj\Yaah\Journal\Deal', $deals);
|
434
|
|
|
}
|
435
|
|
|
|
436
|
|
|
|
437
|
|
|
/**
|
438
|
|
|
* @expectedException Radowoj\Yaah\Exception
|
439
|
|
|
* @expectedExceptionMessage Invalid WebAPI response: stdClass Object
|
440
|
|
|
*/
|
441
|
|
View Code Duplication |
public function testGetAuctionByItemIdExceptionOnInvalidResponse()
|
|
|
|
|
442
|
|
|
{
|
443
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
444
|
|
|
->disableOriginalConstructor()
|
445
|
|
|
->setMethods(['doGetItemFields'])
|
446
|
|
|
->getMock();
|
447
|
|
|
|
448
|
|
|
$apiClient->expects($this->once())
|
449
|
|
|
->method('doGetItemFields')
|
450
|
|
|
->with($this->equalTo([
|
451
|
|
|
'itemId' => 4321,
|
452
|
|
|
]))
|
453
|
|
|
->willReturn((object)[]);
|
454
|
|
|
|
455
|
|
|
$helper = new Helper($apiClient);
|
456
|
|
|
$helper->getAuctionByItemId(4321);
|
457
|
|
|
}
|
458
|
|
|
|
459
|
|
|
|
460
|
|
View Code Duplication |
public function testGetAuctionByItem()
|
|
|
|
|
461
|
|
|
{
|
462
|
|
|
$apiClient = $this->getMockBuilder(Client::class)
|
463
|
|
|
->disableOriginalConstructor()
|
464
|
|
|
->setMethods(['doGetItemFields'])
|
465
|
|
|
->getMock();
|
466
|
|
|
|
467
|
|
|
$apiClient->expects($this->once())
|
468
|
|
|
->method('doGetItemFields')
|
469
|
|
|
->with($this->equalTo([
|
470
|
|
|
'itemId' => 4321,
|
471
|
|
|
]))
|
472
|
|
|
->willReturn((object)[
|
473
|
|
|
'itemFields' => (object)[
|
474
|
|
|
'item' => [
|
475
|
|
|
//no fields returned - mapping from fields to auction tested separately
|
476
|
|
|
]
|
477
|
|
|
]
|
478
|
|
|
]);
|
479
|
|
|
|
480
|
|
|
$helper = new Helper($apiClient);
|
481
|
|
|
$auction = $helper->getAuctionByItemId(4321);
|
482
|
|
|
|
483
|
|
|
$this->assertInstanceOf('Radowoj\Yaah\Auction', $auction);
|
484
|
|
|
}
|
485
|
|
|
|
486
|
|
|
}
|
487
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: