mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Adding a new line to the ConsoleErrorHandler
Refactoring ConsoleErrorHandler test to use dynamic mocks.
This commit is contained in:
parent
9fee81cda0
commit
8bd0f18a53
2 changed files with 31 additions and 36 deletions
|
@ -97,6 +97,7 @@ class ConsoleErrorHandler extends ErrorHandler {
|
||||||
public function error500($error) {
|
public function error500($error) {
|
||||||
$this->_outputMessage();
|
$this->_outputMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Outputs the exception to STDERR.
|
* Outputs the exception to STDERR.
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,21 +19,6 @@
|
||||||
*/
|
*/
|
||||||
require CAKE . 'console' . DS . 'console_error_handler.php';
|
require CAKE . 'console' . DS . 'console_error_handler.php';
|
||||||
|
|
||||||
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.
|
* ConsoleErrorHandler Test case.
|
||||||
*
|
*
|
||||||
|
@ -41,6 +26,15 @@ class TestConsoleErrorHandler extends ConsoleErrorHandler {
|
||||||
*/
|
*/
|
||||||
class ConsoleErrorHandlerTest extends CakeTestCase {
|
class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory method for error handlers with stderr() mocked out.
|
||||||
|
*
|
||||||
|
* @return Mock object
|
||||||
|
*/
|
||||||
|
function getErrorHandler($exception) {
|
||||||
|
return $this->getMock('ConsoleErrorHandler', array('stderr'), array($exception));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that the console error handler can deal with CakeExceptions.
|
* test that the console error handler can deal with CakeExceptions.
|
||||||
*
|
*
|
||||||
|
@ -48,12 +42,12 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testCakeErrors() {
|
function testCakeErrors() {
|
||||||
$exception = new MissingActionException('Missing action');
|
$exception = new MissingActionException('Missing action');
|
||||||
$error = new TestConsoleErrorHandler($exception);
|
$error = $this->getErrorHandler($exception);
|
||||||
$error->render();
|
|
||||||
|
|
||||||
$result = $error->output;
|
$error->expects($this->once())->method('stderr')
|
||||||
$this->assertEquals(1, count($result));
|
->with('Missing action');
|
||||||
$this->assertEquals('Missing action', $result[0]);
|
|
||||||
|
$error->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,12 +57,12 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testNonCakeExceptions() {
|
function testNonCakeExceptions() {
|
||||||
$exception = new InvalidArgumentException('Too many parameters.');
|
$exception = new InvalidArgumentException('Too many parameters.');
|
||||||
$error = new TestConsoleErrorHandler($exception);
|
$error = $this->getErrorHandler($exception);
|
||||||
$error->render();
|
|
||||||
|
|
||||||
$result = $error->output;
|
$error->expects($this->once())->method('stderr')
|
||||||
$this->assertEquals(1, count($result));
|
->with('Too many parameters.');
|
||||||
$this->assertEquals('Too many parameters.', $result[0]);
|
|
||||||
|
$error->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,12 +72,12 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testError404Exception() {
|
function testError404Exception() {
|
||||||
$exception = new NotFoundException('dont use me in cli.');
|
$exception = new NotFoundException('dont use me in cli.');
|
||||||
$error = new TestConsoleErrorHandler($exception);
|
$error = $this->getErrorHandler($exception);
|
||||||
$error->render();
|
|
||||||
|
|
||||||
$result = $error->output;
|
$error->expects($this->once())->method('stderr')
|
||||||
$this->assertEquals(1, count($result));
|
->with('dont use me in cli.');
|
||||||
$this->assertEquals('dont use me in cli.', $result[0]);
|
|
||||||
|
$error->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,12 +87,12 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testError500Exception() {
|
function testError500Exception() {
|
||||||
$exception = new InternalErrorException('dont use me in cli.');
|
$exception = new InternalErrorException('dont use me in cli.');
|
||||||
$error = new TestConsoleErrorHandler($exception);
|
$error = $this->getErrorHandler($exception);
|
||||||
$error->render();
|
|
||||||
|
|
||||||
$result = $error->output;
|
$error->expects($this->once())->method('stderr')
|
||||||
$this->assertEquals(1, count($result));
|
->with('dont use me in cli.');
|
||||||
$this->assertEquals('dont use me in cli.', $result[0]);
|
|
||||||
|
$error->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,7 +102,7 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
function testStdErrFilehandle() {
|
function testStdErrFilehandle() {
|
||||||
$exception = new InternalErrorException('dont use me in cli.');
|
$exception = new InternalErrorException('dont use me in cli.');
|
||||||
$error = new TestConsoleErrorHandler($exception);
|
$error = new ConsoleErrorHandler($exception);
|
||||||
|
|
||||||
$this->assertTrue(is_resource($error->stderr), 'No handle.');
|
$this->assertTrue(is_resource($error->stderr), 'No handle.');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue