handleData() public method

public handleData ( $data )
Example #1
0
 /** @test */
 public function multivalueHeader()
 {
     $requestData = new RequestData('GET', 'http://www.example.com');
     $request = new Request($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', 'X-Xss-Protection' => '1; mode=block', 'Cache-Control' => 'public, must-revalidate, max-age=0'))->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("X-Xss-Protection:1; mode=block\r\n");
     $request->handleData("Cache-Control:public, must-revalidate, max-age=0\r\n");
     $request->handleData("\r\nbody");
     $this->assertNotNull($errorCallback);
     call_user_func($errorCallback, new \Exception('test'));
 }
 /** @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'));
 }
Example #3
0
 /** @test */
 public function chunkedStreamDecoder()
 {
     $requestData = new RequestData('GET', 'http://www.example.com');
     $request = new Request($this->connector, $requestData);
     $this->successfulConnectionMock();
     $request->end();
     $this->stream->expects($this->once())->method('emit')->with('data', ["1\r\nb\r"]);
     $request->handleData("HTTP/1.0 200 OK\r\n");
     $request->handleData("Transfer-Encoding: chunked\r\n");
     $request->handleData("\r\n1\r\nb\r");
     $request->handleData("\n3\t\nody\r\n0\t\n\r\n");
 }