Esempio n. 1
0
 /**
  * @test
  */
 public function http_with_includeResponse_with_buffer()
 {
     $testData1 = str_repeat("1", 1000);
     $testData2 = str_repeat("1", 1000);
     $testData3 = str_repeat("1", 1000);
     $complete = false;
     $error = false;
     $method = "GET";
     $url = "https://www.example.com";
     $requestData = new RequestData($method, $url);
     $request = new Request($this->connector, $requestData);
     $response = new Response($this->stream, 'HTTP', '1.0', '200', 'OK', ['Content-Type' => 'text/plain']);
     $source = $this->createHttpObservable($request, $method, $url)->includeResponse();
     $source->subscribe(new CallbackObserver(function ($value) use(&$result) {
         $result = $value;
     }, function ($e) use(&$error) {
         $error = true;
     }, function () use(&$complete) {
         $complete = true;
     }));
     $request->emit("response", [$response]);
     $response->emit("data", [$testData1, $response]);
     $response->emit("data", [$testData2, $response]);
     $response->emit("data", [$testData3, $response]);
     $response->emit("end");
     $this->assertEquals($result[0], $testData1 . $testData2 . $testData3);
     $this->assertInstanceOf('React\\HttpClient\\Response', $result[1]);
     $this->assertInstanceOf('React\\HttpClient\\Request', $result[2]);
     $this->assertTrue($complete);
     $this->assertFalse($error);
 }