コード例 #1
0
 public function testGetMock()
 {
     $clientMock = GuzzleFactory::createClientMock([new Response(200, ['content-type' => 'application/json', 'content-length' => 26, 'canaltp' => 42]), new Response(200, [], '{"lines":"expected-lines"}'), new Response(404, ['Content-Length' => 0])]);
     $this->assertInstanceOf('CanalTP\\AbstractGuzzle\\Guzzle', $clientMock);
     $firstCall = $clientMock->send(new Request('get', 'github'));
     $firstCallHeaders = $firstCall->getHeaders();
     $this->assertInstanceOf('GuzzleHttp\\Psr7\\Response', $firstCall);
     $this->assertEquals(200, $firstCall->getStatusCode());
     $this->assertEquals(42, $firstCallHeaders['canaltp'][0]);
     $this->assertEquals('application/json', $firstCallHeaders['content-type'][0]);
     $secondCall = $clientMock->send(new Request('post', 'packagist'));
     $this->assertEquals('{"lines":"expected-lines"}', $secondCall->getBody()->getContents());
     // since guzzle 6, exception will be throw in case of http errors
     try {
         $thirdCall = $clientMock->send(new Request('get', 'php/404'));
         $this->assertEquals(404, $thirdCall->getStatusCode());
     } catch (ClientException $e) {
         $this->assertEquals(404, $e->getResponse()->getStatusCode());
     }
 }
コード例 #2
0
 public function testClientMockForVersion6()
 {
     $clientMock = GuzzleFactory::createClientMock([]);
     $this->assertInstanceOf('CanalTP\\AbstractGuzzle\\Version\\Guzzle6', $clientMock);
 }