public function testFlashes() { // Test data $test_session_key = '__flashes'; $test_flashes = array(array('message' => 'Test info message', 'type' => 'info'), array('message' => 'Test error message', 'type' => 'error'), array('message' => 'Test second error message', 'type' => 'error'), array('message' => 'Test whatever message', 'type' => 'whatever')); $test_error_flashes = array($test_flashes[1]['message'], $test_flashes[2]['message']); $service = new ServiceProvider(); $this->assertEmpty($_SESSION); $this->assertEmpty($service->flashes()); $service->flash($test_flashes[0]['message'], $test_flashes[0]['type']); $service->flash($test_flashes[1]['message'], $test_flashes[1]['type']); $service->flash($test_flashes[2]['message'], $test_flashes[2]['type']); $service->flash($test_flashes[3]['message'], $test_flashes[3]['type']); // Test error flashes only $error_flashes = $service->flashes('error'); $this->assertCount(2, $error_flashes); $this->assertSame($test_error_flashes, $error_flashes); // Test the rest $all_flashes = $service->flashes(); $this->assertCount(count($test_flashes) - count($error_flashes), $all_flashes); // Clean up session_destroy(); $_SESSION = array(); }
/** * Routes an exception through the error callbacks * * @param Exception $err The exception that occurred * @throws UnhandledException If the error/exception isn't handled by an error callback * @access protected * @return void */ protected function error(Exception $err) { $type = get_class($err); $msg = $err->getMessage(); if (count($this->errorCallbacks) > 0) { foreach (array_reverse($this->errorCallbacks) as $callback) { if (is_callable($callback)) { if (is_string($callback)) { $callback($this, $msg, $type, $err); return; } else { call_user_func($callback, $this, $msg, $type, $err); return; } } else { if (null !== $this->service && null !== $this->response) { $this->service->flash($err); $this->response->redirect($callback); } } } } else { $this->response->code(500); throw new UnhandledException($msg, $err->getCode(), $err); } // Lock our response, since we probably don't want // anything else messing with our error code/body $this->response->lock(); }
/** * Routes an exception through the error callbacks * * @param Exception $err The exception that occurred * @access protected * @return void */ protected function error(Exception $err) { $type = get_class($err); $msg = $err->getMessage(); if (count($this->errorCallbacks) > 0) { foreach (array_reverse($this->errorCallbacks) as $callback) { if (is_callable($callback)) { if (is_string($callback)) { if ($callback($this, $msg, $type, $err)) { return; } } else { if (call_user_func($callback, $this, $msg, $type, $err)) { return; } } } else { if (null !== $this->service && null !== $this->response) { $this->service->flash($err); $this->response->redirect($callback); } } } } else { $this->response->code(500); throw new UnhandledException($err); } }