public function testEmitsEvents()
 {
     $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
     $request->setBody('foo');
     $request->setResponse(new Response(200));
     // Ensure that IO events are emitted
     $request->getParams()->set('curl.emit_io', true);
     // Attach listeners for each event type
     $request->getEventDispatcher()->addListener('curl.callback.progress', array($this, 'event'));
     $request->getEventDispatcher()->addListener('curl.callback.read', array($this, 'event'));
     $request->getEventDispatcher()->addListener('curl.callback.write', array($this, 'event'));
     $mediator = new RequestMediator($request, true);
     $mediator->progress('a', 'b', 'c', 'd');
     $this->assertEquals(1, count($this->events));
     $this->assertEquals('curl.callback.progress', $this->events[0]->getName());
     $this->assertEquals(3, $mediator->writeResponseBody('foo', 'bar'));
     $this->assertEquals(2, count($this->events));
     $this->assertEquals('curl.callback.write', $this->events[1]->getName());
     $this->assertEquals('bar', $this->events[1]['write']);
     $this->assertSame($request, $this->events[1]['request']);
     $this->assertEquals('foo', $mediator->readRequestBody('a', 'b', 3));
     $this->assertEquals(3, count($this->events));
     $this->assertEquals('curl.callback.read', $this->events[2]->getName());
     $this->assertEquals('foo', $this->events[2]['read']);
     $this->assertSame($request, $this->events[2]['request']);
 }
 public function testSetsCurlHandleParameter()
 {
     $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
     $mediator = new RequestMediator($request);
     $handle = $this->getMockBuilder('Guzzle\\Http\\Curl\\CurlHandle')->disableOriginalConstructor()->getMock();
     $mediator->setCurlHandle($handle);
     $this->assertSame($handle, $request->getParams()->get('curl_handle'));
 }
 /**
  * @covers Guzzle\Http\Message\EntityEnclosingRequest::configureRedirects
  */
 public function testCanDisableRedirects()
 {
     $request = new EntityEnclosingRequest('PUT', 'http://test.com/');
     $request->configureRedirects(false, false);
     $this->assertTrue($request->getParams()->get(RedirectPlugin::DISABLE));
 }
 public function testDoesNotSeekOnRequestsWithNoBodyWhenRetrying()
 {
     // Create a request with a body
     $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
     $request->getParams()->set(BackoffPlugin::DELAY_PARAM, 2);
     $plugin = new BackoffPlugin(new ConstantBackoffStrategy(0));
     $plugin->onRequestPoll($this->getMockEvent($request));
 }
 /**
  * @covers Guzzle\Http\Plugin\ExponentialBackoffPlugin::onRequestPoll
  */
 public function testDoesNotSeekOnRequestsWithNoBodyWhenRetrying()
 {
     // Create a request with a body
     $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
     $request->getParams()->set('plugins.exponential_backoff.retry_time', 2);
     $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
     $plugin->onRequestPoll($this->getMockEvent($request));
 }
 /**
  * @covers Guzzle\Http\Plugin\ExponentialBackoffPlugin::onRequestPoll
  */
 public function testSeeksToBeginningOfRequestBodyWhenRetrying()
 {
     // Create a mock curl multi object
     $multi = $this->getMockBuilder('Guzzle\\Http\\Curl\\CurlMulti')->setMethods(array('remove', 'add'))->getMock();
     // Create a request with a body
     $request = new EntityEnclosingRequest('PUT', 'http://www.example.com');
     $request->setBody('abc');
     // Set the retry time to be something that will be retried always
     $request->getParams()->set('plugins.exponential_backoff.retry_time', 2);
     // Seek to the end of the stream
     $request->getBody()->seek(3);
     $this->assertEquals('', $request->getBody()->read(1));
     // Create a plugin that does not delay when retrying
     $plugin = new ExponentialBackoffPlugin(2, null, array($this, 'delayClosure'));
     // Create an event that is expected for the Poll event
     $event = new Event(array('request' => $request, 'curl_multi' => $multi));
     $event->setName(CurlMultiInterface::POLLING_REQUEST);
     $plugin->onRequestPoll($event);
     // Ensure that the stream was seeked to 0
     $this->assertEquals('a', $request->getBody()->read(1));
 }