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.
This commit is contained in:
mark_story 2010-10-18 23:09:23 -04:00
parent bd156bb601
commit 6900f470ad
11 changed files with 29 additions and 15 deletions

View file

@ -50,15 +50,6 @@ class BakeShell extends Shell {
if (isset($this->params['connection'])) { if (isset($this->params['connection'])) {
$this->{$task}->connection = $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'];
}
} }
} }

View file

@ -51,9 +51,27 @@ class BakeTask extends Shell {
public function getPath() { public function getPath() {
$path = $this->path; $path = $this->path;
if (isset($this->plugin)) { if (isset($this->plugin)) {
$name = substr($this->name, 0, strlen($this->name) - 4); $path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($this->name)) . DS;
$path = $this->_pluginPath($this->plugin) . Inflector::pluralize(Inflector::underscore($name)) . DS;
} }
return $path; 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'];
}
}
} }

View file

@ -56,6 +56,7 @@ class ControllerTask extends BakeTask {
* *
*/ */
public function execute() { public function execute() {
parent::execute();
if (empty($this->args)) { if (empty($this->args)) {
return $this->_interactive(); return $this->_interactive();
} }

View file

@ -95,6 +95,7 @@ class FixtureTask extends BakeTask {
* @return void * @return void
*/ */
public function execute() { public function execute() {
parent::execute();
if (empty($this->args)) { if (empty($this->args)) {
$this->_interactive(); $this->_interactive();
} }

View file

@ -74,6 +74,7 @@ class ModelTask extends BakeTask {
*/ */
public function execute() { public function execute() {
App::import('Model', 'Model', false); App::import('Model', 'Model', false);
parent::execute();
if (empty($this->args)) { if (empty($this->args)) {
$this->_interactive(); $this->_interactive();

View file

@ -65,6 +65,7 @@ class TestTask extends BakeTask {
* *
*/ */
public function execute() { public function execute() {
parent::execute();
if (empty($this->args)) { if (empty($this->args)) {
$this->_interactive(); $this->_interactive();
} }

View file

@ -97,6 +97,7 @@ class ViewTask extends BakeTask {
* *
*/ */
public function execute() { public function execute() {
parent::execute();
if (empty($this->args)) { if (empty($this->args)) {
$this->_interactive(); $this->_interactive();
} }

View file

@ -75,7 +75,7 @@ class ControllerTaskTest extends CakeTestCase {
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'), array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
array(&$this->Dispatcher, $out, $out, $in) 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 = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Template->params['theme'] = 'default'; $this->Task->Template->params['theme'] = 'default';

View file

@ -91,7 +91,7 @@ class ModelTaskTest extends CakeTestCase {
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher, $out, $out, $in)); $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->Template = new TemplateTask($this->Task->Dispatch, $out, $out, $in);
$this->Task->name = 'ModelTask'; $this->Task->name = 'Model';
$this->Task->interactive = true; $this->Task->interactive = true;
} }

View file

@ -250,7 +250,7 @@ class TestTaskTest extends CakeTestCase {
array('in', 'err', 'createFile', '_stop', 'isLoadableClass'), array('in', 'err', 'createFile', '_stop', 'isLoadableClass'),
array(&$this->Dispatcher, $out, $out, $in) array(&$this->Dispatcher, $out, $out, $in)
); );
$this->Task->name = 'TestTask'; $this->Task->name = 'Test';
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in); $this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
} }

View file

@ -394,7 +394,7 @@ class ViewTaskTest extends CakeTestCase {
$this->Task->controllerName = 'ViewTaskComments'; $this->Task->controllerName = 'ViewTaskComments';
$this->Task->controllerPath = 'view_task_comments'; $this->Task->controllerPath = 'view_task_comments';
$this->Task->plugin = 'TestTest'; $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'; $path = APP . 'plugins' . DS . 'test_test' . DS . 'views' . DS . 'view_task_comments' . DS . 'view.ctp';
$this->Task->expects($this->once())->method('createFile') $this->Task->expects($this->once())->method('createFile')