Ejemplo n.º 1
0
 /**
  * @covers Guzzle\Http\Plugin\BatchQueuePlugin::onRequestCreate
  * @covers Guzzle\Http\Plugin\BatchQueuePlugin::addRequest
  * @covers Guzzle\Http\Plugin\BatchQueuePlugin::onRequestBeforeSend
  */
 public function testWorksUsingEvents()
 {
     // Queue up some test responses
     $this->getServer()->flush();
     $this->getServer()->enqueue(array(new Response(200), new Response(200), new Response(200)));
     $plugin = new BatchQueuePlugin(2);
     $client = new Client($this->getServer()->getUrl());
     $client->getEventDispatcher()->addSubscriber($plugin);
     $client->get('/');
     $client->get('/');
     // Ensure that the requests were sent implicitly
     $this->assertEquals(0, count($plugin));
     $this->assertEquals(2, count($this->getServer()->getReceivedRequests()));
     // Add a single request and ensure that it is in queue and not sent
     $client->get('/');
     $this->assertEquals(1, count($plugin));
     $this->assertEquals(2, count($this->getServer()->getReceivedRequests()));
     // Explicitly flush the queued requests
     $client->dispatch('flush');
     $this->assertEquals(0, count($plugin));
     $this->assertEquals(3, count($this->getServer()->getReceivedRequests()));
 }