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()); }
/** * @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); }
public function __callback_testCanInterceptBeforeSending(puzzle_event_BeforeEvent $e) { $e->intercept($this->_closure_testCanInterceptBeforeSending_response); }
public function __callback_testSendingRequestCanBeIntercepted(puzzle_event_BeforeEvent $e) { $e->intercept($this->_closure_testSendingRequestCanBeIntercepted_response); }