public function testInterceptsWithEvent() { $client = new puzzle_Client(); $request = new puzzle_message_Request('GET', '/'); $response = new puzzle_message_Response(404); $transaction = new puzzle_adapter_Transaction($client, $request); $except = new puzzle_exception_RequestException('foo', $request, $response); $event = new puzzle_event_ErrorEvent($transaction, $except); $event->throwImmediately(true); $this->assertTrue($except->getThrowImmediately()); $event->throwImmediately(false); $this->assertFalse($except->getThrowImmediately()); $this->assertSame($except, $event->getException()); $this->assertSame($response, $event->getResponse()); $this->assertSame($request, $event->getRequest()); $this->_closure_testInterceptsWithEvent_res = null; $request->getEmitter()->on('complete', array($this, '__callback_testInterceptsWithEvent')); $good = new puzzle_message_Response(200); $event->intercept($good); $this->assertTrue($event->isPropagationStopped()); $this->assertSame($this->_closure_testInterceptsWithEvent_res->getClient(), $event->getClient()); $this->assertSame($good, $this->_closure_testInterceptsWithEvent_res->getResponse()); }
public function __callback_testHandlesErrors_2(puzzle_event_ErrorEvent $e) { $e->intercept(new puzzle_message_Response(201)); }
public function __callback_testDispatchesErrorEventAndRecovers_2(puzzle_event_ErrorEvent $e) { $e->intercept(new puzzle_message_Response(200, array('Foo' => 'bar'))); }
public function __callback_testHandlesCurlErrors(puzzle_event_ErrorEvent $e) { $e->intercept($this->_closure_testHandlesCurlErrors_r); }
public function __callback_testCanHandleExceptionsUsingEvents(puzzle_event_ErrorEvent $e) { $e->intercept($this->_closure_testCanHandleExceptionsUsingEvents_mockResponse); }
public function __callback_testBeforeSendEmitsErrorEvent_2(puzzle_event_ErrorEvent $e) { $this->_closure_testBeforeSendEmitsErrorEvent_errCalled++; $this->assertInstanceOf('puzzle_exception_RequestException', $e->getException()); if (version_compare(PHP_VERSION, '5.3') >= 0) { $this->assertSame($this->_closure_testBeforeSendEmitsErrorEvent_ex, $e->getException()->getPrevious()); } $e->intercept($this->_closure_testBeforeSendEmitsErrorEvent_response); }
public function onError(puzzle_event_ErrorEvent $errorEvent) { $puzzleException = $errorEvent->getException(); $tubePressException = new tubepress_http_impl_puzzle_RequestException($puzzleException); $eventDispatcher = $this->getEventDispatcher(); $event = $eventDispatcher->newEventInstance($tubePressException, array('response' => null)); $eventDispatcher->dispatch(tubepress_api_http_Events::EVENT_HTTP_ERROR, $event); $response = $event->getArgument('response'); if ($response && $response instanceof tubepress_api_http_message_ResponseInterface) { $puzzleResponse = new puzzle_message_Response($response->getStatusCode(), $response->getHeaders(), $response->getBody()); $errorEvent->intercept($puzzleResponse); } }