React\HttpClient\Request::setResponseFactory PHP Method

setResponseFactory() public method

public setResponseFactory ( $factory )
    public function setResponseFactory($factory)
    {
        $this->responseFactory = $factory;
    }

Usage Example

Esempio n. 1
0
 /** @test */
 public function requestShouldRelayErrorEventsFromResponse()
 {
     $requestData = new RequestData('GET', 'http://www.example.com');
     $request = new Request($this->loop, $this->connector, $requestData);
     $this->successfulConnectionMock();
     $response = $this->response;
     $response->expects($this->at(0))->method('on')->with('end', $this->anything());
     $response->expects($this->at(1))->method('on')->with('error', $this->anything())->will($this->returnCallback(function ($event, $cb) use(&$errorCallback) {
         $errorCallback = $cb;
     }));
     $factory = $this->createCallableMock();
     $factory->expects($this->once())->method('__invoke')->with('HTTP', '1.0', '200', 'OK', array('Content-Type' => 'text/plain'))->will($this->returnValue($response));
     $request->setResponseFactory($factory);
     $request->end();
     $request->handleData("HTTP/1.0 200 OK\r\n");
     $request->handleData("Content-Type: text/plain\r\n");
     $request->handleData("\r\nbody");
     $this->assertNotNull($errorCallback);
     call_user_func($errorCallback, new \Exception('test'));
 }
All Usage Examples Of React\HttpClient\Request::setResponseFactory