Fix errors when testing controllers that use file()

Fix errors related to ob_end_clean() closing PHPUnit's output buffer
when testing controller methods that use response->file().
This commit is contained in:
mark_story 2015-04-09 20:38:37 -04:00
parent a6aefdd4d3
commit 5f2aa4c307
3 changed files with 17 additions and 1 deletions

View file

@ -300,6 +300,18 @@ class ControllerTestCaseTest extends CakeTestCase {
$this->assertSame(302, $Controller->response->statusCode());
}
/**
* Test that file responses don't trigger errors.
*
* @return void
*/
public function testActionWithFile() {
$Controller = $this->Case->generate('TestsApps');
$this->Case->testAction('/tests_apps/file');
$this->assertArrayHasKey('Content-Disposition', $Controller->response->header());
$this->assertArrayHasKey('Content-Length', $Controller->response->header());
}
/**
* Make sure testAction() can hit plugin controllers.
*

View file

@ -44,6 +44,10 @@ class TestsAppsController extends AppController {
$this->render('index');
}
public function file() {
$this->response->file(__FILE__);
}
public function redirect_to() {
return $this->redirect('http://cakephp.org');
}

View file

@ -271,7 +271,7 @@ abstract class ControllerTestCase extends CakeTestCase {
$params['requested'] = 1;
}
$Dispatch->testController = $this->controller;
$Dispatch->response = $this->getMock('CakeResponse', array('send'));
$Dispatch->response = $this->getMock('CakeResponse', array('send', '_clearBuffer'));
$this->result = $Dispatch->dispatch($request, $Dispatch->response, $params);
$this->controller = $Dispatch->testController;
$this->vars = $this->controller->viewVars;