Skip to content

Commit

Permalink
Added tests to fatal error handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Apr 14, 2012
1 parent 1428659 commit eeec217
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion lib/Cake/Test/Case/Error/ErrorHandlerTest.php
Expand Up @@ -194,7 +194,7 @@ public function testHandleException() {
}

/**
* test handleException generating a page.
* test handleException generating log.
*
* @return void
*/
Expand Down Expand Up @@ -238,4 +238,57 @@ public function testLoadPluginHanlder() {
CakePlugin::unload();
}

/**
* test handleFatalError generating a page.
*
* @return void
*/
public function testHandleFatalErrorPage() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');

$originalDebugLevel = Configure::read('debug');
$line = __LINE__;
$error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => $line);

ob_start();
Configure::write('debug', 1);
ErrorHandler::handleFatalError($error);
$result = ob_get_clean();
$this->assertContains('Something wrong', $result, 'message missing.');
$this->assertContains(__FILE__, $result, 'filename missing.');
$this->assertContains((string)$line, $result, 'line missing.');

ob_start();
Configure::write('debug', 0);
ErrorHandler::handleFatalError($error);
$result = ob_get_clean();
$this->assertNotContains('Something wrong', $result, 'message must not appear.');
$this->assertNotContains(__FILE__, $result, 'filename must not appear.');
$this->assertContains('An Internal Error Has Occurred', $result);

Configure::write('debug', $originalDebugLevel);
}

/**
* test handleException generating log.
*
* @return void
*/
public function testHandleFatalErrorLog() {
$this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.');

if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
$error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => __LINE__);

ob_start();
ErrorHandler::handleFatalError($error);
ob_clean();

$log = file(LOGS . 'error.log');
$this->assertContains(__FILE__, $log[0], 'missing filename');
$this->assertContains('[FatalErrorException] Something wrong', $log[1], 'message missing.');
}

}

0 comments on commit eeec217

Please sign in to comment.