Removing ability of plugin task to pass through to a few but not all parts of bake.

Adding OptionParser definition.
This commit is contained in:
mark_story 2010-10-17 23:09:30 -04:00
parent 1d974f5a48
commit 529527a722
2 changed files with 50 additions and 137 deletions

View file

@ -17,6 +17,7 @@
* @since CakePHP(tm) v 1.2
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'File');
/**
* Task class for creating a plugin
@ -55,12 +56,6 @@ class PluginTask extends Shell {
* @return void
*/
public function execute() {
if (empty($this->params['skel'])) {
$this->params['skel'] = '';
if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel') === true) {
$this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . CAKE . 'console' . DS . 'templates' . DS . 'skel';
}
}
$plugin = null;
if (isset($this->args[0])) {
@ -79,21 +74,6 @@ class PluginTask extends Shell {
} else {
return $this->_interactive();
}
if (isset($this->args[0])) {
$task = Inflector::classify($this->args[0]);
$this->Dispatch->shiftArgs();
if (in_array($task, $this->tasks)) {
$this->{$task}->plugin = $plugin;
$this->{$task}->path = $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
if (!is_dir($this->{$task}->path)) {
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s"), $task, $this->{$task}->path));
}
$this->{$task}->loadTasks();
return $this->{$task}->execute();
}
}
}
/**
@ -108,7 +88,7 @@ class PluginTask extends Shell {
}
if (!$this->bake($plugin)) {
$this->err(sprintf(__("An error occured trying to bake: %s in %s"), $plugin, $this->path . Inflector::underscore($pluginPath)));
$this->error(sprintf(__("An error occured trying to bake: %s in %s"), $plugin, $this->path . Inflector::underscore($pluginPath)));
}
}
@ -127,20 +107,19 @@ class PluginTask extends Shell {
$this->findPath($pathOptions);
}
$this->hr();
$this->out(sprintf(__("Plugin Name: %s"), $plugin));
$this->out(sprintf(__("Plugin Directory: %s"), $this->path . $pluginPath));
$this->out(sprintf(__("<info>Plugin Name:</info> %s"), $plugin));
$this->out(sprintf(__("<info>Plugin Directory:</info> %s"), $this->path . $pluginPath));
$this->hr();
$looksGood = $this->in(__('Look okay?'), array('y', 'n', 'q'), 'y');
if (strtolower($looksGood) == 'y') {
$verbose = $this->in(__('Do you want verbose output?'), array('y', 'n'), 'n');
$Folder =& new Folder($this->path . $pluginPath);
$directories = array(
'config' . DS . 'schema',
'models' . DS . 'behaviors',
'models' . DS . 'datasources',
'console' . DS . 'shells' . DS . 'tasks',
'controllers' . DS . 'components',
'libs',
'views' . DS . 'helpers',
@ -152,7 +131,6 @@ class PluginTask extends Shell {
'tests' . DS . 'groups',
'tests' . DS . 'fixtures',
'vendors',
'vendors' . DS . 'shells' . DS . 'tasks',
'webroot'
);
@ -162,10 +140,8 @@ class PluginTask extends Shell {
$File =& new File($dirPath . DS . 'empty', true);
}
if (strtolower($verbose) == 'y') {
foreach ($Folder->messages() as $message) {
$this->out($message);
}
foreach ($Folder->messages() as $message) {
$this->out($message, 1, Shell::VERBOSE);
}
$errors = $Folder->errors();
@ -190,8 +166,7 @@ class PluginTask extends Shell {
$this->createFile($this->path . $pluginPath . DS . $modelFileName, $out);
$this->hr();
$this->out(sprintf(__('Created: %s in %s'), $plugin, $this->path . $pluginPath));
$this->hr();
$this->out(sprintf(__('<success>Created:</success> %s in %s'), $plugin, $this->path . $pluginPath), 2);
}
return true;
@ -218,6 +193,21 @@ class PluginTask extends Shell {
$this->path = $pathOptions[$choice - 1];
}
/**
* get the option parser for the plugin task
*
* @return void
*/
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(
'Create the directory structure, AppModel and AppController classes for a new plugin. ' .
'Can create plugins in any of your bootstrapped plugin paths.'
)->addArgument('name', array(
'help' => __('CamelCased name of the plugin to create.')
));
}
/**
* Help
*

View file

@ -59,16 +59,6 @@ class PluginTaskTest extends CakeTestCase {
App::build(array('plugins' => $paths));
}
/**
* teardown
*
* @return void
*/
public function tearDown() {
parent::tearDown();
App::build(array('plugins' => $this->_paths));
}
/**
* test bake()
*
@ -81,81 +71,39 @@ class PluginTaskTest extends CakeTestCase {
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expects($this->at(3))->method('createFile')
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expects($this->at(4))->method('createFile')
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->bake('BakeTestPlugin');
$path = $this->Task->path . 'bake_test_plugin';
$this->assertTrue(is_dir($path), 'No plugin dir %s');
$this->assertTrue(is_dir($path . DS . 'config'), 'No config dir %s');
$this->assertTrue(is_dir($path . DS . 'config' . DS . 'schema'), 'No schema dir %s');
$this->assertTrue(file_exists($path . DS . 'config' . DS . 'schema' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'controllers'), 'No controllers dir %s');
$this->assertTrue(is_dir($path . DS . 'controllers' . DS .'components'), 'No components dir %s');
$this->assertTrue(file_exists($path . DS . 'controllers' . DS . 'components' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'models'), 'No models dir %s');
$this->assertTrue(file_exists($path . DS . 'models' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'models' . DS . 'datasources'), 'No datasources dir %s');
$this->assertTrue(file_exists($path . DS . 'models' . DS . 'datasources' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'views'), 'No views dir %s');
$this->assertTrue(is_dir($path . DS . 'views' . DS . 'helpers'), 'No helpers dir %s');
$this->assertTrue(file_exists($path . DS . 'views' . DS . 'helpers' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'tests'), 'No tests dir %s');
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases'), 'No cases dir %s');
$this->assertTrue(
is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'components'), 'No components cases dir %s'
$directories = array(
'config' . DS . 'schema',
'models' . DS . 'behaviors',
'models' . DS . 'datasources',
'console' . DS . 'shells' . DS . 'tasks',
'controllers' . DS . 'components',
'libs',
'views' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'components',
'tests' . DS . 'cases' . DS . 'helpers',
'tests' . DS . 'cases' . DS . 'behaviors',
'tests' . DS . 'cases' . DS . 'controllers',
'tests' . DS . 'cases' . DS . 'models',
'tests' . DS . 'groups',
'tests' . DS . 'fixtures',
'vendors',
'webroot'
);
$this->assertTrue(
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'components' . DS . 'empty'), 'No empty file %s'
);
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors'), 'No behaviors cases dir %s');
$this->assertTrue(
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'behaviors' . DS . 'empty'), 'No empty file %s'
);
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'helpers'), 'No helpers cases dir %s');
$this->assertTrue(
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'helpers' . DS . 'empty'), 'No empty file %s'
);
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'models'), 'No models cases dir %s');
$this->assertTrue(
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'models' . DS . 'empty'), 'No empty file %s'
);
$this->assertTrue(
is_dir($path . DS . 'tests' . DS . 'cases' . DS . 'controllers'),
'No controllers cases dir %s'
);
$this->assertTrue(
file_exists($path . DS . 'tests' . DS . 'cases' . DS . 'controllers' . DS . 'empty'), 'No empty file %s'
);
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'groups'), 'No groups dir %s');
$this->assertTrue(file_exists($path . DS . 'tests' . DS . 'groups' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'tests' . DS . 'fixtures'), 'No fixtures dir %s');
$this->assertTrue(file_exists($path . DS . 'tests' . DS . 'fixtures' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'vendors'), 'No vendors dir %s');
$this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells'), 'No vendors shells dir %s');
$this->assertTrue(is_dir($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks'), 'No vendors shells tasks dir %s');
$this->assertTrue(file_exists($path . DS . 'vendors' . DS . 'shells' . DS . 'tasks' . DS . 'empty'), 'No empty file %s');
$this->assertTrue(is_dir($path . DS . 'libs'), 'No libs dir %s');
$this->assertTrue(is_dir($path . DS . 'webroot'), 'No webroot dir %s');
foreach ($directories as $dir) {
$this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir);
}
$Folder = new Folder($this->Task->path . 'bake_test_plugin');
$Folder->delete();
@ -170,15 +118,14 @@ class PluginTaskTest extends CakeTestCase {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('TestPlugin'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('3'));
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('n'));
$path = $this->Task->path . 'test_plugin';
$file = $path . DS . 'test_plugin_app_controller.php';
$this->Task->expects($this->at(4))->method('createFile')
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$file = $path . DS . 'test_plugin_app_model.php';
$this->Task->expects($this->at(5))->method('createFile')
$this->Task->expects($this->at(4))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->args = array();
@ -201,12 +148,12 @@ class PluginTaskTest extends CakeTestCase {
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_controller.php';
$this->Task->expects($this->at(3))->method('createFile')
$this->Task->expects($this->at(2))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$path = $this->Task->path . 'bake_test_plugin';
$file = $path . DS . 'bake_test_plugin_app_model.php';
$this->Task->expects($this->at(4))->method('createFile')
$this->Task->expects($this->at(3))->method('createFile')
->with($file, new PHPUnit_Framework_Constraint_IsAnything());
$this->Task->Dispatch->args = array('BakeTestPlugin');
@ -218,28 +165,4 @@ class PluginTaskTest extends CakeTestCase {
$Folder->delete();
}
/**
* test execute chaining into MVC parts
*
* @return void
*/
public function testExecuteWithTwoArgs() {
$out = $this->getMock('ConsoleOutput', array(), array(), '', false);
$in = $this->getMock('ConsoleInput', array(), array(), '', false);
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->expects($this->once())->method('in')->will($this->returnValue($this->_testPath));
$this->Task->Model->expects($this->once())->method('loadTasks');
$this->Task->Model->expects($this->once())->method('execute');
$Folder = new Folder($this->Task->path . 'bake_test_plugin', true);
$this->Task->Dispatch->args = array('BakeTestPlugin', 'model');
$this->Task->args = $this->Task->Dispatch->args;
$this->Task->execute();
$Folder->delete();
}
}