public function testHasTransactionMethods()
 {
     $t = new Transaction(new Client(), new Request('GET', '/'));
     $e = $this->getMockBuilder('GuzzleHttp\\Event\\AbstractRequestEvent')->setConstructorArgs([$t])->getMockForAbstractClass();
     $this->assertSame($t->getClient(), $e->getClient());
     $this->assertSame($t->getRequest(), $e->getRequest());
 }
 public function testEmitsAfterSendEventAndEmitsErrorIfNeeded()
 {
     $ex2 = $res = null;
     $request = new Request('GET', '/');
     $t = new Transaction(new Client(), $request);
     $t->setResponse(new Response(200));
     $ex = new RequestException('foo', $request);
     $t->getRequest()->getEmitter()->on('complete', function ($e) use($ex) {
         $ex->e = $e;
         throw $ex;
     });
     $t->getRequest()->getEmitter()->on('error', function ($e) use(&$ex2) {
         $ex2 = $e->getException();
         $e->stopPropagation();
     });
     RequestEvents::emitComplete($t);
     $this->assertSame($ex, $ex2);
 }
Exemplo n.º 3
0
 public function testHasRequestAndClient()
 {
     $c = new Client();
     $req = new Request('GET', '/');
     $response = new Response(200);
     $t = new Transaction($c, $req);
     $this->assertSame($c, $t->getClient());
     $this->assertSame($req, $t->getRequest());
     $this->assertNull($t->getResponse());
     $t->setResponse($response);
     $this->assertSame($response, $t->getResponse());
 }
 public function testInterceptsWithEvent()
 {
     $response = new Response(200);
     $res = null;
     $t = new Transaction(new Client(), new Request('GET', '/'));
     $t->getRequest()->getEmitter()->on('complete', function ($e) use(&$res) {
         $res = $e;
     });
     $e = new BeforeEvent($t);
     $e->intercept($response);
     $this->assertTrue($e->isPropagationStopped());
     $this->assertSame($res->getClient(), $e->getClient());
 }