public function testToStringForFailure() { $guzzleResponse = m::mock(GuzzleResponseInterface::class); $guzzleResponse->shouldReceive('getBody')->andReturn($this->toStream(TestFixtures::getFixture('failure_403'))); $response = new Response($guzzleResponse); static::assertRegExp('/Response: \\d+: \\w+ - \\d+: .+\\n.+\\n.+\\n.+/s', $response->__toString()); }
public function testUnknownResponseContainsTheOriginalResponse() { $response = new Response(200, [], TestFixtures::getFixture('invalid_json')); $handler = new MockHandler([$response]); $middleware = ValidGigyaResponseMiddleware::middleware(); $func = $middleware($handler); try { $func(new Request('GET', 'https://foo.com'), [])->wait(); } catch (UnknownResponseException $e) { $this->assertSame($response, $e->getResponse()); } }
public function testError403() { $response = m::mock(GuzzleResponseInterface::class); $response->shouldReceive('getBody')->andReturn($this->tostream(TestFixtures::getFixture('failure_403'))); $gigyaResponse = $this->factory->getResponse($response); static::assertInstanceOf('Graze\\Gigya\\Response\\Response', $gigyaResponse); static::assertEquals(403, $gigyaResponse->getStatusCode()); static::assertEquals(403005, $gigyaResponse->getErrorCode()); static::assertEquals('Forbidden', $gigyaResponse->getStatusReason()); static::assertEquals('Unauthorized user', $gigyaResponse->getErrorMessage()); static::assertEquals('The user billyBob cannot login', $gigyaResponse->getErrorDetails()); }
public function createBasicHandler() { $handler = new MockHandler(array_pad([], 1000, new Response(200, [], TestFixtures::getFixture('basic')))); $this->gigya = new Gigya('key', 'secret', null, null, ['guzzle' => ['handler' => new HandlerStack($handler)]]); }
/** * @param string|null $body Optional body text * * @return HandlerStack */ public function setupHandler($body = null) { $mockHandler = new MockHandler(array_pad([], 3, new Response('200', [], $body ?: TestFixtures::getFixture('basic')))); return new HandlerStack($mockHandler); }
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()); }
/** * @dataProvider clientCallDataProvider * @param $namespace * @param $method * @param $expectedUri */ public function testClientCalls($namespace, $method, $expectedUri) { $client = $this->createClient(); $response = m::mock('GuzzleHttp\\Message\\ResponseInterface'); $response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('accounts.getAccountInfo')); $this->guzzleClient->shouldReceive('get')->with($expectedUri, ['query' => ['apiKey' => 'key', 'secret' => 'secret', 'params' => 'passedThrough'], 'cert' => $this->certPath])->andReturn($response); $gigyaResponse = m::mock('Graze\\Gigya\\Response\\ResponseInterface'); $this->factory->shouldReceive('getResponse')->with($response)->andReturn($gigyaResponse); $result = $client->{$namespace}()->{$method}(['params' => 'passedThrough']); static::assertSame($gigyaResponse, $result); }
public function testInvalidBody() { $response = m::mock('GuzzleHttp\\Message\\ResponseInterface'); $response->shouldReceive('getBody')->andReturn(TestFixtures::getFixture('invalid_json')); static::assertFalse($this->validator->validate($response)); static::setExpectedException('Graze\\Gigya\\Exceptions\\UnknownResponseException', "The contents of the response could not be determined. Could not decode the body"); $this->validator->assert($response); }