예제 #1
0
 /**
  * Hydrates the data from the executed request into the response instance.
  * @param \BluePsyduck\MultiCurl\Entity\Response $response
  * @param \BluePsyduck\MultiCurl\Entity\Request $request
  * @return $this
  */
 protected function hydrateResponse(Response $response, Request $request)
 {
     $curl = $request->getCurl();
     $headerSize = $curl->getInfo(CURLINFO_HEADER_SIZE);
     $rawContent = $this->multiCurl->getContent($curl);
     $response->setStatusCode($curl->getInfo(CURLINFO_HTTP_CODE))->setHeaders($this->parseHeaders(substr($rawContent, 0, $headerSize)))->setContent(substr($rawContent, $headerSize));
     return $this;
 }
예제 #2
0
 /**
  * Tests the hydrateResponse() method.
  * @covers \BluePsyduck\MultiCurl\Manager::hydrateResponse
  */
 public function testParseResponse()
 {
     $rawContent = 'abcdef';
     $rawHeader = 'abc';
     $headers = new Collection(array('abc' => 'def'));
     $content = 'def';
     $statusCode = 42;
     /* @var $curl \BluePsyduck\MultiCurl\Wrapper\Curl|\PHPUnit_Framework_MockObject_MockObject */
     $curl = $this->getMockBuilder('BluePsyduck\\MultiCurl\\Wrapper\\Curl')->setMethods(array('getInfo'))->getMock();
     $curl->expects($this->at(0))->method('getInfo')->with(CURLINFO_HEADER_SIZE)->willReturn(strlen($rawHeader));
     $curl->expects($this->at(1))->method('getInfo')->with(CURLINFO_HTTP_CODE)->willReturn($statusCode);
     $request = new Request();
     $request->setCurl($curl);
     /* @var $response \BluePsyduck\MultiCurl\Entity\Response|\PHPUnit_Framework_MockObject_MockObject */
     $response = $this->getMockBuilder('BluePsyduck\\MultiCurl\\Entity\\Response')->setMethods(array('setStatusCode', 'setHeaders', 'setContent'))->getMock();
     $response->expects($this->once())->method('setStatusCode')->with($statusCode)->willReturnSelf();
     $response->expects($this->once())->method('setHeaders')->with($headers)->willReturnSelf();
     $response->expects($this->once())->method('setContent')->with($content)->willReturnSelf();
     /* @var $multiCurl \BluePsyduck\MultiCurl\Wrapper\MultiCurl|\PHPUnit_Framework_MockObject_MockObject */
     $multiCurl = $this->getMockBuilder('BluePsyduck\\MultiCurl\\Wrapper\\MultiCurl')->setMethods(array('getContent'))->getMock();
     $multiCurl->expects($this->once())->method('getContent')->with($curl)->willReturn($rawContent);
     /* @var $manager \BluePsyduck\MultiCurl\Manager|\PHPUnit_Framework_MockObject_MockObject */
     $manager = $this->getMockBuilder('BluePsyduck\\MultiCurl\\Manager')->setMethods(array('parseHeaders'))->getMock();
     $manager->expects($this->once())->method('parseHeaders')->with($rawHeader)->willReturn($headers);
     $this->injectProperty($manager, 'multiCurl', $multiCurl);
     $result = $this->invokeMethod($manager, 'hydrateResponse', array($response, $request));
     $this->assertEquals($manager, $result);
 }
예제 #3
0
 /**
  * Tests the setResponse() method.
  * @covers \BluePsyduck\MultiCurl\Entity\Request::setResponse
  */
 public function testSetResponse()
 {
     $expected = new Response();
     $request = new Request();
     $result = $request->setResponse($expected);
     $this->assertEquals($request, $result);
     $this->assertPropertyEquals($expected, $request, 'response');
 }