@@ -44,6 +44,7 @@ class AuthBlueberryUser extends CakeTestModel {
44
44
*/
45
45
public $ useTable = false ;
46
46
}
47
+
47
48
if (!class_exists ('AppController ' )) {
48
49
/**
49
50
* AppController class
@@ -68,24 +69,6 @@ class AppController extends Controller {
68
69
function beforeRender () {
69
70
echo $ this ->Blueberry ->testName ;
70
71
}
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
- }
89
72
}
90
73
} elseif (!defined ('APP_CONTROLLER_EXISTS ' )){
91
74
define ('APP_CONTROLLER_EXISTS ' , true );
@@ -228,7 +211,17 @@ function setUp() {
228
211
229
212
function teardown () {
230
213
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
+ }
232
225
233
226
/**
234
227
* test handleException generating a page.
@@ -239,6 +232,9 @@ function testHandleException() {
239
232
if ($ this ->skipIf (file_exists (APP . 'app_error.php ' ), 'App error exists cannot run. ' )) {
240
233
return ;
241
234
}
235
+ if ($ this ->skipIf (PHP_SAPI == 'cli ' , 'This integration test can not be run in cli. ' )) {
236
+ return ;
237
+ }
242
238
$ error = new NotFoundException ('Kaboom! ' );
243
239
ob_start ();
244
240
ErrorHandler::handleException ($ error );
@@ -256,7 +252,7 @@ function testSubclassMethodsNotBeingConvertedToError() {
256
252
Configure::write ('debug ' , 2 );
257
253
258
254
$ exception = new MissingWidgetThingException ('Widget not found ' );
259
- $ ErrorHandler = new MyCustomErrorHandler ($ exception );
255
+ $ ErrorHandler = $ this -> _mockResponse ( new MyCustomErrorHandler ($ exception) );
260
256
261
257
ob_start ();
262
258
$ ErrorHandler ->render ();
@@ -273,7 +269,7 @@ function testSubclassMethodsNotBeingConvertedToError() {
273
269
function testSubclassMethodsNotBeingConvertedDebug0 () {
274
270
Configure::write ('debug ' , 0 );
275
271
$ exception = new MissingWidgetThingException ('Widget not found ' );
276
- $ ErrorHandler = new MyCustomErrorHandler ($ exception );
272
+ $ ErrorHandler = $ this -> _mockResponse ( new MyCustomErrorHandler ($ exception) );
277
273
278
274
$ this ->assertEqual ('missingWidgetThing ' , $ ErrorHandler ->method );
279
275
@@ -293,7 +289,7 @@ function testSubclassConvertingFrameworkErrors() {
293
289
Configure::write ('debug ' , 0 );
294
290
295
291
$ exception = new MissingControllerException ('PostsController ' );
296
- $ ErrorHandler = new MyCustomErrorHandler ($ exception );
292
+ $ ErrorHandler = $ this -> _mockResponse ( new MyCustomErrorHandler ($ exception) );
297
293
298
294
$ this ->assertEqual ('error400 ' , $ ErrorHandler ->method );
299
295
@@ -341,7 +337,7 @@ function testErrorMethodCoercion() {
341
337
function testUnknownExceptionTypeWithExceptionThatHasA400Code () {
342
338
$ exception = new MissingWidgetThingException ('coding fail. ' );
343
339
$ ErrorHandler = new ErrorHandler ($ exception );
344
- $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' ));
340
+ $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' , ' _sendHeader ' ));
345
341
$ ErrorHandler ->controller ->response ->expects ($ this ->once ())->method ('statusCode ' )->with (404 );
346
342
347
343
ob_start ();
@@ -360,7 +356,7 @@ function testUnknownExceptionTypeWithExceptionThatHasA400Code() {
360
356
function testUnknownExceptionTypeWithNoCodeIsA500 () {
361
357
$ exception = new OutOfBoundsException ('foul ball. ' );
362
358
$ ErrorHandler = new ErrorHandler ($ exception );
363
- $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' ));
359
+ $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' , ' _sendHeader ' ));
364
360
$ ErrorHandler ->controller ->response ->expects ($ this ->once ())->method ('statusCode ' )->with (500 );
365
361
366
362
ob_start ();
@@ -387,7 +383,7 @@ function testerror400() {
387
383
388
384
$ exception = new NotFoundException ('Custom message ' );
389
385
$ ErrorHandler = new ErrorHandler ($ exception );
390
- $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' ));
386
+ $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' , ' _sendHeader ' ));
391
387
$ ErrorHandler ->controller ->response ->expects ($ this ->once ())->method ('statusCode ' )->with (404 );
392
388
393
389
ob_start ();
@@ -409,15 +405,15 @@ function testerror400OnlyChangingCakeException() {
409
405
Configure::write ('debug ' , 0 );
410
406
411
407
$ exception = new NotFoundException ('Custom message ' );
412
- $ ErrorHandler = new ErrorHandler ($ exception );
408
+ $ ErrorHandler = $ this -> _mockResponse ( new ErrorHandler ($ exception) );
413
409
414
410
ob_start ();
415
411
$ ErrorHandler ->render ();
416
412
$ result = ob_get_clean ();
417
413
$ this ->assertContains ('Custom message ' , $ result );
418
414
419
415
$ exception = new MissingActionException (array ('controller ' => 'PostsController ' , 'action ' => 'index ' ));
420
- $ ErrorHandler = new ErrorHandler ($ exception );
416
+ $ ErrorHandler = $ this -> _mockResponse ( new ErrorHandler ($ exception) );
421
417
422
418
ob_start ();
423
419
$ ErrorHandler ->render ();
@@ -436,7 +432,7 @@ function testError400NoInjection() {
436
432
Router::setRequestInfo ($ request );
437
433
438
434
$ exception = new NotFoundException ('Custom message ' );
439
- $ ErrorHandler = new ErrorHandler ($ exception );
435
+ $ ErrorHandler = $ this -> _mockResponse ( new ErrorHandler ($ exception) );
440
436
441
437
ob_start ();
442
438
$ ErrorHandler ->render ();
@@ -455,7 +451,7 @@ function testError400NoInjection() {
455
451
function testError500Message () {
456
452
$ exception = new InternalErrorException ('An Internal Error Has Occurred ' );
457
453
$ ErrorHandler = new ErrorHandler ($ exception );
458
- $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' ));
454
+ $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' , ' _sendHeader ' ));
459
455
$ ErrorHandler ->controller ->response ->expects ($ this ->once ())->method ('statusCode ' )->with (500 );
460
456
461
457
ob_start ();
@@ -475,7 +471,7 @@ function testMissingController() {
475
471
$ this ->skipIf (defined ('APP_CONTROLLER_EXISTS ' ), '%s Need a non-existent AppController ' );
476
472
477
473
$ exception = new MissingControllerException (array ('controller ' => 'PostsController ' ));
478
- $ ErrorHandler = new ErrorHandler ($ exception );
474
+ $ ErrorHandler = $ this -> _mockResponse ( new ErrorHandler ($ exception) );
479
475
480
476
ob_start ();
481
477
$ ErrorHandler ->render ();
@@ -624,7 +620,7 @@ public static function testProvider() {
624
620
*/
625
621
function testCakeExceptionHandling ($ exception , $ patterns , $ code ) {
626
622
$ ErrorHandler = new ErrorHandler ($ exception );
627
- $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' ));
623
+ $ ErrorHandler ->controller ->response = $ this ->getMock ('CakeResponse ' , array ('statusCode ' , ' _sendHeader ' ));
628
624
$ ErrorHandler ->controller ->response ->expects ($ this ->once ())
629
625
->method ('statusCode ' )
630
626
->with ($ code );
0 commit comments