Exemplo n.º 1
0
 public function __callback_testBeforeSendEmitsErrorEvent_1(puzzle_event_BeforeEvent $e)
 {
     $this->assertSame($this->_closure_testBeforeSendEmitsErrorEvent_request, $e->getRequest());
     $this->assertSame($this->_closure_testBeforeSendEmitsErrorEvent_client, $e->getClient());
     $this->_closure_testBeforeSendEmitsErrorEvent_beforeCalled++;
     throw $this->_closure_testBeforeSendEmitsErrorEvent_ex;
 }
 public function testInterceptsWithEvent()
 {
     $response = new puzzle_message_Response(200);
     $this->_closure_testInterceptsWithEvent_res = null;
     $t = new puzzle_adapter_Transaction(new puzzle_Client(), new puzzle_message_Request('GET', '/'));
     $t->getRequest()->getEmitter()->on('complete', array($this, '__callback_testInterceptsWithEvent'));
     $e = new puzzle_event_BeforeEvent($t);
     $e->intercept($response);
     $this->assertTrue($e->isPropagationStopped());
     $this->assertSame($this->_closure_testInterceptsWithEvent_res->getClient(), $e->getClient());
 }
Exemplo n.º 3
0
 /**
  * @throws OutOfBoundsException|Exception
  */
 public function onBefore(puzzle_event_BeforeEvent $event)
 {
     if (!($item = array_shift($this->queue))) {
         throw new OutOfBoundsException('Mock queue is empty');
     } elseif ($item instanceof puzzle_exception_RequestException) {
         throw $item;
     }
     // Emulate the receiving of the response headers
     $request = $event->getRequest();
     $transaction = new puzzle_adapter_Transaction($event->getClient(), $request);
     $transaction->setResponse($item);
     $request->getEmitter()->emit('headers', new puzzle_event_HeadersEvent($transaction));
     // Emulate reading a response body
     if ($this->readBodies && $request->getBody()) {
         while (!$request->getBody()->eof()) {
             $request->getBody()->read(8096);
         }
     }
     $event->intercept($item);
 }