public function testCanMutateData()
 {
     $client = $this->getMockForAbstractClass('GuzzleHttp\\Command\\ServiceClientInterface');
     $command = new Command('foo', []);
     $trans = new CommandTransaction($client, $command, ['foo' => 'bar']);
     $request = new Request('GET', 'http://foo.com');
     $trans->setRequest($request);
     $this->assertSame($request, $trans->getRequest());
     $response = new Response(200);
     $trans->setResponse($response);
     $this->assertSame($response, $trans->getResponse());
     $trans->setResult('foo');
     $this->assertSame('foo', $trans->getResult());
     $e = new \Exception('foo');
     $trans->setException($e);
     $this->assertSame($e, $trans->getException());
 }
 /**
  * Gets the HTTP request that will be sent for the command (if one is set).
  *
  * @return RequestInterface|null
  */
 public function getRequest()
 {
     return $this->trans->getRequest();
 }
Пример #3
0
 /**
  * Wrap HTTP level errors with command level errors.
  */
 private static function injectErrorHandler(CommandTransaction $trans)
 {
     $trans->getRequest()->getEmitter()->on('error', function (ErrorEvent $re) use($trans) {
         $re->stopPropagation();
         $trans->setException(self::exceptionFromError($trans, $re));
         $cev = new CommandErrorEvent($trans);
         $trans->getCommand()->getEmitter()->emit('error', $cev);
         if ($cev->isPropagationStopped()) {
             $trans->setException(null);
         }
     }, RequestEvents::LATE);
 }
 /**
  * Set the current request of the iterator and hook the request's event
  * system up to the command's event system.
  */
 private function processCurrentRequest(CommandTransaction $trans)
 {
     $this->currentRequest = $trans->getRequest();
     if ($this->currentRequest) {
         // Emit the command's process event when the request completes
         $this->currentRequest->getEmitter()->on('complete', function (CompleteEvent $event) use($trans) {
             $trans->setResponse($event->getResponse());
             CommandEvents::process($trans);
         });
     }
 }