Skip to content

Commit

Permalink
Make sure ComponentCollection has the controller dependency.
Browse files Browse the repository at this point in the history
Add setter method as changing ComponentCollection's constructor now is
not possible. This fixes issues where components that rely on
Collection->getController() in their constructor can work properly.

Fixes #3946
  • Loading branch information
markstory committed Jul 30, 2013
1 parent 4c7bc11 commit 95b74bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Cake/Controller/ComponentCollection.php
Expand Up @@ -54,6 +54,16 @@ public function init(Controller $Controller) {
}
}

/**
* Set the controller associated with the collection.
*
* @param Controller $Controller Controller to set
* @return void
*/
public function setController(Controller $Controller) {
$this->_Controller = $Controller;
}

/**
* Get the controller associated with the collection.
*
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/TestSuite/ControllerTestCase.php
Expand Up @@ -334,6 +334,7 @@ public function generate($controller, $mocks = array()) {
$request = $this->getMock('CakeRequest');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
$controllerObj->__construct($request, $response);
$controllerObj->Components->setController($controllerObj);

$config = ClassRegistry::config('Model');
foreach ($mocks['models'] as $model => $methods) {
Expand Down

0 comments on commit 95b74bd

Please sign in to comment.