Skip to content

Commit

Permalink
Updating fixture task to use the OptionParser
Browse files Browse the repository at this point in the history
Fixing failing tests caused by changing tasks to lazy loading.
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 1009069 commit 52c1c71
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
56 changes: 29 additions & 27 deletions cake/console/libs/tasks/fixture.php
Expand Up @@ -59,6 +59,35 @@ public function __construct(&$dispatch, $stdout = null, $stderr = null, $stdin =
$this->path = $this->Dispatch->params['working'] . DS . 'tests' . DS . 'fixtures' . DS;
}

/**
* get the option parser.
*
* @return void
*/
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(
__('Generate fixtures for use with the test suite. You can use `bake fixture all` to bake all fixtures.')
)->addArgument('name', array(
'help' => __('Name of the fixture to bake. Can use Plugin.name to bake plugin fixtures.')
))->addOption('count', array(
'help' => __('When using generated data, the number of records to include in the fixture(s).'),
'short' => 'n',
'default' => 10
))->addOption('connection', array(
'help' => __('Which database configuration to use for baking.'),
'short' => 'c',
'default' => 'default'
))->addOption('plugin', array(
'help' => __('CamelCased name of the plugin to bake fixtures for.'),
'short' => 'p',
))->addOption('records', array(
'help' => 'Used with --count and <name>/all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10',
'short' => 'r',
'boolean' => true
));
}

/**
* Execution method always used for tasks
* Handles dispatching to interactive, named, or all processess.
Expand Down Expand Up @@ -382,31 +411,4 @@ protected function _getRecordsFromTable($modelName, $useTable = null) {
return $out;
}

/**
* Displays help contents
*
*/
public function help() {
$this->hr();
$this->out("Usage: cake bake fixture <arg1> <params>");
$this->hr();
$this->out('Arguments:');
$this->out();
$this->out("<name>");
$this->out("\tName of the fixture to bake. Can use Plugin.name");
$this->out("\tas a shortcut for plugin baking.");
$this->out();
$this->out('Commands:');
$this->out("\nfixture <name>\n\tbakes fixture with specified name.");
$this->out("\nfixture all\n\tbakes all fixtures.");
$this->out();
$this->out('Parameters:');
$this->out("\t-count When using generated data, the number of records to include in the fixture(s).");
$this->out("\t-connection Which database configuration to use for baking.");
$this->out("\t-plugin CamelCased name of plugin to bake fixtures for.");
$this->out("\t-records Used with -count and <name>/all commands to pull [n] records from the live tables");
$this->out("\t Where [n] is either -count or the default of 10.");
$this->out();
$this->_stop();
}
}
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -76,7 +76,7 @@ public function setUp() {
);
$this->Task->name = 'ControllerTask';
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Template->params['theme'] = 'default';

$this->Task->Model = $this->getMock('ModelTask',
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -59,6 +59,7 @@ public function setUp() {
array(&$this->Dispatcher, $out, $out, $in)
);
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template->initialize();
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -87,7 +87,7 @@ protected function _setupOtherMocks() {

$this->Task->Fixture = $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->interactive = true;
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/plugin.test.php
Expand Up @@ -226,7 +226,7 @@ public function testExecuteWithTwoArgs() {

$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher, $out, $out, $in));

$this->Task->expects($this->at(0))->method('in')->will($this->returnValue($this->_testPath));
$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');
Expand Down
1 change: 1 addition & 0 deletions cake/tests/cases/console/libs/tasks/view.test.php
Expand Up @@ -233,6 +233,7 @@ public function setUp() {
$this->Task->Template = new TemplateTask($this->Dispatcher, $out, $out, $in);
$this->Task->Controller = $this->getMock('ControllerTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher, $out, $out, $in));
$this->Task->DbConfig = $this->getMock('DbConfigTask', array(), array(&$this->Dispatcher, $out, $out, $in));

$this->Dispatcher->shellPaths = App::path('shells');
$this->Task->path = TMP;
Expand Down

0 comments on commit 52c1c71

Please sign in to comment.