Making sure components in controller test cases always have a fresh reference to the request object, fixes #2705

This commit is contained in:
Jose Lorenzo Rodriguez 2012-03-24 14:34:29 -04:30
parent 83ceef045d
commit 16bde9c723
3 changed files with 20 additions and 3 deletions

View file

@ -527,4 +527,19 @@ class ControllerTestCaseTest extends CakeTestCase {
$this->Case->testAction('/tests_apps/redirect_to', $options);
}
/**
* Tests that Components storing response or request objects internally during construct
* will always have a fresh reference to those object available
*
* @return void
* @see http://cakephp.lighthouseapp.com/projects/42648-cakephp/tickets/2705-requesthandler-weird-behavior
*/
public function testComponentsSameRequestAndResponse() {
$this->Case->generate('TestsApps');
$options = array('method' => 'get');
$this->Case->testAction('/tests_apps/index', $options);
$this->assertSame($this->Case->controller->response, $this->Case->controller->RequestHandler->response);
$this->assertSame($this->Case->controller->request, $this->Case->controller->RequestHandler->request);
}
}

View file

@ -22,6 +22,8 @@ class TestsAppsController extends AppController {
public $uses = array();
public $components = array('RequestHandler');
public function index() {
$var = '';
if (isset($this->request->query['var'])) {

View file

@ -62,10 +62,10 @@ class ControllerTestDispatcher extends Dispatcher {
if (isset($object->response)) {
$object->response = $response;
}
}
if (isset($object->request)) {
$object->request = $request;
}
}
return $this->testController;
}