1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/gigya-client |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/gigya-client/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/gigya-client |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\Gigya\Test\Unit; |
15
|
|
|
|
16
|
|
|
use Exception; |
17
|
|
|
use Graze\Gigya\Auth\GigyaAuthInterface; |
18
|
|
|
use Graze\Gigya\Gigya; |
19
|
|
|
use Graze\Gigya\Response\ResponseInterface; |
20
|
|
|
use Graze\Gigya\Test\TestCase; |
21
|
|
|
use Graze\Gigya\Test\TestFixtures; |
22
|
|
|
use Graze\Gigya\Validation\ResponseValidatorInterface; |
23
|
|
|
use Graze\Gigya\Validation\ValidGigyaResponseSubscriber; |
24
|
|
|
use GuzzleHttp\Event\EmitterInterface; |
25
|
|
|
use GuzzleHttp\Event\SubscriberInterface; |
26
|
|
|
use Mockery as m; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @runTestsInSeparateProcesses |
30
|
|
|
* @preserveGlobalState disabled |
31
|
|
|
*/ |
32
|
|
|
class GigyaTest extends TestCase |
33
|
|
|
{ |
34
|
|
|
/** @var mixed */ |
35
|
|
|
private $guzzleClient; |
36
|
|
|
/** @var mixed */ |
37
|
|
|
private $factory; |
38
|
|
|
/** @var string */ |
39
|
|
|
private $certPath; |
40
|
|
|
/** @var mixed */ |
41
|
|
|
private $emitter; |
42
|
|
|
|
43
|
|
|
public function setUp() |
44
|
|
|
{ |
45
|
|
|
$this->guzzleClient = m::mock('overload:GuzzleHttp\Client'); |
46
|
|
|
$this->emitter = m::mock(EmitterInterface::class); |
47
|
|
|
$this->guzzleClient->shouldReceive('getEmitter') |
48
|
|
|
->andReturn($this->emitter); |
49
|
|
|
$this->factory = m::mock('Graze\Gigya\Response\ResponseFactoryInterface'); |
50
|
|
|
$this->certPath = realpath(__DIR__ . '/../../src/' . Gigya::CERTIFICATE_FILE); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function tearDown() |
54
|
|
|
{ |
55
|
|
|
$this->guzzleClient = $this->factory = null; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $key |
60
|
|
|
* @param string $secret |
61
|
|
|
* @param string $dc |
62
|
|
|
* @param string|null $userKey |
63
|
|
|
* |
64
|
|
|
* @return Gigya |
65
|
|
|
*/ |
66
|
|
|
public function createClient($key = 'key', $secret = 'secret', $dc = Gigya::DC_EU, $userKey = null) |
67
|
|
|
{ |
68
|
|
|
$options = [ |
69
|
|
|
'uidValidator' => false, |
70
|
|
|
'factory' => $this->factory, |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
return new Gigya($key, $secret, $dc, $userKey, $options); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Setup the subscribers |
78
|
|
|
* |
79
|
|
|
* @param string $key |
80
|
|
|
* @param string $secret |
81
|
|
|
* @param string|null $userKey |
82
|
|
|
*/ |
83
|
|
|
private function setupSubscribers($key, $secret, $userKey = null) |
84
|
|
|
{ |
85
|
|
|
$subscriber = function (SubscriberInterface $subscriber) use ($key, $secret, $userKey) { |
86
|
|
|
if ($subscriber instanceof GigyaAuthInterface) { |
87
|
|
|
static::assertEquals($key, $subscriber->getApiKey()); |
88
|
|
|
static::assertEquals($secret, $subscriber->getSecret()); |
89
|
|
|
static::assertEquals($userKey, $subscriber->getUserKey()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return true; |
93
|
|
|
}; |
94
|
|
|
$this->emitter->shouldReceive('attach') |
95
|
|
|
->with(m::type(ValidGigyaResponseSubscriber::class)) |
96
|
|
|
->once(); |
97
|
|
|
$this->emitter->shouldReceive('attach') |
98
|
|
|
->with(m::on($subscriber)) |
99
|
|
|
->once(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $fixtureName |
104
|
|
|
* @param string $uri |
105
|
|
|
* @param array $getOptions |
106
|
|
|
* @param string $key |
107
|
|
|
* @param string $secret |
108
|
|
|
* @param string|null $userKey |
109
|
|
|
* |
110
|
|
|
* @return ResponseInterface |
|
|
|
|
111
|
|
|
*/ |
112
|
|
|
private function setupCall($fixtureName, $uri, array $getOptions, $key, $secret, $userKey = null) |
113
|
|
|
{ |
114
|
|
|
$this->setupSubscribers($key, $secret, $userKey); |
115
|
|
|
|
116
|
|
|
$response = m::mock('GuzzleHttp\Message\ResponseInterface'); |
117
|
|
|
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture($fixtureName)); |
118
|
|
|
|
119
|
|
|
$this->guzzleClient->shouldReceive('get') |
120
|
|
|
->with( |
121
|
|
|
$uri, |
122
|
|
|
$getOptions |
123
|
|
|
) |
124
|
|
|
->andReturn($response); |
125
|
|
|
|
126
|
|
|
$gigyaResponse = m::mock('Graze\Gigya\Response\ResponseInterface'); |
127
|
|
|
|
128
|
|
|
$this->factory->shouldReceive('getResponse') |
129
|
|
|
->with($response) |
130
|
|
|
->andReturn($gigyaResponse); |
131
|
|
|
|
132
|
|
|
return $gigyaResponse; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testConstructorConfig() |
136
|
|
|
{ |
137
|
|
|
$this->guzzleClient->shouldReceive('__construct') |
138
|
|
|
->once() |
139
|
|
|
->with([ |
140
|
|
|
'emitter' => $this->emitter, |
141
|
|
|
]) |
142
|
|
|
->andReturn($this->guzzleClient); |
143
|
|
|
|
144
|
|
|
$this->emitter->shouldReceive('attach') |
145
|
|
|
->with(m::type(ValidGigyaResponseSubscriber::class)) |
146
|
|
|
->once(); |
147
|
|
|
|
148
|
|
|
$response = m::mock('GuzzleHttp\Message\ResponseInterface'); |
149
|
|
|
$response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('account.getAccountInfo')); |
150
|
|
|
|
151
|
|
|
$this->guzzleClient->shouldReceive('get') |
152
|
|
|
->with( |
153
|
|
|
'https://accounts.au1.gigya.com/accounts.getAccountInfo', |
154
|
|
|
[ |
155
|
|
|
'cert' => 'some_cert.pem', |
156
|
|
|
'auth' => 'oauth', |
157
|
|
|
'verify' => $this->certPath, |
158
|
|
|
'query' => [], |
159
|
|
|
] |
160
|
|
|
) |
161
|
|
|
->andReturn($response); |
162
|
|
|
|
163
|
|
|
$gigyaResponse = m::mock('Graze\Gigya\Response\ResponseInterface'); |
164
|
|
|
|
165
|
|
|
$this->factory->shouldReceive('getResponse') |
166
|
|
|
->with($response) |
167
|
|
|
->andReturn($gigyaResponse); |
168
|
|
|
|
169
|
|
|
$config = [ |
170
|
|
|
'auth' => 'oauth', |
171
|
|
|
'uidValidator' => false, |
172
|
|
|
'factory' => $this->factory, |
173
|
|
|
'guzzle' => [ |
174
|
|
|
'emitter' => $this->emitter, |
175
|
|
|
], |
176
|
|
|
'options' => [ |
177
|
|
|
'cert' => 'some_cert.pem', |
178
|
|
|
], |
179
|
|
|
]; |
180
|
|
|
$client = new Gigya('key', 'secret', Gigya::DC_AU, null, $config); |
181
|
|
|
|
182
|
|
|
static::assertSame($gigyaResponse, $client->accounts()->getAccountInfo()); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function testSettingKeyAndSecretWillPassToGuzzleClient() |
186
|
|
|
{ |
187
|
|
|
$key = 'key' . rand(1, 1000); |
188
|
|
|
$secret = 'secret' . rand(1001, 2000002); |
189
|
|
|
|
190
|
|
|
$gigyaResponse = $this->setupCall( |
191
|
|
|
'accounts.getAccountInfo', |
192
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
193
|
|
|
[ |
194
|
|
|
'auth' => 'gigya', |
195
|
|
|
'verify' => $this->certPath, |
196
|
|
|
'query' => [], |
197
|
|
|
], |
198
|
|
|
$key, |
199
|
|
|
$secret |
200
|
|
|
); |
201
|
|
|
$client = $this->createClient($key, $secret, Gigya::DC_EU, null); |
202
|
|
|
$client->setFactory($this->factory); |
203
|
|
|
|
204
|
|
|
$result = $client->accounts()->getAccountInfo([]); |
205
|
|
|
|
206
|
|
|
static::assertSame($gigyaResponse, $result); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
View Code Duplication |
public function testSettingDataCenterToAuWillCallAuUri() |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
$gigyaResponse = $this->setupCall( |
212
|
|
|
'accounts.getAccountInfo', |
213
|
|
|
'https://accounts.au1.gigya.com/accounts.getAccountInfo', |
214
|
|
|
[ |
215
|
|
|
'auth' => 'gigya', |
216
|
|
|
'verify' => $this->certPath, |
217
|
|
|
'query' => [], |
218
|
|
|
], |
219
|
|
|
'key', |
220
|
|
|
'secret' |
221
|
|
|
); |
222
|
|
|
$client = $this->createClient('key', 'secret', Gigya::DC_AU); |
223
|
|
|
|
224
|
|
|
$result = $client->accounts()->getAccountInfo([]); |
225
|
|
|
|
226
|
|
|
static::assertSame($gigyaResponse, $result); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
View Code Duplication |
public function testSettingDataCenterToUsWillCallUsUri() |
|
|
|
|
230
|
|
|
{ |
231
|
|
|
$gigyaResponse = $this->setupCall( |
232
|
|
|
'accounts.getAccountInfo', |
233
|
|
|
'https://accounts.us1.gigya.com/accounts.getAccountInfo', |
234
|
|
|
[ |
235
|
|
|
'auth' => 'gigya', |
236
|
|
|
'verify' => $this->certPath, |
237
|
|
|
'query' => [], |
238
|
|
|
], |
239
|
|
|
'key', |
240
|
|
|
'secret' |
241
|
|
|
); |
242
|
|
|
$client = $this->createClient('key', 'secret', Gigya::DC_US); |
243
|
|
|
|
244
|
|
|
$result = $client->accounts()->getAccountInfo([]); |
245
|
|
|
|
246
|
|
|
static::assertSame($gigyaResponse, $result); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
View Code Duplication |
public function testSettingTheUserKeyWillPassItThroughToGuzzle() |
|
|
|
|
250
|
|
|
{ |
251
|
|
|
$gigyaResponse = $this->setupCall( |
252
|
|
|
'accounts.getAccountInfo', |
253
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
254
|
|
|
[ |
255
|
|
|
'auth' => 'gigya', |
256
|
|
|
'verify' => $this->certPath, |
257
|
|
|
'query' => [], |
258
|
|
|
], |
259
|
|
|
'key', |
260
|
|
|
'userSecret', |
261
|
|
|
'userKey' |
262
|
|
|
); |
263
|
|
|
$client = $this->createClient('key', 'userSecret', Gigya::DC_EU, 'userKey'); |
264
|
|
|
$client->setFactory($this->factory); |
265
|
|
|
|
266
|
|
|
$result = $client->accounts()->getAccountInfo([]); |
267
|
|
|
|
268
|
|
|
static::assertSame($gigyaResponse, $result); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
View Code Duplication |
public function testPassingParamsThroughToTheMethodWillPassThroughToGuzzle() |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$gigyaResponse = $this->setupCall( |
274
|
|
|
'accounts.getAccountInfo', |
275
|
|
|
'https://socialize.eu1.gigya.com/socialize.notifyLogin', |
276
|
|
|
[ |
277
|
|
|
'auth' => 'gigya', |
278
|
|
|
'verify' => $this->certPath, |
279
|
|
|
'query' => [ |
280
|
|
|
'param' => 'passedThrough', |
281
|
|
|
], |
282
|
|
|
], |
283
|
|
|
'key', |
284
|
|
|
'secret' |
285
|
|
|
); |
286
|
|
|
$client = $this->createClient(); |
287
|
|
|
|
288
|
|
|
$result = $client->socialize()->notifyLogin(['param' => 'passedThrough']); |
289
|
|
|
|
290
|
|
|
static::assertSame($gigyaResponse, $result); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
View Code Duplication |
public function testCallingChildMethodsCallTheCorrectUri() |
|
|
|
|
294
|
|
|
{ |
295
|
|
|
$gigyaResponse = $this->setupCall( |
296
|
|
|
'accounts.getAccountInfo', |
297
|
|
|
'https://fidm.eu1.gigya.com/fidm.saml.idp.getConfig', |
298
|
|
|
[ |
299
|
|
|
'auth' => 'gigya', |
300
|
|
|
'verify' => $this->certPath, |
301
|
|
|
'query' => [ |
302
|
|
|
'params' => 'passedThrough', |
303
|
|
|
], |
304
|
|
|
], |
305
|
|
|
'key', |
306
|
|
|
'secret' |
307
|
|
|
); |
308
|
|
|
$client = $this->createClient(); |
309
|
|
|
|
310
|
|
|
$result = $client->saml()->idp()->getConfig(['params' => 'passedThrough']); |
311
|
|
|
|
312
|
|
|
static::assertSame($gigyaResponse, $result); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
View Code Duplication |
public function testTfaCallingChildMethodsCallTheCorrectUri() |
|
|
|
|
316
|
|
|
{ |
317
|
|
|
$gigyaResponse = $this->setupCall( |
318
|
|
|
'accounts.getAccountInfo', |
319
|
|
|
'https://accounts.eu1.gigya.com/accounts.tfa.getCertificate', |
320
|
|
|
[ |
321
|
|
|
'auth' => 'gigya', |
322
|
|
|
'verify' => $this->certPath, |
323
|
|
|
'query' => [ |
324
|
|
|
'params' => 'passedThrough', |
325
|
|
|
], |
326
|
|
|
], |
327
|
|
|
'key', |
328
|
|
|
'secret' |
329
|
|
|
); |
330
|
|
|
$client = $this->createClient(); |
331
|
|
|
|
332
|
|
|
$result = $client->accounts()->tfa()->getCertificate(['params' => 'passedThrough']); |
333
|
|
|
|
334
|
|
|
static::assertSame($gigyaResponse, $result); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @dataProvider clientCallDataProvider |
339
|
|
|
* |
340
|
|
|
* @param string $namespace |
341
|
|
|
* @param string $method |
342
|
|
|
* @param string $expectedUri |
343
|
|
|
*/ |
344
|
|
|
public function testClientCalls($namespace, $method, $expectedUri) |
345
|
|
|
{ |
346
|
|
|
$gigyaResponse = $this->setupCall( |
347
|
|
|
'accounts.getAccountInfo', |
348
|
|
|
$expectedUri, |
349
|
|
|
[ |
350
|
|
|
'auth' => 'gigya', |
351
|
|
|
'verify' => $this->certPath, |
352
|
|
|
'query' => [ |
353
|
|
|
'params' => 'passedThrough', |
354
|
|
|
], |
355
|
|
|
], |
356
|
|
|
'key', |
357
|
|
|
'secret' |
358
|
|
|
); |
359
|
|
|
$client = $this->createClient(); |
360
|
|
|
|
361
|
|
|
$result = $client->{$namespace}()->{$method}(['params' => 'passedThrough']); |
362
|
|
|
|
363
|
|
|
static::assertSame($gigyaResponse, $result); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
public function testCallingMagicMethodWithArgumentsThrowsAnException() |
367
|
|
|
{ |
368
|
|
|
static::setExpectedException( |
369
|
|
|
'BadMethodCallException', |
370
|
|
|
'No Arguments should be supplied for Gigya call' |
371
|
|
|
); |
372
|
|
|
|
373
|
|
|
$this->setupSubscribers('key', 'secret'); |
374
|
|
|
$client = $this->createClient(); |
375
|
|
|
$client->custom('params'); |
|
|
|
|
376
|
|
|
} |
377
|
|
|
|
378
|
|
View Code Duplication |
public function testAddingOptionsPassesThroughTheOptionsToGuzzle() |
|
|
|
|
379
|
|
|
{ |
380
|
|
|
$gigyaResponse = $this->setupCall( |
381
|
|
|
'accounts.getAccountInfo', |
382
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
383
|
|
|
[ |
384
|
|
|
'auth' => 'gigya', |
385
|
|
|
'verify' => $this->certPath, |
386
|
|
|
'query' => [ |
387
|
|
|
'params' => 'passedThrough', |
388
|
|
|
], |
389
|
|
|
'option1' => 'value1', |
390
|
|
|
'option2' => false, |
391
|
|
|
], |
392
|
|
|
'key', |
393
|
|
|
'secret' |
394
|
|
|
); |
395
|
|
|
$client = $this->createClient(); |
396
|
|
|
|
397
|
|
|
$client->addOption('option1', 'value1'); |
398
|
|
|
$client->addOption('option2', false); |
399
|
|
|
|
400
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough']); |
401
|
|
|
|
402
|
|
|
static::assertSame($gigyaResponse, $result); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
View Code Duplication |
public function testAddingOptionsWithASingleCallPassesThroughTheOptionsToGuzzle() |
|
|
|
|
406
|
|
|
{ |
407
|
|
|
$gigyaResponse = $this->setupCall( |
408
|
|
|
'accounts.getAccountInfo', |
409
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
410
|
|
|
[ |
411
|
|
|
'auth' => 'gigya', |
412
|
|
|
'verify' => $this->certPath, |
413
|
|
|
'query' => [ |
414
|
|
|
'params' => 'passedThrough', |
415
|
|
|
], |
416
|
|
|
'option1' => 'value1', |
417
|
|
|
'option2' => true, |
418
|
|
|
], |
419
|
|
|
'key', |
420
|
|
|
'secret' |
421
|
|
|
); |
422
|
|
|
$client = $this->createClient(); |
423
|
|
|
|
424
|
|
|
$client->addOptions([ |
425
|
|
|
'option1' => 'value1', |
426
|
|
|
'option2' => true, |
427
|
|
|
]); |
428
|
|
|
|
429
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough']); |
430
|
|
|
|
431
|
|
|
static::assertSame($gigyaResponse, $result); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
View Code Duplication |
public function testAddingTheSameOptionAgainWillTakeTheLastValueSet() |
|
|
|
|
435
|
|
|
{ |
436
|
|
|
$gigyaResponse = $this->setupCall( |
437
|
|
|
'accounts.getAccountInfo', |
438
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
439
|
|
|
[ |
440
|
|
|
'auth' => 'gigya', |
441
|
|
|
'verify' => $this->certPath, |
442
|
|
|
'query' => [ |
443
|
|
|
'params' => 'passedThrough', |
444
|
|
|
], |
445
|
|
|
'option1' => false, |
446
|
|
|
], |
447
|
|
|
'key', |
448
|
|
|
'secret' |
449
|
|
|
); |
450
|
|
|
$client = $this->createClient(); |
451
|
|
|
|
452
|
|
|
$client->addOption('option1', 'value1'); |
453
|
|
|
$client->addOption('option1', false); |
454
|
|
|
|
455
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough']); |
456
|
|
|
|
457
|
|
|
static::assertSame($gigyaResponse, $result); |
458
|
|
|
} |
459
|
|
|
|
460
|
|
View Code Duplication |
public function testAddingTheSameOptionAgainWithAddOptionsWillTakeTheLastValueSet() |
|
|
|
|
461
|
|
|
{ |
462
|
|
|
$gigyaResponse = $this->setupCall( |
463
|
|
|
'accounts.getAccountInfo', |
464
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
465
|
|
|
[ |
466
|
|
|
'auth' => 'gigya', |
467
|
|
|
'verify' => $this->certPath, |
468
|
|
|
'query' => [ |
469
|
|
|
'params' => 'passedThrough', |
470
|
|
|
], |
471
|
|
|
'option1' => true, |
472
|
|
|
], |
473
|
|
|
'key', |
474
|
|
|
'secret' |
475
|
|
|
); |
476
|
|
|
$client = $this->createClient(); |
477
|
|
|
|
478
|
|
|
$client->addOption('option1', 'value1'); |
479
|
|
|
$client->addOptions(['option1' => true]); |
480
|
|
|
|
481
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough']); |
482
|
|
|
|
483
|
|
|
static::assertSame($gigyaResponse, $result); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
public function testAddingQueryOptionsWillBeIgnored() |
487
|
|
|
{ |
488
|
|
|
$gigyaResponse = $this->setupCall( |
489
|
|
|
'accounts.getAccountInfo', |
490
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
491
|
|
|
[ |
492
|
|
|
'auth' => 'gigya', |
493
|
|
|
'verify' => 'notAFile', |
494
|
|
|
'query' => [ |
495
|
|
|
'params' => 'passedThrough', |
496
|
|
|
], |
497
|
|
|
], |
498
|
|
|
'key', |
499
|
|
|
'secret' |
500
|
|
|
); |
501
|
|
|
$client = $this->createClient(); |
502
|
|
|
|
503
|
|
|
$client->addOption('query', 'random'); |
504
|
|
|
$client->addOption('verify', 'notAFile'); |
505
|
|
|
|
506
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough']); |
507
|
|
|
|
508
|
|
|
static::assertSame($gigyaResponse, $result); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
View Code Duplication |
public function testSettingOptionsAsPartOfTheQuery() |
|
|
|
|
512
|
|
|
{ |
513
|
|
|
$gigyaResponse = $this->setupCall( |
514
|
|
|
'accounts.getAccountInfo', |
515
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
516
|
|
|
[ |
517
|
|
|
'auth' => 'gigya', |
518
|
|
|
'verify' => $this->certPath, |
519
|
|
|
'query' => [ |
520
|
|
|
'params' => 'passedThrough', |
521
|
|
|
], |
522
|
|
|
'custom' => 'value', |
523
|
|
|
], |
524
|
|
|
'key', |
525
|
|
|
'secret' |
526
|
|
|
); |
527
|
|
|
$client = $this->createClient(); |
528
|
|
|
|
529
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough'], ['custom' => 'value']); |
530
|
|
|
|
531
|
|
|
static::assertSame($gigyaResponse, $result); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
View Code Duplication |
public function testSettingGlobalAndRequestOptionsTheRequestOptionsOverrideGlobalOptions() |
|
|
|
|
535
|
|
|
{ |
536
|
|
|
$gigyaResponse = $this->setupCall( |
537
|
|
|
'accounts.getAccountInfo', |
538
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
539
|
|
|
[ |
540
|
|
|
'auth' => 'gigya', |
541
|
|
|
'verify' => $this->certPath, |
542
|
|
|
'query' => [ |
543
|
|
|
'params' => 'passedThrough', |
544
|
|
|
], |
545
|
|
|
'custom' => 'value', |
546
|
|
|
], |
547
|
|
|
'key', |
548
|
|
|
'secret' |
549
|
|
|
); |
550
|
|
|
$client = $this->createClient(); |
551
|
|
|
|
552
|
|
|
$client->addOption('custom', 'notUsed'); |
553
|
|
|
|
554
|
|
|
$result = $client->accounts()->getAccountInfo(['params' => 'passedThrough'], ['custom' => 'value']); |
555
|
|
|
|
556
|
|
|
static::assertSame($gigyaResponse, $result); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
public function testSettingRequestOptionsDoOverrideTheParams() |
560
|
|
|
{ |
561
|
|
|
$gigyaResponse = $this->setupCall( |
562
|
|
|
'accounts.getAccountInfo', |
563
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
564
|
|
|
[ |
565
|
|
|
'auth' => 'gigya', |
566
|
|
|
'verify' => false, |
567
|
|
|
'query' => [ |
568
|
|
|
'params' => 'passedThrough', |
569
|
|
|
], |
570
|
|
|
], |
571
|
|
|
'key', |
572
|
|
|
'secret' |
573
|
|
|
); |
574
|
|
|
$client = $this->createClient(); |
575
|
|
|
|
576
|
|
|
$result = $client->accounts()->getAccountInfo( |
577
|
|
|
['params' => 'passedThrough'], |
578
|
|
|
['query' => 'value', 'verify' => false] |
579
|
|
|
); |
580
|
|
|
|
581
|
|
|
static::assertSame($gigyaResponse, $result); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
View Code Duplication |
public function testSettingParamsWillNotOverwriteTheDefaultParams() |
|
|
|
|
585
|
|
|
{ |
586
|
|
|
$gigyaResponse = $this->setupCall( |
587
|
|
|
'accounts.getAccountInfo', |
588
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
589
|
|
|
[ |
590
|
|
|
'auth' => 'gigya', |
591
|
|
|
'verify' => $this->certPath, |
592
|
|
|
'query' => [ |
593
|
|
|
'secret' => 'newSecret', |
594
|
|
|
], |
595
|
|
|
], |
596
|
|
|
'key', |
597
|
|
|
'secret' |
598
|
|
|
); |
599
|
|
|
$client = $this->createClient(); |
600
|
|
|
|
601
|
|
|
$result = $client->accounts()->getAccountInfo( |
602
|
|
|
['secret' => 'newSecret'] |
603
|
|
|
); |
604
|
|
|
|
605
|
|
|
static::assertSame($gigyaResponse, $result); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
View Code Duplication |
public function testCallingAChainWillCallThatChain() |
|
|
|
|
609
|
|
|
{ |
610
|
|
|
$gigyaResponse = $this->setupCall( |
611
|
|
|
'accounts.getAccountInfo', |
612
|
|
|
'https://fidm.eu1.gigya.com/fidm.saml.idp.getConfig', |
613
|
|
|
[ |
614
|
|
|
'auth' => 'gigya', |
615
|
|
|
'verify' => $this->certPath, |
616
|
|
|
'query' => [ |
617
|
|
|
'secret' => 'newSecret', |
618
|
|
|
], |
619
|
|
|
], |
620
|
|
|
'key', |
621
|
|
|
'secret' |
622
|
|
|
); |
623
|
|
|
$client = $this->createClient(); |
624
|
|
|
|
625
|
|
|
$result = $client->fidm()->{'saml.idp.getConfig'}( |
|
|
|
|
626
|
|
|
['secret' => 'newSecret'] |
627
|
|
|
); |
628
|
|
|
|
629
|
|
|
static::assertSame($gigyaResponse, $result); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
public function testWillCallAValidator() |
633
|
|
|
{ |
634
|
|
|
$response = $this->setupCall( |
635
|
|
|
'accounts.getAccountInfo', |
636
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
637
|
|
|
[ |
638
|
|
|
'auth' => 'gigya', |
639
|
|
|
'verify' => $this->certPath, |
640
|
|
|
'query' => [], |
641
|
|
|
], |
642
|
|
|
'key', |
643
|
|
|
'secret' |
644
|
|
|
); |
645
|
|
|
$client = $this->createClient(); |
646
|
|
|
|
647
|
|
|
$validator = m::mock(ResponseValidatorInterface::class); |
648
|
|
|
$client->addValidator($validator); |
649
|
|
|
$validator->shouldReceive('canValidate') |
650
|
|
|
->with($response) |
651
|
|
|
->andReturn(true); |
652
|
|
|
$validator->shouldReceive('assert') |
653
|
|
|
->with($response) |
654
|
|
|
->andReturn(true); |
655
|
|
|
|
656
|
|
|
static::assertSame($response, $client->accounts()->getAccountInfo()); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
public function tesWillCallMultipleValidators() |
660
|
|
|
{ |
661
|
|
|
$response = $this->setupCall( |
662
|
|
|
'accounts.getAccountInfo', |
663
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
664
|
|
|
[ |
665
|
|
|
'auth' => 'gigya', |
666
|
|
|
'verify' => $this->certPath, |
667
|
|
|
'query' => [], |
668
|
|
|
], |
669
|
|
|
'key', |
670
|
|
|
'secret' |
671
|
|
|
); |
672
|
|
|
$client = $this->createClient(); |
673
|
|
|
|
674
|
|
|
$validator = m::mock(ResponseValidatorInterface::class); |
675
|
|
|
$client->addValidator($validator); |
676
|
|
|
$validator->shouldReceive('canValidate') |
677
|
|
|
->with($response) |
678
|
|
|
->andReturn(true); |
679
|
|
|
$validator->shouldReceive('assert') |
680
|
|
|
->with($response) |
681
|
|
|
->andReturn(true); |
682
|
|
|
$validator2 = m::mock(ResponseValidatorInterface::class); |
683
|
|
|
$client->addValidator($validator2); |
684
|
|
|
$validator2->shouldReceive('canValidate') |
685
|
|
|
->with($response) |
686
|
|
|
->andReturn(true); |
687
|
|
|
$validator2->shouldReceive('assert') |
688
|
|
|
->with($response) |
689
|
|
|
->andReturn(true); |
690
|
|
|
|
691
|
|
|
static::assertSame($response, $client->accounts()->getAccountInfo()); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
public function testTheValidatorThrowingAnExceptionWillPassthrough() |
695
|
|
|
{ |
696
|
|
|
$response = $this->setupCall( |
697
|
|
|
'accounts.getAccountInfo', |
698
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
699
|
|
|
[ |
700
|
|
|
'auth' => 'gigya', |
701
|
|
|
'verify' => $this->certPath, |
702
|
|
|
'query' => [], |
703
|
|
|
], |
704
|
|
|
'key', |
705
|
|
|
'secret' |
706
|
|
|
); |
707
|
|
|
$client = $this->createClient(); |
708
|
|
|
|
709
|
|
|
$validator = m::mock(ResponseValidatorInterface::class); |
710
|
|
|
$validator2 = m::mock(ResponseValidatorInterface::class); |
711
|
|
|
$client->addValidator($validator); |
712
|
|
|
$client->addValidator($validator2); |
713
|
|
|
$exception = new Exception(); |
714
|
|
|
$validator->shouldReceive('canValidate') |
715
|
|
|
->with($response) |
716
|
|
|
->andReturn(true); |
717
|
|
|
$validator->shouldReceive('assert') |
718
|
|
|
->with($response) |
719
|
|
|
->andThrow($exception); |
720
|
|
|
|
721
|
|
|
static::setExpectedException(Exception::class); |
722
|
|
|
|
723
|
|
|
$client->accounts()->getAccountInfo(); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
public function testTheValidatorWillOnlyCallAssertWhenItCanValidate() |
727
|
|
|
{ |
728
|
|
|
$response = $this->setupCall( |
729
|
|
|
'accounts.getAccountInfo', |
730
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
731
|
|
|
[ |
732
|
|
|
'auth' => 'gigya', |
733
|
|
|
'verify' => $this->certPath, |
734
|
|
|
'query' => [], |
735
|
|
|
], |
736
|
|
|
'key', |
737
|
|
|
'secret' |
738
|
|
|
); |
739
|
|
|
$client = $this->createClient(); |
740
|
|
|
|
741
|
|
|
$validator = m::mock(ResponseValidatorInterface::class); |
742
|
|
|
$validator2 = m::mock(ResponseValidatorInterface::class); |
743
|
|
|
$client->addValidator($validator); |
744
|
|
|
$client->addValidator($validator2); |
745
|
|
|
$validator->shouldReceive('canValidate') |
746
|
|
|
->with($response) |
747
|
|
|
->andReturn(true); |
748
|
|
|
$validator->shouldReceive('assert') |
749
|
|
|
->with($response) |
750
|
|
|
->andReturn(true); |
751
|
|
|
$validator2->shouldReceive('canValidate') |
752
|
|
|
->with($response) |
753
|
|
|
->andReturn(false); |
754
|
|
|
|
755
|
|
|
static::assertSame($response, $client->accounts()->getAccountInfo()); |
756
|
|
|
} |
757
|
|
|
|
758
|
|
|
public function testRemoveSubscriberWillDetachFromEmitter() |
759
|
|
|
{ |
760
|
|
|
$response = $this->setupCall( |
761
|
|
|
'accounts.getAccountInfo', |
762
|
|
|
'https://accounts.eu1.gigya.com/accounts.getAccountInfo', |
763
|
|
|
[ |
764
|
|
|
'auth' => 'gigya', |
765
|
|
|
'verify' => $this->certPath, |
766
|
|
|
'query' => [], |
767
|
|
|
], |
768
|
|
|
'key', |
769
|
|
|
'secret' |
770
|
|
|
); |
771
|
|
|
$client = $this->createClient(); |
772
|
|
|
|
773
|
|
|
static::assertSame($response, $client->accounts()->getAccountInfo()); |
774
|
|
|
|
775
|
|
|
$subscriber = m::mock(SubscriberInterface::class); |
776
|
|
|
$this->emitter->shouldReceive('attach') |
777
|
|
|
->with($subscriber) |
778
|
|
|
->once(); |
779
|
|
|
|
780
|
|
|
$client->addSubscriber($subscriber); |
781
|
|
|
|
782
|
|
|
$this->emitter->shouldReceive('detach') |
783
|
|
|
->with($subscriber) |
784
|
|
|
->once(); |
785
|
|
|
|
786
|
|
|
$client->removeSubscriber($subscriber); |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* @return array |
791
|
|
|
*/ |
792
|
|
|
public function clientCallDataProvider() |
793
|
|
|
{ |
794
|
|
|
return [ |
795
|
|
|
['accounts', 'getAccountInfo', 'https://accounts.eu1.gigya.com/accounts.getAccountInfo'], |
796
|
|
|
['accounts', 'tfa.getCertificate', 'https://accounts.eu1.gigya.com/accounts.tfa.getCertificate'], |
797
|
|
|
['audit', 'search', 'https://audit.eu1.gigya.com/audit.search'], |
798
|
|
|
['comments', 'analyzeMediaItem', 'https://comments.eu1.gigya.com/comments.analyzeMediaItem'], |
799
|
|
|
['dataStore', 'get', 'https://ds.eu1.gigya.com/ds.get'], |
800
|
|
|
['ds', 'get', 'https://ds.eu1.gigya.com/ds.get'], |
801
|
|
|
['gameMechanics', 'getChallengeStatus', 'https://gm.eu1.gigya.com/gm.getChallengeStatus'], |
802
|
|
|
['gm', 'getChallengeStatus', 'https://gm.eu1.gigya.com/gm.getChallengeStatus'], |
803
|
|
|
['identityStorage', 'getSchema', 'https://ids.eu1.gigya.com/ids.getSchema'], |
804
|
|
|
['ids', 'getSchema', 'https://ids.eu1.gigya.com/ids.getSchema'], |
805
|
|
|
['reports', 'getGMStats', 'https://reports.eu1.gigya.com/reports.getGMStats'], |
806
|
|
|
['saml', 'setConfig', 'https://fidm.eu1.gigya.com/fidm.saml.setConfig'], |
807
|
|
|
['fidm', 'saml.setConfig', 'https://fidm.eu1.gigya.com/fidm.saml.setConfig'], |
808
|
|
|
['saml', 'idp.getConfig', 'https://fidm.eu1.gigya.com/fidm.saml.idp.getConfig'], |
809
|
|
|
['fidm', 'saml.idp.getConfig', 'https://fidm.eu1.gigya.com/fidm.saml.idp.getConfig'], |
810
|
|
|
['socialize', 'checkin', 'https://socialize.eu1.gigya.com/socialize.checkin'], |
811
|
|
|
]; |
812
|
|
|
} |
813
|
|
|
} |
814
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.