Browse Source

Use new logError in FrontController, tests

namespace
Anton Terekhov 12 years ago
parent
commit
5f47dab73e
  1. 24
      app/ErrorAction.php
  2. 1
      app/FrontController.php
  3. 14
      tests/app/FrontControllerTest.php

24
app/ErrorAction.php

@ -63,29 +63,7 @@ class ErrorAction extends Action
protected function logError() protected function logError()
{ {
if ($this->template == 500) { if ($this->template == 500) {
$error = 0;
$ex = $this->exception;
if ($ex instanceof ErrorException) {
$error = $ex->getSeverity();
}
switch ($error) {
case E_NOTICE:
$error = 'Notice';
break;
case E_WARNING:
$error = 'Warning';
break;
case E_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown Error';
break;
}
$message = 'PHP ' . $error . ': ' . $ex->getMessage() . ' in ' . $ex->getFile()
. ' on line ' . $ex->getLine();
error_log($message);
ErrorHandler::logError($this->exception);
} }
} }

1
app/FrontController.php

@ -143,6 +143,7 @@ class FrontController
header('HTTP/1.0 500 Internal Server Error'); header('HTTP/1.0 500 Internal Server Error');
} }
} }
ErrorHandler::logError($e);
return ErrorHandler::showDebug($e); return ErrorHandler::showDebug($e);
} }
$layout_class = $this->getRouter()->getErrorLayout(); $layout_class = $this->getRouter()->getErrorLayout();

14
tests/app/FrontControllerTest.php

@ -28,6 +28,7 @@ require_once dirname(__FILE__) . '/../../app/AjaxAction.php';
class FrontControllerTest extends PHPUnit_Framework_TestCase class FrontControllerTest extends PHPUnit_Framework_TestCase
{ {
protected $log_file_name = 'error_log_file';
public function run(PHPUnit_Framework_TestResult $result = NULL) public function run(PHPUnit_Framework_TestResult $result = NULL)
{ {
@ -141,11 +142,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
public function testExecuteNoRouteDebug() public function testExecuteNoRouteDebug()
{ {
$this->setConstants(true); $this->setConstants(true);
ini_set('error_log', $this->log_file_name);
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$result = $controller->execute(); $result = $controller->execute();
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
$this->assertContains('Route for "" not found', $result); $this->assertContains('Route for "" not found', $result);
$this->assertContains('Error404Exception', $result); $this->assertContains('Error404Exception', $result);
$error = file_get_contents($this->log_file_name);
$this->assertContains('PHP Unknown Error: Route for "" not found', $error);
} }
/** /**
@ -155,11 +159,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{ {
$_SERVER['REQUEST_URI'] = '/user/account/213'; $_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true); $this->setConstants(true);
ini_set('error_log', $this->log_file_name);
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$router = $controller->getRouter(); $router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'user'); $router->add('user', 'user/account/:id', 'user');
$result = $controller->execute(); $result = $controller->execute();
$this->assertContains('Action class "userAction" not found.', $result); $this->assertContains('Action class "userAction" not found.', $result);
$error = file_get_contents($this->log_file_name);
$this->assertContains('PHP Unknown Error: Action class "userAction" not found.', $error);
} }
/** /**
@ -170,11 +177,14 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
$this->getMock('userAction'); $this->getMock('userAction');
$_SERVER['REQUEST_URI'] = '/user/account/213'; $_SERVER['REQUEST_URI'] = '/user/account/213';
$this->setConstants(true); $this->setConstants(true);
ini_set('error_log', $this->log_file_name);
$controller = FrontController::getInstance(); $controller = FrontController::getInstance();
$router = $controller->getRouter(); $router = $controller->getRouter();
$router->add('user', 'user/account/:id', 'user'); $router->add('user', 'user/account/:id', 'user');
$result = $controller->execute(); $result = $controller->execute();
$this->assertContains('Layout class "DefaultLayout" not found.', $result); $this->assertContains('Layout class "DefaultLayout" not found.', $result);
$error = file_get_contents($this->log_file_name);
$this->assertContains('PHP Unknown Error: Layout class "DefaultLayout" not found.', $error);
} }
/** /**
@ -267,6 +277,10 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
public function tearDown() public function tearDown()
{ {
unset_new_overload(); unset_new_overload();
if (file_exists($this->log_file_name) && is_writable($this->log_file_name)) {
unlink($this->log_file_name);
}
ini_set('error_log', 'php://stderr');
} }
protected function newCallback($className) protected function newCallback($className)

Loading…
Cancel
Save