public function testSingleCallAgain() { $this->createBasicHandler(); $this->startBenchmark(); $this->gigya->accounts()->getAccountInfo(['uid' => 'some_uid']); $this->printBenchmark(__METHOD__, 1); }
/** * @return AccessToken|null */ public function getToken() { if (!is_null($this->token) && $this->token->isExpired()) { $this->token = null; } if (is_null($this->token)) { $response = $this->gigya->socialize()->getToken(['grant_type' => 'none'], ['auth' => 'credentials']); if ($response->getErrorCode() == ErrorCode::OK) { $data = $response->getData(); $token = $data->get('access_token'); $expires = null; if ($data->has('expires_in')) { $expires = (new DateTime())->add(new DateInterval(sprintf('PT%dS', $data->get('expires_in', 0)))); } $this->token = new AccessToken($token, $expires); } } return $this->token; }
public function testSettingTheUserKeyWillPassItThroughToGuzzle() { $client = new Gigya('key', 'userSecret', Gigya::DC_EU, 'userKey'); $response = m::mock('GuzzleHttp\\Message\\ResponseInterface'); $response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('accounts.getAccountInfo')); $this->guzzleClient->shouldReceive('get')->with('https://accounts.eu1.gigya.com/accounts.getAccountInfo', ['query' => ['apiKey' => 'key', 'secret' => 'userSecret', 'userKey' => 'userKey'], 'cert' => $this->certPath])->andReturn($response); $gigyaResponse = m::mock('Graze\\Gigya\\Response\\ResponseInterface'); $this->factory->shouldReceive('getResponse')->with($response)->andReturn($gigyaResponse); $result = $client->accounts()->getAccountInfo([]); static::assertSame($gigyaResponse, $result); }
public function testGigyaWillTriggerSubscriberOnlyWhenItIsAddedInARequest() { $handler = $this->setupHandler(); $client = new Gigya('key', 'secret', null, null, ['guzzle' => ['handler' => $handler]]); $client->accounts()->getAccountInfo(); $called = 0; $fn = function (callable $handler) use(&$called) { return function (RequestInterface $request, $options) use($handler, &$called) { $called++; return $handler($request, $options); }; }; $client->addHandler($fn); $client->accounts()->getAccountInfo(); $this->assertEquals(1, $called); $client->removeHandler($fn); $client->accounts()->getAccountInfo(); $this->assertEquals(1, $called); }
public function testCredentialsAuthConstructor() { $this->guzzleClient->shouldReceive('__construct')->with(['handler' => $this->handlerStack])->once()->andReturn($this->guzzleClient); $response = new Response(200, [], TestFixtures::getFixture('account.getAccountInfo')); $this->guzzleClient->shouldReceive('get')->with('https://accounts.au1.gigya.com/accounts.getAccountInfo', ['cert' => 'some_cert.pem', 'auth' => 'credentials', 'verify' => $this->certPath, 'query' => []])->once()->andReturn($response); $gigyaResponse = m::mock('Graze\\Gigya\\Response\\ResponseInterface'); $this->factory->shouldReceive('getResponse')->with($response)->andReturn($gigyaResponse); $config = ['auth' => 'credentials', 'uidValidator' => false, 'factory' => $this->factory, 'guzzle' => ['handler' => $this->handlerStack], 'options' => ['cert' => 'some_cert.pem']]; $client = new Gigya('key', 'secret', Gigya::DC_AU, null, $config); static::assertSame($gigyaResponse, $client->accounts()->getAccountInfo()); }