Skip to content

Commit 6900f47

Browse files
committed
Moving code from BakeShell to BakeTask.
Adding a base execute method to contain common code shared amongst all the bake tasks. Updating test cases as $name attributes value has changed.
1 parent bd156bb commit 6900f47

File tree

11 files changed

+29
-15
lines changed

11 files changed

+29
-15
lines changed

cake/console/shells/bake.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ public function startup() {
5050
if (isset($this->params['connection'])) {
5151
$this->{$task}->connection = $this->params['connection'];
5252
}
53-
foreach($this->args as $i => $arg) {
54-
if (strpos($arg, '.')) {
55-
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
56-
break;
57-
}
58-
}
59-
if (isset($this->params['plugin'])) {
60-
$this->{$task}->plugin = $this->params['plugin'];
61-
}
6253
}
6354
}
6455

cake/console/shells/tasks/bake.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,27 @@ class BakeTask extends Shell {
5151
public function getPath() {
5252
$path = $this->path;
5353
if (isset($this->plugin)) {
54-
$name = substr($this->name, 0, strlen($this->name) - 4);
55-
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($name)) . DS;
54+
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($this->name)) . DS;
5655
}
5756
return $path;
5857
}
58+
59+
/**
60+
* Base execute method parses some parameters and sets some properties on the bake tasks.
61+
* call when overriding execute()
62+
*
63+
* @return void
64+
*/
65+
public function execute() {
66+
foreach($this->args as $i => $arg) {
67+
if (strpos($arg, '.')) {
68+
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
69+
break;
70+
}
71+
}
72+
if (isset($this->params['plugin'])) {
73+
$this->plugin = $this->params['plugin'];
74+
}
75+
}
76+
5977
}

cake/console/shells/tasks/controller.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function initialize() {
5656
*
5757
*/
5858
public function execute() {
59+
parent::execute();
5960
if (empty($this->args)) {
6061
return $this->_interactive();
6162
}

cake/console/shells/tasks/fixture.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function getOptionParser() {
9595
* @return void
9696
*/
9797
public function execute() {
98+
parent::execute();
9899
if (empty($this->args)) {
99100
$this->_interactive();
100101
}

cake/console/shells/tasks/model.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class ModelTask extends BakeTask {
7474
*/
7575
public function execute() {
7676
App::import('Model', 'Model', false);
77+
parent::execute();
7778

7879
if (empty($this->args)) {
7980
$this->_interactive();

cake/console/shells/tasks/test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TestTask extends BakeTask {
6565
*
6666
*/
6767
public function execute() {
68+
parent::execute();
6869
if (empty($this->args)) {
6970
$this->_interactive();
7071
}

cake/console/shells/tasks/view.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function initialize() {
9797
*
9898
*/
9999
public function execute() {
100+
parent::execute();
100101
if (empty($this->args)) {
101102
$this->_interactive();
102103
}

cake/tests/cases/console/shells/tasks/controller.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function setUp() {
7575
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
7676
array(&$this->Dispatcher, $out, $out, $in)
7777
);
78-
$this->Task->name = 'ControllerTask';
78+
$this->Task->name = 'Controller';
7979
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
8080
$this->Task->Template->params['theme'] = 'default';
8181

cake/tests/cases/console/shells/tasks/model.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected function _setupOtherMocks() {
9191
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher, $out, $out, $in));
9292
$this->Task->Template = new TemplateTask($this->Task->Dispatch, $out, $out, $in);
9393

94-
$this->Task->name = 'ModelTask';
94+
$this->Task->name = 'Model';
9595
$this->Task->interactive = true;
9696
}
9797

cake/tests/cases/console/shells/tasks/test.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public function setup() {
250250
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
251251
array(&$this->Dispatcher, $out, $out, $in)
252252
);
253-
$this->Task->name = 'TestTask';
253+
$this->Task->name = 'Test';
254254
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
255255
}
256256

cake/tests/cases/console/shells/tasks/view.test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public function testBakeWithPlugin() {
394394
$this->Task->controllerName = 'ViewTaskComments';
395395
$this->Task->controllerPath = 'view_task_comments';
396396
$this->Task->plugin = 'TestTest';
397-
$this->Task->name = 'ViewTask';
397+
$this->Task->name = 'View';
398398

399399
$path = APP . 'plugins' . DS . 'test_test' . DS . 'views' . DS . 'view_task_comments' . DS . 'view.ctp';
400400
$this->Task->expects($this->once())->method('createFile')

0 commit comments

Comments
 (0)