Esempio n. 1
0
 public function testEmitsProgress()
 {
     $client = new Client(['handler' => function () {
         throw new \RuntimeException('No network access');
     }]);
     $responses = [new Response(200), new Response(404)];
     $client->getEmitter()->attach(new Mock($responses));
     $requests = [$client->createRequest('GET', 'http://foo.com/baz'), $client->createRequest('HEAD', 'http://httpbin.org/get')];
     $pool = new Pool($client, $requests);
     $count = 0;
     $thenned = null;
     $pool->then(function ($value) use(&$thenned) {
         $thenned = $value;
     }, null, function ($result) use(&$count, $requests) {
         $this->assertSame($requests[$count], $result['request']);
         if ($count == 0) {
             $this->assertNull($result['error']);
             $this->assertEquals(200, $result['response']->getStatusCode());
         } else {
             $this->assertInstanceOf('GuzzleHttp\\Exception\\ClientException', $result['error']);
         }
         $count++;
     });
     $pool->wait();
     $this->assertEquals(2, $count);
     $this->assertEquals(true, $thenned);
 }