Skip to content
Permalink
Browse files

Integrating ConsoleOutput with ConsoleErrorHandler.

Updating test cases to match new output.
  • Loading branch information...
markstory committed Oct 4, 2010
1 parent ce4fe64 commit ffbb4e6b455e583451d6e366840c2f97457d0f12
@@ -17,8 +17,8 @@
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'ErrorHandler');
require_once 'console_output.php';
/**
* Error Handler for Cake console. Does simple printing of the
@@ -44,7 +44,7 @@ class ConsoleErrorHandler extends ErrorHandler {
* @param array $messages Error messages
*/
function __construct($error) {
$this->stderr = fopen('php://stderr', 'w');
$this->stderr = new ConsoleOutput('php://stderr');
parent::__construct($error);
}
@@ -105,15 +105,11 @@ public function error500($error) {
* @return void
*/
public function _outputMessage($template = null) {
$this->stderr($this->error->getMessage() . "\n" . $this->error->getTraceAsString());
$this->stderr->write(sprintf(
__("<error>Error:</error> %s\n%s"),
$this->error->getMessage(),
$this->error->getTraceAsString()
));
}
/**
* Outputs to the stderr filehandle.
*
* @param string $string Error text to output.
*/
public function stderr($string) {
fwrite($this->stderr, "Error: ". $string . "\n");
}
}
@@ -360,7 +360,7 @@ public function hr($newlines = 0) {
* @param string $message An optional error message
*/
public function error($title, $message = null) {
$this->err(sprintf(__('Error: %s'), $title));
$this->err(sprintf(__('<error>Error:</error> %s'), $title));
if (!empty($message)) {
$this->err($message);
@@ -32,7 +32,9 @@ class ConsoleErrorHandlerTest extends CakeTestCase {
* @return Mock object
*/
function getErrorHandler($exception) {
return $this->getMock('ConsoleErrorHandler', array('stderr'), array($exception));
$error = new ConsoleErrorHandler($exception);
$error->stderr = $this->getMock('ConsoleOutput');
return $error;
}
/**
@@ -44,7 +46,7 @@ function testCakeErrors() {
$exception = new MissingActionException('Missing action');
$error = $this->getErrorHandler($exception);
$error->expects($this->once())->method('stderr')
$error->stderr->expects($this->once())->method('write')
->with($this->stringContains('Missing action'));
$error->render();
@@ -59,7 +61,7 @@ function testNonCakeExceptions() {
$exception = new InvalidArgumentException('Too many parameters.');
$error = $this->getErrorHandler($exception);
$error->expects($this->once())->method('stderr')
$error->stderr->expects($this->once())->method('write')
->with($this->stringContains('Too many parameters.'));
$error->render();
@@ -74,7 +76,7 @@ function testError404Exception() {
$exception = new NotFoundException('dont use me in cli.');
$error = $this->getErrorHandler($exception);
$error->expects($this->once())->method('stderr')
$error->stderr->expects($this->once())->method('write')
->with($this->stringContains('dont use me in cli.'));
$error->render();
@@ -89,7 +91,7 @@ function testError500Exception() {
$exception = new InternalErrorException('dont use me in cli.');
$error = $this->getErrorHandler($exception);
$error->expects($this->once())->method('stderr')
$error->stderr->expects($this->once())->method('write')
->with($this->stringContains('dont use me in cli.'));
$error->render();
@@ -104,6 +106,6 @@ function testStdErrFilehandle() {
$exception = new InternalErrorException('dont use me in cli.');
$error = new ConsoleErrorHandler($exception);
$this->assertTrue(is_resource($error->stderr), 'No handle.');
$this->assertType('ConsoleOutput', $error->stderr, 'No handle.');
}
}
@@ -325,11 +325,11 @@ public function testHr() {
public function testError() {
$this->Shell->Dispatch->expects($this->at(0))
->method('stderr')
->with("Error: Foo Not Found\n");
->with("<error>Error:</error> Foo Not Found\n");
$this->Shell->Dispatch->expects($this->at(1))
->method('stderr')
->with("Error: Foo Not Found\n");
->with("<error>Error:</error> Foo Not Found\n");
$this->Shell->Dispatch->expects($this->at(2))
->method('stderr')

0 comments on commit ffbb4e6

Please sign in to comment.
You can’t perform that action at this time.