/** @inheritdoc */
 public function send(RequestInterface $request)
 {
     $spiral = new Client($this->transport);
     $response = new Response();
     $spiral->request($request, $response);
     return $response;
 }
Пример #2
0
    public function testRequest()
    {
        $responseContent = <<<RESP
HTTP/1.1 302 FOUND
Server: nginx
Date: Tue, 09 Feb 2016 11:54:35 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 0
Connection: keep-alive
Location: get
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

HTTP/1.1 200 OK
Server: nginx
Date: Tue, 09 Feb 2016 11:54:35 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 30
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

<!doctype html>
<html>
</html>
RESP;
        $transferInfo = ['header_size' => 452, 'http_code' => 200, 'content_type' => 'text/html; charset=utf-8'];
        $transport = $this->getMockBuilder(Curl::class)->disableOriginalConstructor()->getMock();
        $transport->expects(static::once())->method('request')->will(static::returnValue($responseContent));
        $transport->expects(static::once())->method('responseInfo')->will(static::returnValue($transferInfo));
        $transport->expects(static::once())->method('close');
        $request = new Request('', 'GET');
        $response = new Response();
        $client = new Client($transport);
        $response = $client->request($request, $response);
        static::assertEquals(200, $response->getStatusCode());
        static::assertEquals('nginx', $response->getHeaderLine('Server'));
        static::assertFalse($response->hasHeader('Location'));
        static::assertEquals(1, preg_match('/^<!doctype html>/i', $response->getBody()));
    }