Skip to content

Commit 326ae97

Browse files
committed
Updating debugger and error_handler tests to remove errors in CLI.
1 parent 98d1272 commit 326ae97

File tree

2 files changed

+27
-37
lines changed

2 files changed

+27
-37
lines changed

cake/tests/cases/libs/debugger.test.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,9 @@ function testExportVar() {
218218
$result = Debugger::exportVar($View);
219219
$expected = 'View
220220
View::$Helpers = HelperCollection object
221-
View::$base = NULL
222-
View::$here = NULL
223221
View::$plugin = NULL
224222
View::$name = ""
225-
View::$action = NULL
226-
View::$params = array
227223
View::$passedArgs = array
228-
View::$data = array
229224
View::$helpers = array
230225
View::$viewPath = ""
231226
View::$viewVars = array
@@ -247,7 +242,6 @@ function testExportVar() {
247242
View::$modelId = NULL
248243
View::$uuids = array
249244
View::$output = false
250-
View::$webroot = NULL
251245
View::$request = NULL';
252246
$result = str_replace(array("\t", "\r\n", "\n"), "", strtolower($result));
253247
$expected = str_replace(array("\t", "\r\n", "\n"), "", strtolower($expected));

cake/tests/cases/libs/error_handler.test.php

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AuthBlueberryUser extends CakeTestModel {
4444
*/
4545
public $useTable = false;
4646
}
47+
4748
if (!class_exists('AppController')) {
4849
/**
4950
* AppController class
@@ -68,24 +69,6 @@ class AppController extends Controller {
6869
function beforeRender() {
6970
echo $this->Blueberry->testName;
7071
}
71-
/**
72-
* header method
73-
*
74-
* @access public
75-
* @return void
76-
*/
77-
function header($header) {
78-
echo $header;
79-
}
80-
/**
81-
* _stop method
82-
*
83-
* @access public
84-
* @return void
85-
*/
86-
function _stop($status = 0) {
87-
echo 'Stopped with status: ' . $status;
88-
}
8972
}
9073
} elseif (!defined('APP_CONTROLLER_EXISTS')){
9174
define('APP_CONTROLLER_EXISTS', true);
@@ -228,7 +211,17 @@ function setUp() {
228211

229212
function teardown() {
230213
Configure::write('debug', $this->_debug);
231-
}
214+
}
215+
216+
/**
217+
* Mocks out the response on the errorhandler object so headers aren't modified.
218+
*
219+
* @return void
220+
*/
221+
protected function _mockResponse($error) {
222+
$error->controller->response = $this->getMock('CakeResponse', array('_sendHeader'));
223+
return $error;
224+
}
232225

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

258254
$exception = new MissingWidgetThingException('Widget not found');
259-
$ErrorHandler = new MyCustomErrorHandler($exception);
255+
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));
260256

261257
ob_start();
262258
$ErrorHandler->render();
@@ -273,7 +269,7 @@ function testSubclassMethodsNotBeingConvertedToError() {
273269
function testSubclassMethodsNotBeingConvertedDebug0() {
274270
Configure::write('debug', 0);
275271
$exception = new MissingWidgetThingException('Widget not found');
276-
$ErrorHandler = new MyCustomErrorHandler($exception);
272+
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));
277273

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

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

295291
$exception = new MissingControllerException('PostsController');
296-
$ErrorHandler = new MyCustomErrorHandler($exception);
292+
$ErrorHandler = $this->_mockResponse(new MyCustomErrorHandler($exception));
297293

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

@@ -341,7 +337,7 @@ function testErrorMethodCoercion() {
341337
function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
342338
$exception = new MissingWidgetThingException('coding fail.');
343339
$ErrorHandler = new ErrorHandler($exception);
344-
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
340+
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
345341
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(404);
346342

347343
ob_start();
@@ -360,7 +356,7 @@ function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
360356
function testUnknownExceptionTypeWithNoCodeIsA500() {
361357
$exception = new OutOfBoundsException('foul ball.');
362358
$ErrorHandler = new ErrorHandler($exception);
363-
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
359+
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
364360
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
365361

366362
ob_start();
@@ -387,7 +383,7 @@ function testerror400() {
387383

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

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

411407
$exception = new NotFoundException('Custom message');
412-
$ErrorHandler = new ErrorHandler($exception);
408+
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));
413409

414410
ob_start();
415411
$ErrorHandler->render();
416412
$result = ob_get_clean();
417413
$this->assertContains('Custom message', $result);
418414

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

422418
ob_start();
423419
$ErrorHandler->render();
@@ -436,7 +432,7 @@ function testError400NoInjection() {
436432
Router::setRequestInfo($request);
437433

438434
$exception = new NotFoundException('Custom message');
439-
$ErrorHandler = new ErrorHandler($exception);
435+
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));
440436

441437
ob_start();
442438
$ErrorHandler->render();
@@ -455,7 +451,7 @@ function testError400NoInjection() {
455451
function testError500Message() {
456452
$exception = new InternalErrorException('An Internal Error Has Occurred');
457453
$ErrorHandler = new ErrorHandler($exception);
458-
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
454+
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
459455
$ErrorHandler->controller->response->expects($this->once())->method('statusCode')->with(500);
460456

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

477473
$exception = new MissingControllerException(array('controller' => 'PostsController'));
478-
$ErrorHandler = new ErrorHandler($exception);
474+
$ErrorHandler = $this->_mockResponse(new ErrorHandler($exception));
479475

480476
ob_start();
481477
$ErrorHandler->render();
@@ -624,7 +620,7 @@ public static function testProvider() {
624620
*/
625621
function testCakeExceptionHandling($exception, $patterns, $code) {
626622
$ErrorHandler = new ErrorHandler($exception);
627-
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode'));
623+
$ErrorHandler->controller->response = $this->getMock('CakeResponse', array('statusCode', '_sendHeader'));
628624
$ErrorHandler->controller->response->expects($this->once())
629625
->method('statusCode')
630626
->with($code);

0 commit comments

Comments
 (0)