@ -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 )
{
{
@ -132,8 +133,6 @@ class FrontControllerTest extends PHPUnit_Framework_TestCase
{
{
$this -> setConstants ( false );
$this -> setConstants ( false );
$controller = FrontController :: getInstance ();
$controller = FrontController :: getInstance ();
$result = $controller -> execute ();
$controller = FrontController :: getInstance ();
$this -> assertNull ( $controller -> execute ());
$this -> assertNull ( $controller -> execute ());
}
}
@ -143,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: Error404Exception: Route for "" not found in ' , $error );
}
}
/**
/**
@ -157,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: GeneralException: Action class "userAction" not found. in ' , $error );
}
}
/**
/**
@ -172,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: GeneralException: Layout class "DefaultLayout" not found. in ' , $error );
}
}
/**
/**
@ -269,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 )