public function it_adds_the_token_to_the_command_before_prepare(Event $event, CommandInterface $command) { /** @var EventDispatcher $dispatcher */ $dispatcher = $this->getEventDispatcher(); $event->offsetGet('command')->willReturn($command); $event->setDispatcher($dispatcher)->shouldBeCalled(); $event->setName('command.before_prepare')->shouldBeCalled(); $event->isPropagationStopped()->willReturn(false); $command->offsetSet('token', $this->config['token'])->shouldBeCalled(); $dispatcher->dispatch('command.before_prepare', $event); }
protected function getMockEvent(RequestInterface $request) { // Create a mock curl multi object $multi = $this->getMockBuilder('Guzzle\\Http\\Curl\\CurlMulti')->setMethods(array('remove', 'add'))->getMock(); // Create an event that is expected for the Poll event $event = new Event(array('request' => $request, 'curl_multi' => $multi)); $event->setName(CurlMultiInterface::POLLING_REQUEST); return $event; }
/** * @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)); }