mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making sure components in controller test cases always have a fresh reference to the request object, fixes #2705
This commit is contained in:
parent
83ceef045d
commit
16bde9c723
3 changed files with 20 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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'])) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue