Ejemplo n.º 1
0
 public function testAddsProgress()
 {
     Server::enqueue([new Response(200)]);
     $client = new Client(['base_url' => Server::$url]);
     $request = $client->createRequest('GET');
     $called = false;
     $request->getEmitter()->on('progress', function (ProgressEvent $e) use(&$called) {
         $called = true;
     });
     $this->assertEquals(200, $client->send($request)->getStatusCode());
     $this->assertTrue($called);
 }
Ejemplo n.º 2
0
 public function testNestedFutureErrorsAreResolvedWhenSending()
 {
     $c = new Client();
     $total = 3;
     Server::enqueue([new Response(500), new Response(501), new Response(502)]);
     $c->getEmitter()->on('error', function (ErrorEvent $e) use(&$total) {
         if (--$total) {
             $e->retry();
         }
     });
     try {
         $c->get(Server::$url);
         $this->fail('Did not throw!');
     } catch (RequestException $e) {
         $this->assertEquals(502, $e->getResponse()->getStatusCode());
     }
 }
Ejemplo n.º 3
0
 public function testContentLengthIntegrationTest()
 {
     Server::flush();
     Server::enqueue([new Response(200)]);
     $client = new Client(['base_url' => Server::$url]);
     $this->assertEquals(200, $client->put('/', ['body' => 'test'])->getStatusCode());
     $request = Server::received(true)[0];
     $this->assertEquals('PUT', $request->getMethod());
     $this->assertEquals('4', $request->getHeader('Content-Length'));
     $this->assertEquals('test', (string) $request->getBody());
 }