2010-09-02 22:02:58 +00:00
|
|
|
<?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)
|
|
|
|
*/
|
2010-10-17 21:39:05 +00:00
|
|
|
require_once CONSOLE_LIBS . 'console_error_handler.php';
|
2010-09-02 22:02:58 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-05 15:22:39 +00:00
|
|
|
* ConsoleErrorHandler Test case.
|
2010-09-02 22:02:58 +00:00
|
|
|
*
|
2010-09-05 15:22:39 +00:00
|
|
|
* @package cake.tests.cases.console
|
2010-09-02 22:02:58 +00:00
|
|
|
*/
|
2010-09-05 15:22:39 +00:00
|
|
|
class ConsoleErrorHandlerTest extends CakeTestCase {
|
2010-09-02 22:02:58 +00:00
|
|
|
|
|
|
|
/**
|
2010-09-05 15:22:39 +00:00
|
|
|
* Factory method for error handlers with stderr() mocked out.
|
2010-09-02 22:02:58 +00:00
|
|
|
*
|
2010-09-05 15:22:39 +00:00
|
|
|
* @return Mock object
|
2010-09-02 22:02:58 +00:00
|
|
|
*/
|
2010-09-05 15:22:39 +00:00
|
|
|
function getErrorHandler($exception) {
|
2010-10-04 01:53:23 +00:00
|
|
|
$error = new ConsoleErrorHandler($exception);
|
2010-10-07 02:52:42 +00:00
|
|
|
$error->stderr = $this->getMock('ConsoleOutput', array(), array(), '', false);
|
2010-10-04 01:53:23 +00:00
|
|
|
return $error;
|
2010-09-05 15:22:39 +00:00
|
|
|
}
|
2010-09-02 22:02:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that the console error handler can deal with CakeExceptions.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testCakeErrors() {
|
|
|
|
$exception = new MissingActionException('Missing action');
|
2010-09-05 15:22:39 +00:00
|
|
|
$error = $this->getErrorHandler($exception);
|
|
|
|
|
2010-10-04 01:53:23 +00:00
|
|
|
$error->stderr->expects($this->once())->method('write')
|
2010-09-09 03:38:51 +00:00
|
|
|
->with($this->stringContains('Missing action'));
|
2010-09-02 22:02:58 +00:00
|
|
|
|
2010-09-05 15:22:39 +00:00
|
|
|
$error->render();
|
2010-09-02 22:02:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test a non CakeException exception.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testNonCakeExceptions() {
|
|
|
|
$exception = new InvalidArgumentException('Too many parameters.');
|
2010-09-05 15:22:39 +00:00
|
|
|
$error = $this->getErrorHandler($exception);
|
2010-09-02 22:02:58 +00:00
|
|
|
|
2010-10-04 01:53:23 +00:00
|
|
|
$error->stderr->expects($this->once())->method('write')
|
2010-09-09 03:38:51 +00:00
|
|
|
->with($this->stringContains('Too many parameters.'));
|
2010-09-05 15:22:39 +00:00
|
|
|
|
|
|
|
$error->render();
|
2010-09-02 22:02:58 +00:00
|
|
|
}
|
2010-09-02 22:04:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test a Error404 exception.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testError404Exception() {
|
2010-09-05 15:10:48 +00:00
|
|
|
$exception = new NotFoundException('dont use me in cli.');
|
2010-09-05 15:22:39 +00:00
|
|
|
$error = $this->getErrorHandler($exception);
|
2010-09-02 22:04:50 +00:00
|
|
|
|
2010-10-04 01:53:23 +00:00
|
|
|
$error->stderr->expects($this->once())->method('write')
|
2010-09-09 03:38:51 +00:00
|
|
|
->with($this->stringContains('dont use me in cli.'));
|
2010-09-05 15:22:39 +00:00
|
|
|
|
|
|
|
$error->render();
|
2010-09-02 22:04:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test a Error500 exception.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testError500Exception() {
|
2010-09-05 15:10:48 +00:00
|
|
|
$exception = new InternalErrorException('dont use me in cli.');
|
2010-09-05 15:22:39 +00:00
|
|
|
$error = $this->getErrorHandler($exception);
|
2010-09-02 22:04:50 +00:00
|
|
|
|
2010-10-04 01:53:23 +00:00
|
|
|
$error->stderr->expects($this->once())->method('write')
|
2010-09-09 03:38:51 +00:00
|
|
|
->with($this->stringContains('dont use me in cli.'));
|
2010-09-05 15:22:39 +00:00
|
|
|
|
|
|
|
$error->render();
|
2010-09-02 22:04:50 +00:00
|
|
|
}
|
2010-09-04 14:46:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* test that ConsoleErrorHandler has a stderr file handle.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testStdErrFilehandle() {
|
2010-09-05 15:10:48 +00:00
|
|
|
$exception = new InternalErrorException('dont use me in cli.');
|
2010-09-05 15:22:39 +00:00
|
|
|
$error = new ConsoleErrorHandler($exception);
|
2010-09-04 19:36:57 +00:00
|
|
|
|
2010-10-04 01:53:23 +00:00
|
|
|
$this->assertType('ConsoleOutput', $error->stderr, 'No handle.');
|
2010-09-04 14:46:04 +00:00
|
|
|
}
|
2010-09-02 22:02:58 +00:00
|
|
|
}
|