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());
 }
 public function testHasData()
 {
     $command = $this->getMock('GuzzleHttp\\Command\\CommandInterface');
     $client = $this->getMock('GuzzleHttp\\Command\\ServiceClientInterface');
     $ctrans = new CommandTransaction($client, $command);
     $response = new Response(200);
     $ex = new \Exception('foo');
     $ctrans->setException($ex);
     $ctrans->setResponse($response);
     $event = new CommandErrorEvent($ctrans);
     $this->assertSame($ctrans, $event->getTransaction());
     $this->assertSame($command, $event->getCommand());
     $this->assertSame($client, $event->getClient());
     $this->assertSame($ex, $event->getException());
     $this->assertSame($response, $event->getResponse());
     $this->assertNull($event->getResult());
     $event->setResult('foo');
     $this->assertSame('foo', $event->getResult());
     $this->assertTrue($event->isPropagationStopped());
     $event->getContext()->set('abc', '123');
     $this->assertEquals('123', $ctrans->getContext()->get('abc'));
 }
 /**
  * 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);
 }