Skip to content

Commit

Permalink
Moving code from BakeShell to BakeTask.
Browse files Browse the repository at this point in the history
Adding a base execute method to contain common code shared amongst all the bake tasks.
Updating test cases as $name attributes value has changed.
  • Loading branch information
markstory committed Oct 19, 2010
1 parent bd156bb commit 6900f47
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 15 deletions.
9 changes: 0 additions & 9 deletions cake/console/shells/bake.php
Expand Up @@ -50,15 +50,6 @@ public function startup() {
if (isset($this->params['connection'])) {
$this->{$task}->connection = $this->params['connection'];
}
foreach($this->args as $i => $arg) {
if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
break;
}
}
if (isset($this->params['plugin'])) {
$this->{$task}->plugin = $this->params['plugin'];
}
}
}

Expand Down
22 changes: 20 additions & 2 deletions cake/console/shells/tasks/bake.php
Expand Up @@ -51,9 +51,27 @@ class BakeTask extends Shell {
public function getPath() {
$path = $this->path;
if (isset($this->plugin)) {
$name = substr($this->name, 0, strlen($this->name) - 4);
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($name)) . DS;
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($this->name)) . DS;
}
return $path;
}

/**
* Base execute method parses some parameters and sets some properties on the bake tasks.
* call when overriding execute()
*
* @return void
*/
public function execute() {
foreach($this->args as $i => $arg) {
if (strpos($arg, '.')) {
list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
break;
}
}
if (isset($this->params['plugin'])) {
$this->plugin = $this->params['plugin'];
}
}

}
1 change: 1 addition & 0 deletions cake/console/shells/tasks/controller.php
Expand Up @@ -56,6 +56,7 @@ public function initialize() {
*
*/
public function execute() {
parent::execute();
if (empty($this->args)) {
return $this->_interactive();
}
Expand Down
1 change: 1 addition & 0 deletions cake/console/shells/tasks/fixture.php
Expand Up @@ -95,6 +95,7 @@ public function getOptionParser() {
* @return void
*/
public function execute() {
parent::execute();
if (empty($this->args)) {
$this->_interactive();
}
Expand Down
1 change: 1 addition & 0 deletions cake/console/shells/tasks/model.php
Expand Up @@ -74,6 +74,7 @@ class ModelTask extends BakeTask {
*/
public function execute() {
App::import('Model', 'Model', false);
parent::execute();

if (empty($this->args)) {
$this->_interactive();
Expand Down
1 change: 1 addition & 0 deletions cake/console/shells/tasks/test.php
Expand Up @@ -65,6 +65,7 @@ class TestTask extends BakeTask {
*
*/
public function execute() {
parent::execute();
if (empty($this->args)) {
$this->_interactive();
}
Expand Down
1 change: 1 addition & 0 deletions cake/console/shells/tasks/view.php
Expand Up @@ -97,6 +97,7 @@ public function initialize() {
*
*/
public function execute() {
parent::execute();
if (empty($this->args)) {
$this->_interactive();
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/shells/tasks/controller.test.php
Expand Up @@ -75,7 +75,7 @@ public function setUp() {
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->name = 'ControllerTask';
$this->Task->name = 'Controller';
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Template->params['theme'] = 'default';

Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/shells/tasks/model.test.php
Expand Up @@ -91,7 +91,7 @@ protected function _setupOtherMocks() {
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Template = new TemplateTask($this->Task->Dispatch, $out, $out, $in);

$this->Task->name = 'ModelTask';
$this->Task->name = 'Model';
$this->Task->interactive = true;
}

Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/shells/tasks/test.test.php
Expand Up @@ -250,7 +250,7 @@ public function setup() {
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->name = 'TestTask';
$this->Task->name = 'Test';
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
}

Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/shells/tasks/view.test.php
Expand Up @@ -394,7 +394,7 @@ public function testBakeWithPlugin() {
$this->Task->controllerName = 'ViewTaskComments';
$this->Task->controllerPath = 'view_task_comments';
$this->Task->plugin = 'TestTest';
$this->Task->name = 'ViewTask';
$this->Task->name = 'View';

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

0 comments on commit 6900f47

Please sign in to comment.