Skip to content

Commit

Permalink
Updating debugger and error_handler tests to remove errors in CLI.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Sep 25, 2010
1 parent 98d1272 commit 326ae97
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 37 deletions.
6 changes: 0 additions & 6 deletions cake/tests/cases/libs/debugger.test.php
Expand Up @@ -218,14 +218,9 @@ function testExportVar() {
$result = Debugger::exportVar($View);
$expected = 'View
View::$Helpers = HelperCollection object
View::$base = NULL
View::$here = NULL
View::$plugin = NULL
View::$name = ""
View::$action = NULL
View::$params = array
View::$passedArgs = array
View::$data = array
View::$helpers = array
View::$viewPath = ""
View::$viewVars = array
Expand All @@ -247,7 +242,6 @@ function testExportVar() {
View::$modelId = NULL
View::$uuids = array
View::$output = false
View::$webroot = NULL
View::$request = NULL';
$result = str_replace(array("\t", "\r\n", "\n"), "", strtolower($result));
$expected = str_replace(array("\t", "\r\n", "\n"), "", strtolower($expected));
Expand Down
58 changes: 27 additions & 31 deletions cake/tests/cases/libs/error_handler.test.php
Expand Up @@ -44,6 +44,7 @@ class AuthBlueberryUser extends CakeTestModel {
*/
public $useTable = false;
}

if (!class_exists('AppController')) {
/**
* AppController class
Expand All @@ -68,24 +69,6 @@ class AppController extends Controller {
function beforeRender() {
echo $this->Blueberry->testName;
}
/**
* header method
*
* @access public
* @return void
*/
function header($header) {
echo $header;
}
/**
* _stop method
*
* @access public
* @return void
*/
function _stop($status = 0) {
echo 'Stopped with status: ' . $status;
}
}
} elseif (!defined('APP_CONTROLLER_EXISTS')){
define('APP_CONTROLLER_EXISTS', true);
Expand Down Expand Up @@ -228,7 +211,17 @@ function setUp() {

function teardown() {
Configure::write('debug', $this->_debug);
}
}

/**
* Mocks out the response on the errorhandler object so headers aren't modified.
*
* @return void
*/
protected function _mockResponse($error) {
$error->controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
return $error;
}

/**
* test handleException generating a page.
Expand All @@ -239,6 +232,9 @@ function testHandleException() {
if ($this->skipIf(file_exists(APP . 'app_error.php'), 'App error exists cannot run.')) {
return;
}
if ($this->skipIf(PHP_SAPI == 'cli', 'This integration test can not be run in cli.')) {
return;
}
$error = new NotFoundException('Kaboom!');
ob_start();
ErrorHandler::handleException($error);
Expand All @@ -256,7 +252,7 @@ function testSubclassMethodsNotBeingConvertedToError() {
Configure::write('debug', 2);

$exception = new MissingWidgetThingException('Widget not found');
$ErrorHandler = new MyCustomErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));

ob_start();
$ErrorHandler->render();
Expand All @@ -273,7 +269,7 @@ function testSubclassMethodsNotBeingConvertedToError() {
function testSubclassMethodsNotBeingConvertedDebug0() {
Configure::write('debug', 0);
$exception = new MissingWidgetThingException('Widget not found');
$ErrorHandler = new MyCustomErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));

$this->assertEqual('missingWidgetThing', $ErrorHandler->method);

Expand All @@ -293,7 +289,7 @@ function testSubclassConvertingFrameworkErrors() {
Configure::write('debug', 0);

$exception = new MissingControllerException('PostsController');
$ErrorHandler = new MyCustomErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));

$this->assertEqual('error400', $ErrorHandler->method);

Expand Down Expand Up @@ -341,7 +337,7 @@ function testErrorMethodCoercion() {
function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
$exception = new MissingWidgetThingException('coding fail.');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);

ob_start();
Expand All @@ -360,7 +356,7 @@ function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
function testUnknownExceptionTypeWithNoCodeIsA500() {
$exception = new OutOfBoundsException('foul ball.');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);

ob_start();
Expand All @@ -387,7 +383,7 @@ function testerror400() {

$exception = new NotFoundException('Custom message');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);

ob_start();
Expand All @@ -409,15 +405,15 @@ function testerror400OnlyChangingCakeException() {
Configure::write('debug', 0);

$exception = new NotFoundException('Custom message');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));

ob_start();
$ErrorHandler->render();
$result = ob_get_clean();
$this->assertContains('Custom message', $result);

$exception = new MissingActionException(array('controller' => 'PostsController', 'action' => 'index'));
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));

ob_start();
$ErrorHandler->render();
Expand All @@ -436,7 +432,7 @@ function testError400NoInjection() {
Router::setRequestInfo($request);

$exception = new NotFoundException('Custom message');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));

ob_start();
$ErrorHandler->render();
Expand All @@ -455,7 +451,7 @@ function testError400NoInjection() {
function testError500Message() {
$exception = new InternalErrorException('An Internal Error Has Occurred');
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);

ob_start();
Expand All @@ -475,7 +471,7 @@ function testMissingController() {
$this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController');

$exception = new MissingControllerException(array('controller' => 'PostsController'));
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));

ob_start();
$ErrorHandler->render();
Expand Down Expand Up @@ -624,7 +620,7 @@ public static function testProvider() {
*/
function testCakeExceptionHandling($exception, $patterns, $code) {
$ErrorHandler = new ErrorHandler($exception);
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
$ErrorHandler->controller->response->expects($this->once())
->method('statusCode')
->with($code);
Expand Down

0 comments on commit 326ae97

Please sign in to comment.