public function __construct(HttpMessage $response = null) { if ($response && $response->getType() != HTTP_MSG_RESPONSE) { throw new Kwf_Exception("invalid response type"); } if ($response && ($response->getResponseCode() == 301 || $response->getResponseCode() == 302)) { //workaround for strange pecl_http bug that breaks requests that redirect to the same url again //and for some reason then there is only response message containing in the body the second response message (including http headers) if (preg_match('#^HTTP/1\\.. [0-9]{3} #', $response->getBody())) { $r = HttpMessage::factory($response->getBody()); if ($r->getType() == HTTP_MSG_RESPONSE) { $response = $r; } } } $this->_response = $response; }
public function testExecute() { $statusCode = 200; $statusMessage = 'OK'; $body = 'data'; $data = <<<EOF HTTP/1.1 {$statusCode} {$statusMessage} X-Foo: test {$body} EOF; $request = new Request(); $endpoint = new Endpoint(); $mockHttpRequest = $this->getMock('HttpRequest'); $mockHttpRequest->expects($this->once())->method('send')->will($this->returnValue(\HttpMessage::factory($data))); $mock = $this->getMock('Solarium\\Core\\Client\\Adapter\\PeclHttp', array('toHttpRequest')); $mock->expects($this->once())->method('toHttpRequest')->with($request, $endpoint)->will($this->returnValue($mockHttpRequest)); $response = $mock->execute($request, $endpoint); $this->assertEquals($body, $response->getBody()); $this->assertEquals($statusCode, $response->getStatusCode()); $this->assertEquals($statusMessage, $response->getStatusMessage()); }