Пример #1
0
 public function testHasData()
 {
     $command = $this->getMock('GuzzleHttp\\Command\\CommandInterface');
     $client = $this->getMock('GuzzleHttp\\Command\\ServiceClientInterface');
     $trans = new CommandTransaction($client, $command);
     $request = new Request('GET', 'http://httbin.org');
     $response = new Response(200);
     $trans->setRequest($request);
     $trans->setResponse($response);
     $event = new ProcessEvent($trans);
     $this->assertSame($command, $event->getCommand());
     $this->assertSame($client, $event->getClient());
     $this->assertSame($request, $event->getRequest());
     $this->assertSame($response, $event->getResponse());
     $this->assertSame($trans, $event->getTransaction());
     $this->assertNull($event->getResult());
 }
 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());
 }
Пример #3
0
 public function testEmitsProcessEvent()
 {
     $req = new Request('GET', 'http://httbin.org');
     $res = new Response(200);
     $client = $this->getMockForAbstractClass('GuzzleHttp\\Command\\ServiceClientInterface');
     $cmd = new Command('foo', []);
     $trans = new CommandTransaction($client, $cmd);
     $trans->setRequest($req);
     $trans->setResponse($res);
     $c = false;
     $cmd->getEmitter()->on('process', function (ProcessEvent $e) use(&$c, $client, $cmd, $req, $res) {
         $e->setResult('foo');
         $this->assertSame($client, $e->getClient());
         $this->assertSame($cmd, $e->getCommand());
         $this->assertSame($req, $e->getRequest());
         $this->assertSame($res, $e->getResponse());
         $c = true;
     });
     CommandEvents::process($trans);
     $this->assertEquals('foo', $trans->getResult());
     $this->assertTrue($c);
 }