/home/desid573/public_html/tollster/vendor/google/auth/tests/HttpHandler
NameSizeModeActions
Guzzle5HttpHandlerTest.php63770644editdlrm
Guzzle6HttpHandlerTest.php22630644editdlrm
HttpHandlerFactoryTest.php11860644editdlrm
Edit: /home/desid573/public_html/tollster/vendor/google/auth/tests/HttpHandler/Guzzle5HttpHandlerTest.php (6377B)
onlyGuzzle5(); $this->mockPsr7Request = $this ->getMockBuilder('Psr\Http\Message\RequestInterface') ->getMock(); $this->mockRequest = $this ->getMockBuilder('GuzzleHttp\Message\RequestInterface') ->getMock(); $this->mockClient = $this ->getMockBuilder('GuzzleHttp\Client') ->disableOriginalConstructor() ->getMock(); $this->mockFuture = $this ->getMockBuilder('GuzzleHttp\Ring\Future\FutureInterface') ->disableOriginalConstructor() ->getMock(); } public function testSuccessfullySendsRealRequest() { $request = new \GuzzleHttp\Psr7\Request('get', 'http://httpbin.org/get'); $client = new \GuzzleHttp\Client(); $handler = new Guzzle5HttpHandler($client); $response = $handler($request); $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertEquals(200, $response->getStatusCode()); $json = json_decode((string) $response->getBody(), true); $this->assertArrayHasKey('url', $json); $this->assertEquals($request->getUri(), $json['url']); } public function testSuccessfullySendsMockRequest() { $response = new Response( 200, [], Stream::factory('Body Text') ); $this->mockClient ->expects($this->any()) ->method('send') ->will($this->returnValue($response)); $this->mockClient ->expects($this->any()) ->method('createRequest') ->will($this->returnValue($this->mockRequest)); $handler = new Guzzle5HttpHandler($this->mockClient); $response = $handler($this->mockPsr7Request); $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $response); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Body Text', (string) $response->getBody()); } public function testAsyncWithoutGuzzlePromiseThrowsException() { // Pretend the promise library doesn't exist foreach (spl_autoload_functions() as $function) { if ($function[0] instanceof ClassLoader) { $newAutoloader = clone $function[0]; $newAutoloader->setPsr4('GuzzleHttp\\Promise\\', '/tmp'); spl_autoload_register($newAutoloadFunc = [$newAutoloader, 'loadClass']); spl_autoload_unregister($previousAutoloadFunc = $function); } } $this->mockClient ->expects($this->any()) ->method('send') ->will($this->returnValue(new FutureResponse($this->mockFuture))); $this->mockClient ->expects($this->any()) ->method('createRequest') ->will($this->returnValue($this->mockRequest)); $handler = new Guzzle5HttpHandler($this->mockClient); $errorThrown = false; try { $handler->async($this->mockPsr7Request); } catch (Exception $e) { $this->assertEquals( 'Install guzzlehttp/promises to use async with Guzzle 5', $e->getMessage() ); $errorThrown = true; } // Restore autoloader before assertion (in case it fails) spl_autoload_register($previousAutoloadFunc); spl_autoload_unregister($newAutoloadFunc); $this->assertTrue($errorThrown); } public function testSuccessfullySendsRequestAsync() { $response = new Response( 200, [], Stream::factory('Body Text') ); $this->mockClient ->expects($this->any()) ->method('send') ->will($this->returnValue(new FutureResponse( new CompletedFutureValue($response) ))); $this->mockClient ->expects($this->any()) ->method('createRequest') ->will($this->returnValue($this->mockRequest)); $handler = new Guzzle5HttpHandler($this->mockClient); $promise = $handler->async($this->mockPsr7Request); $this->assertInstanceOf('Psr\Http\Message\ResponseInterface', $promise->wait()); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('Body Text', (string) $response->getBody()); } /** * @expectedException Exception * @expectedExceptionMessage This is a test rejection message */ public function testPromiseHandlesException() { $this->mockClient ->expects($this->any()) ->method('send') ->will($this->returnValue(new FutureResponse( (new CompletedFutureValue(new Response(200))) ->then(function () { throw new Exception('This is a test rejection message'); }) ))); $this->mockClient ->expects($this->any()) ->method('createRequest') ->will($this->returnValue($this->mockRequest)); $handler = new Guzzle5HttpHandler($this->mockClient); $promise = $handler->async($this->mockPsr7Request); $promise->wait(); } }