Skip to content

Commit

Permalink
Update bake for task subcommand changes.
Browse files Browse the repository at this point in the history
Subcommands can now be nested when using tasks. This means we can drop
some gross code around method delegation in various bake tasks.

Clean up remaining tests for execute() -> main() changes as well.
  • Loading branch information
markstory committed Apr 24, 2014
1 parent 2b40223 commit c2008e7
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 105 deletions.
3 changes: 1 addition & 2 deletions src/Console/Command/BakeShell.php
Expand Up @@ -194,7 +194,6 @@ public function all($name = null) {
$this->out('Bake All');
$this->hr();

$this->connection = 'default';
if (!empty($this->params['connection'])) {
$this->connection = $this->params['connection'];
}
Expand All @@ -218,7 +217,7 @@ public function all($name = null) {
$this->Model->bake($name);
$this->Controller->bake($name);

$this->View->execute($name);
$this->View->main($name);

$this->out(__d('cake_console', '<success>Bake All complete</success>'), 1, Shell::QUIET);
return true;
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/Task/BakeTask.php
Expand Up @@ -113,6 +113,7 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Force overwriting existing files without prompting.')
])->addOption('connection', [
'short' => 'c',
'default' => 'default',
'help' => __d('cake_console', 'The datasource connection to get data from.')
])->addOption('theme', [
'short' => 't',
Expand Down
8 changes: 0 additions & 8 deletions src/Console/Command/Task/ControllerTask.php
Expand Up @@ -47,10 +47,6 @@ class ControllerTask extends BakeTask {
public function main($name = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
}

if (empty($name)) {
$this->out(__d('cake_console', 'Possible controllers based on your current database:'));
foreach ($this->listAll() as $table) {
Expand All @@ -59,10 +55,6 @@ public function main($name = null) {
return true;
}

if (strtolower($name) === 'all') {
return $this->all();
}

$controller = $this->_controllerName($name);
$this->bake($controller);
}
Expand Down
6 changes: 0 additions & 6 deletions src/Console/Command/Task/FixtureTask.php
Expand Up @@ -92,9 +92,6 @@ public function getOptionParser() {
*/
public function main($name = null) {
parent::main();
if (!isset($this->connection)) {
$this->connection = 'default';
}

if (empty($name)) {
$this->out(__d('cake_console', 'Choose a fixture to bake from the following:'));
Expand All @@ -104,9 +101,6 @@ public function main($name = null) {
return true;
}

if (strtolower($name) === 'all') {
return $this->all();
}
$table = null;
if (isset($this->params['table'])) {
$table = $this->params['table'];
Expand Down
8 changes: 0 additions & 8 deletions src/Console/Command/Task/ModelTask.php
Expand Up @@ -78,10 +78,6 @@ class ModelTask extends BakeTask {
public function main($name = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
}

if (empty($name)) {
$this->out(__d('cake_console', 'Choose a model to bake from the following:'));
foreach ($this->listAll() as $table) {
Expand All @@ -90,10 +86,6 @@ public function main($name = null) {
return true;
}

if (strtolower($name) === 'all') {
return $this->all();
}

$this->bake($this->_modelName($name));
}

Expand Down
10 changes: 1 addition & 9 deletions src/Console/Command/Task/ViewTask.php
Expand Up @@ -101,10 +101,6 @@ public function initialize() {
public function main($name = null, $template = null, $action = null) {
parent::main();

if (!isset($this->connection)) {
$this->connection = 'default';
}

if (empty($name)) {
$this->out(__d('cake_console', 'Possible tables to bake views for based on your current database:'));
$this->Model->connection = $this->connection;
Expand All @@ -114,10 +110,6 @@ public function main($name = null, $template = null, $action = null) {
return true;
}

if (strtolower($name) === 'all') {
return $this->all();
}

$controller = null;
if (!empty($this->params['controller'])) {
$controller = $this->params['controller'];
Expand Down Expand Up @@ -219,7 +211,7 @@ public function all() {
$tables = $this->Model->listAll();

foreach ($tables as $table) {
$this->execute($table);
$this->main($table);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Console/Command/BakeShellTest.php
Expand Up @@ -78,7 +78,7 @@ public function testAllWithModelName() {
->will($this->returnValue(true));

$this->Shell->View->expects($this->once())
->method('execute')
->method('main')
->with('Comments');

$this->Shell->expects($this->at(0))
Expand Down
14 changes: 7 additions & 7 deletions tests/TestCase/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -280,23 +280,23 @@ public function testBakeTestDisabled() {
*
* @return void
*/
public function testExecuteNoArgs() {
public function testMainNoArgs() {
$this->Task->expects($this->never())
->method('createFile');

$this->Task->expects($this->at(0))
->method('out')
->with($this->stringContains('Possible controllers based on your current database'));

$this->Task->execute();
$this->Task->main();
}

/**
* test that execute runs all when the first arg == all
*
* @return void
*/
public function testExecuteIntoAll() {
public function testMainIntoAll() {
$count = count($this->Task->listAll());
if ($count != count($this->fixtures)) {
$this->markTestSkipped('Additional tables detected.');
Expand All @@ -316,11 +316,11 @@ public function testExecuteIntoAll() {
))
->will($this->returnValue(true));

$this->Task->execute('all');
$this->Task->all();
}

/**
* data provider for testExecuteWithControllerNameVariations
* data provider for testMainWithControllerNameVariations
*
* @return void
*/
Expand All @@ -336,14 +336,14 @@ public static function nameVariations() {
* @dataProvider nameVariations
* @return void
*/
public function testExecuteWithControllerNameVariations($name) {
public function testMainWithControllerNameVariations($name) {
$this->Task->connection = 'test';

$filename = $this->_normalizePath(APP . 'Controller/BakeArticlesController.php');
$this->Task->expects($this->once())
->method('createFile')
->with($filename, $this->stringContains('public function index()'));
$this->Task->execute($name);
$this->Task->main($name);
}

}
16 changes: 8 additions & 8 deletions tests/TestCase/Console/Command/Task/ExtractTaskTest.php
Expand Up @@ -75,7 +75,7 @@ public function testExecute() {
->will($this->returnValue('y'));
$this->Task->expects($this->never())->method('_stop');

$this->Task->execute();
$this->Task->main();
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');

Expand Down Expand Up @@ -135,7 +135,7 @@ public function testExtractCategory() {
->will($this->returnValue('y'));
$this->Task->expects($this->never())->method('_stop');

$this->Task->execute();
$this->Task->main();
$this->assertTrue(file_exists($this->path . DS . 'LC_TIME' . DS . 'default.pot'));

$result = file_get_contents($this->path . DS . 'default.pot');
Expand All @@ -159,7 +159,7 @@ public function testExtractWithExclude() {
$this->Task->expects($this->any())->method('in')
->will($this->returnValue('y'));

$this->Task->execute();
$this->Task->main();
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$result = file_get_contents($this->path . DS . 'default.pot');

Expand All @@ -186,7 +186,7 @@ public function testExtractMultiplePaths() {
$this->Task->params['extract-core'] = 'no';
$this->Task->expects($this->never())->method('err');
$this->Task->expects($this->never())->method('_stop');
$this->Task->execute();
$this->Task->main();

$result = file_get_contents($this->path . DS . 'default.pot');

Expand All @@ -213,7 +213,7 @@ public function testExtractExcludePlugins() {
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['exclude-plugins'] = true;

$this->Task->execute();
$this->Task->main();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotRegExp('#TestPlugin#', $result);
}
Expand All @@ -234,7 +234,7 @@ public function testExtractPlugin() {
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['plugin'] = 'TestPlugin';

$this->Task->execute();
$this->Task->main();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotRegExp('#Pages#', $result);
$this->assertRegExp('/translate\.ctp:\d+/', $result);
Expand All @@ -259,7 +259,7 @@ public function testExtractOverwrite() {
$this->assertTrue(file_exists($this->path . DS . 'default.pot'));
$original = file_get_contents($this->path . DS . 'default.pot');

$this->Task->execute();
$this->Task->main();
$result = file_get_contents($this->path . DS . 'default.pot');
$this->assertNotEquals($original, $result);
}
Expand All @@ -277,7 +277,7 @@ public function testExtractCore() {
$this->Task->params['output'] = $this->path . DS;
$this->Task->params['extract-core'] = 'yes';

$this->Task->execute();
$this->Task->main();
$this->assertTrue(file_exists($this->path . DS . 'cake.pot'));
$result = file_get_contents($this->path . DS . 'cake.pot');

Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Console/Command/Task/FixtureTaskTest.php
Expand Up @@ -177,7 +177,7 @@ public function testImportRecordsNoEscaping() {
*
* @return void
*/
public function testExecuteWithTableOption() {
public function testMainWithTableOption() {
$this->Task->connection = 'test';
$this->Task->params = ['table' => 'comments'];
$filename = $this->_normalizePath(ROOT . '/Test/Fixture/ArticleFixture.php');
Expand All @@ -186,31 +186,31 @@ public function testExecuteWithTableOption() {
->method('createFile')
->with($filename, $this->stringContains("public \$table = 'comments';"));

$this->Task->execute('article');
$this->Task->main('article');
}

/**
* test that execute passes runs bake depending with named model.
*
* @return void
*/
public function testExecuteWithNamedModel() {
public function testMainWithNamedModel() {
$this->Task->connection = 'test';
$filename = $this->_normalizePath(ROOT . '/Test/Fixture/ArticleFixture.php');

$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains('class ArticleFixture'));

$this->Task->execute('article');
$this->Task->main('article');
}

/**
* test that execute runs all() when args[0] = all
*
* @return void
*/
public function testExecuteIntoAll() {
public function testMainIntoAll() {
$this->Task->connection = 'test';
$this->Task->Model->expects($this->any())
->method('listAll')
Expand All @@ -226,7 +226,7 @@ public function testExecuteIntoAll() {
->method('createFile')
->with($filename, $this->stringContains('class CommentFixture'));

$this->Task->execute('all');
$this->Task->all();
}

/**
Expand Down Expand Up @@ -284,7 +284,7 @@ public function testAllWithSchemaImport() {
*
* @return void
*/
public function testExecuteNoArgs() {
public function testMainNoArgs() {
$this->Task->connection = 'test';

$this->Task->Model->expects($this->any())
Expand All @@ -295,7 +295,7 @@ public function testExecuteNoArgs() {
$this->Task->expects($this->never())
->method('createFile');

$this->Task->execute();
$this->Task->main();
}

/**
Expand Down

0 comments on commit c2008e7

Please sign in to comment.