Skip to content

Commit

Permalink
Remove un-necessary calls to constructClasses().
Browse files Browse the repository at this point in the history
Now that Controller::__constuct() calls constructClasses() it doesn't
need to be called all over the place.
  • Loading branch information
markstory committed Sep 14, 2014
1 parent 4c52ded commit a42d56a
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Controller/Controller.php
Expand Up @@ -303,7 +303,7 @@ public function components() {
* This method will also set the component to a property.
* For example:
*
* `$this->addComponent('DebugKit.Toolbar');`
* `$this->addComponent('Acl.Acl');`
*
* Will result in a `Toolbar` property being set.
*
Expand Down
1 change: 0 additions & 1 deletion src/Controller/ErrorController.php
Expand Up @@ -31,7 +31,6 @@ class ErrorController extends Controller {
*/
public function __construct($request = null, $response = null) {
parent::__construct($request, $response);
$this->constructClasses();
if (count(Router::extensions()) &&
!isset($this->RequestHandler)
) {
Expand Down
1 change: 0 additions & 1 deletion src/Shell/Task/TestTask.php
Expand Up @@ -363,7 +363,6 @@ protected function _processModel($subject) {
* @return void
*/
protected function _processController($subject) {
$subject->constructClasses();
$models = [$subject->modelClass];
foreach ($models as $model) {
list(, $model) = pluginSplit($model);
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Controller/Component/CookieComponentTest.php
Expand Up @@ -41,8 +41,7 @@ public function setUp() {
array('redirect'),
array(new Request(), new Response())
);
$controller->components = array('Cookie');
$controller->constructClasses();
$controller->addComponent('Cookie');
$this->Controller = $controller;
$this->Cookie = $controller->Cookie;
$this->request = $controller->request;
Expand Down
Expand Up @@ -68,7 +68,6 @@ protected function _init() {
$request = new Request('controller_posts/index');
$response = $this->getMock('Cake\Network\Response', array('_sendHeader', 'stop'));
$this->Controller = new RequestHandlerTestController($request, $response);
$this->Controller->constructClasses();
$this->RequestHandler = new RequestHandlerComponent($this->Controller->components());

Router::scope('/', function($routes) {
Expand Down
Expand Up @@ -141,7 +141,6 @@ public function setUp() {
->will($this->returnValue('/articles/index'));

$this->Controller = new SecurityTestController($request);
$this->Controller->constructClasses();
$this->Controller->Security = $this->Controller->TestSecurity;
$this->Controller->Security->config('blackHoleCallback', 'fail');
$this->Security = $this->Controller->Security;
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase/Controller/ComponentTest.php
Expand Up @@ -112,9 +112,7 @@ public function testMultipleComponentInitialize() {
*/
public function testSomethingReferencingCookieComponent() {
$Controller = new ComponentTestController();
$Controller->components = array('SomethingWithCookie');
$Controller->uses = false;
$Controller->constructClasses();
$Controller->addComponent('SomethingWithCookie');
$Controller->startupProcess();

$this->assertInstanceOf('TestApp\Controller\Component\SomethingWithCookieComponent', $Controller->SomethingWithCookie);
Expand Down
25 changes: 1 addition & 24 deletions tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -333,9 +333,8 @@ public function testConstructClassesWithComponents() {
Plugin::load('TestPlugin');

$Controller = new TestPluginController(new Request(), new Response());
$Controller->components[] = 'TestPlugin.Other';
$Controller->addComponent('TestPlugin.Other');

$Controller->constructClasses();
$this->assertInstanceOf('TestPlugin\Controller\Component\OtherComponent', $Controller->Other);
}

Expand Down Expand Up @@ -507,9 +506,7 @@ public function testRedirectBeforeRedirectListenerReturnFalse() {
*/
public function testMergeVars() {
$request = new Request();

$TestController = new TestController($request);
$TestController->constructClasses();

$expected = [
'Html' => null,
Expand All @@ -524,31 +521,13 @@ public function testMergeVars() {
$this->assertEquals($expected, $TestController->components);

$TestController = new AnotherTestController($request);
$TestController->constructClasses();

$this->assertEquals(
'Posts',
$TestController->modelClass,
'modelClass should not be overwritten when defined.'
);
}

/**
* test that options from child classes replace those in the parent classes.
*
* @return void
*/
public function testChildComponentOptionsSupercedeParents() {
$request = new Request('controller_posts/index');

$TestController = new TestController($request);

$expected = array('foo');
$TestController->components = array('Cookie' => $expected);
$TestController->constructClasses();
$this->assertEquals($expected, $TestController->components['Cookie']);
}

/**
* Ensure that _mergeControllerVars is not being greedy and merging with
* ControllerTestAppController when you make an instance of Controller
Expand Down Expand Up @@ -685,7 +664,6 @@ public function testPaginate() {

$Controller = new Controller($request, $response);
$Controller->request->query['url'] = [];
$Controller->constructClasses();
$this->assertEquals([], $Controller->paginate);

$this->assertNotContains('Paginator', $Controller->helpers);
Expand Down Expand Up @@ -716,7 +694,6 @@ public function testPaginateUsesModelClass() {

$Controller = new Controller($request, $response);
$Controller->request->query['url'] = [];
$Controller->constructClasses();
$Controller->modelClass = 'Posts';
$results = $Controller->paginate();

Expand Down
2 changes: 0 additions & 2 deletions tests/TestCase/Shell/Task/TestTaskTest.php
Expand Up @@ -389,7 +389,6 @@ public function testBakeControllerTest() {

$this->assertNotContains('function setUp()', $result);
$this->assertNotContains("\$this->Posts = new PostsController()", $result);
$this->assertNotContains("\$this->Posts->constructClasses()", $result);

$this->assertNotContains('function tearDown()', $result);
$this->assertNotContains('unset($this->Posts)', $result);
Expand Down Expand Up @@ -417,7 +416,6 @@ public function testBakePrefixControllerTest() {

$this->assertNotContains('function setUp()', $result);
$this->assertNotContains("\$this->Posts = new PostsController()", $result);
$this->assertNotContains("\$this->Posts->constructClasses()", $result);

$this->assertNotContains('function tearDown()', $result);
$this->assertNotContains('unset($this->Posts)', $result);
Expand Down
1 change: 0 additions & 1 deletion tests/TestCase/View/ViewTest.php
Expand Up @@ -1115,7 +1115,6 @@ public function testRender() {
$this->assertNull($View->render(false, 'ajax2'));

$this->PostsController->helpers = array('Session', 'Html');
$this->PostsController->constructClasses();
$this->PostsController->request->params['action'] = 'index';
Configure::write('Cache.check', true);

Expand Down

0 comments on commit a42d56a

Please sign in to comment.