Exemple #1
0
 public function onError(puzzle_event_ErrorEvent $event)
 {
     // Only track when no response is present, meaning this didn't ever
     // emit a complete event
     if (!$event->getResponse()) {
         $this->add($event->getRequest());
     }
 }
Exemple #2
0
 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));
 }
Exemple #4
0
 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_testThrowsImmediatelyIfInstructed_1(puzzle_event_ErrorEvent $e)
 {
     $e->throwImmediately(true);
 }
 public function __callback_testCanHandleExceptionsUsingEvents(puzzle_event_ErrorEvent $e)
 {
     $e->intercept($this->_closure_testCanHandleExceptionsUsingEvents_mockResponse);
 }
 public function __callback_testEmitsErrorEventForRequestExceptionsThrownDuringBeforeThatHaveNotEmittedAnErrorEvent_2(puzzle_event_ErrorEvent $event)
 {
     $this->_closure_testEmitsErrorEventForRequestExceptionsThrownDuringBeforeThatHaveNotEmittedAnErrorEvent_called = true;
     $this->assertSame($this->_closure_testEmitsErrorEventForRequestExceptionsThrownDuringBeforeThatHaveNotEmittedAnErrorEvent_ex, $event->getException());
 }
 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);
     }
 }