mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Adding a tests for CakeExceptions and non CakeExceptions
This commit is contained in:
parent
a44b35311d
commit
a1e01e414b
2 changed files with 94 additions and 2 deletions
|
@ -75,16 +75,35 @@ class ConsoleErrorHandler extends ErrorHandler {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function _cakeError($error) {
|
protected function _cakeError($error) {
|
||||||
$this->_outputMessage('');
|
$this->_outputMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override error404 method
|
||||||
|
*
|
||||||
|
* @param Exception $error Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function error404($error) {
|
||||||
|
$this->_outputMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override error500 method
|
||||||
|
*
|
||||||
|
* @param Exception $error Exception
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function error500($error) {
|
||||||
|
$this->_outputMessage();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Outputs the exception to STDERR.
|
* Outputs the exception to STDERR.
|
||||||
*
|
*
|
||||||
* @param string $template The name of the template to render.
|
* @param string $template The name of the template to render.
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function _outputMessage($template) {
|
public function _outputMessage($template = null) {
|
||||||
$this->stderr($this->error->getMessage());
|
$this->stderr($this->error->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
73
cake/tests/cases/console/console_error_handler.test.php
Normal file
73
cake/tests/cases/console/console_error_handler.test.php
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ConsoleErrorHandler Test case
|
||||||
|
*
|
||||||
|
* PHP versions 5
|
||||||
|
*
|
||||||
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||||
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
*
|
||||||
|
* Licensed under The MIT License
|
||||||
|
* Redistributions of files must retain the above copyright notice.
|
||||||
|
*
|
||||||
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||||
|
* @link http://cakephp.org CakePHP(tm) Project
|
||||||
|
* @package cake
|
||||||
|
* @subpackage cake.cake.tests.cases.console
|
||||||
|
* @since CakePHP(tm) v 2.0
|
||||||
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
|
*/
|
||||||
|
App::import('Core', 'ConsoleErrorHandler');
|
||||||
|
|
||||||
|
class TestConsoleErrorHandler extends ConsoleErrorHandler {
|
||||||
|
public $output = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override stderr() so it doesn't do bad things.
|
||||||
|
*
|
||||||
|
* @param string $line
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function stderr($line) {
|
||||||
|
$this->output[] = $line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConsoleErrorHandler Test case.
|
||||||
|
*
|
||||||
|
* @package cake.tests.cases.console
|
||||||
|
*/
|
||||||
|
class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that the console error handler can deal with CakeExceptions.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testCakeErrors() {
|
||||||
|
$exception = new MissingActionException('Missing action');
|
||||||
|
$error = new TestConsoleErrorHandler($exception);
|
||||||
|
$error->render();
|
||||||
|
|
||||||
|
$result = $error->output;
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
$this->assertEquals('Missing action', $result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test a non CakeException exception.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testNonCakeExceptions() {
|
||||||
|
$exception = new InvalidArgumentException('Too many parameters.');
|
||||||
|
$error = new TestConsoleErrorHandler($exception);
|
||||||
|
$error->render();
|
||||||
|
|
||||||
|
$result = $error->output;
|
||||||
|
$this->assertEquals(1, count($result));
|
||||||
|
$this->assertEquals('Too many parameters.', $result[0]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue