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()); }
public function onBefore(puzzle_event_BeforeEvent $event) { $request = $event->getRequest(); // Set the appropriate Content-Type for a request if one is not set and // there are form fields if (!($body = $request->getBody())) { return; } $this->addContentLength($request, $body); if ($body instanceof puzzle_post_PostBodyInterface) { // Synchronize the POST body with the request's headers $body->applyRequestHeaders($request); } elseif (!$request->hasHeader('Content-Type')) { $this->addContentType($request, $body); } $this->addExpectHeader($request, $body); }
/** * @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); }
public function onBefore(puzzle_event_BeforeEvent $event) { $this->cookieJar->addCookieHeader($event->getRequest()); }