示例#1
0
 public function testSingleCallAgain()
 {
     $this->createBasicHandler();
     $this->startBenchmark();
     $this->gigya->accounts()->getAccountInfo(['uid' => 'some_uid']);
     $this->printBenchmark(__METHOD__, 1);
 }
示例#2
0
 /**
  * @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;
 }
示例#3
0
 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);
 }
示例#4
0
 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);
 }
示例#5
0
 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());
 }