Skip to content

Commit f19fa11

Browse files
committed
Update bake tasks to use method arguments over $args property.
Use the new positional arguments feature to clean up bake a bit.
1 parent 9e0da22 commit f19fa11

17 files changed

+62
-91
lines changed

src/Console/Command/BakeShell.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected function _findTaskClasses($files) {
190190
*
191191
* @return void
192192
*/
193-
public function all() {
193+
public function all($name = null) {
194194
$this->out('Bake All');
195195
$this->hr();
196196

@@ -199,7 +199,7 @@ public function all() {
199199
$this->connection = $this->params['connection'];
200200
}
201201

202-
if (empty($this->args)) {
202+
if (empty($name)) {
203203
$this->Model->connection = $this->connection;
204204
$this->out(__d('cake_console', 'Possible model names based on your database'));
205205
foreach ($this->Model->listAll() as $table) {
@@ -213,14 +213,12 @@ public function all() {
213213
$this->{$task}->connection = $this->connection;
214214
}
215215

216-
$name = $this->args[0];
217216
$name = $this->_modelName($name);
218217

219218
$this->Model->bake($name);
220219
$this->Controller->bake($name);
221220

222-
$this->View->args = [$name];
223-
$this->View->execute();
221+
$this->View->execute($name);
224222

225223
$this->out(__d('cake_console', '<success>Bake All complete</success>'), 1, Shell::QUIET);
226224
return true;

src/Console/Command/Task/ControllerTask.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ class ControllerTask extends BakeTask {
4444
*
4545
* @return void
4646
*/
47-
public function execute() {
47+
public function execute($name = null) {
4848
parent::execute();
4949

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

54-
if (empty($this->args)) {
54+
if (empty($name)) {
5555
$this->out(__d('cake_console', 'Possible controllers based on your current database:'));
5656
foreach ($this->listAll() as $table) {
5757
$this->out('- ' . $this->_controllerName($table));
5858
}
5959
return true;
6060
}
6161

62-
if (strtolower($this->args[0]) === 'all') {
62+
if (strtolower($name) === 'all') {
6363
return $this->all();
6464
}
6565

66-
$controller = $this->_controllerName($this->args[0]);
66+
$controller = $this->_controllerName($name);
6767
$this->bake($controller);
6868
}
6969

src/Console/Command/Task/FixtureTask.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ public function getOptionParser() {
9090
*
9191
* @return void
9292
*/
93-
public function execute() {
93+
public function execute($name = null) {
9494
parent::execute();
9595
if (!isset($this->connection)) {
9696
$this->connection = 'default';
9797
}
9898

99-
if (empty($this->args)) {
99+
if (empty($name)) {
100100
$this->out(__d('cake_console', 'Choose a fixture to bake from the following:'));
101101
foreach ($this->Model->listAll() as $table) {
102102
$this->out('- ' . $this->_modelName($table));
103103
}
104104
return true;
105105
}
106106

107-
if (strtolower($this->args[0]) === 'all') {
107+
if (strtolower($name) === 'all') {
108108
return $this->all();
109109
}
110110
$table = null;
111111
if (isset($this->params['table'])) {
112112
$table = $this->params['table'];
113113
}
114-
$model = $this->_modelName($this->args[0]);
114+
$model = $this->_modelName($name);
115115
$this->bake($model, $table);
116116
}
117117

src/Console/Command/Task/ModelTask.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,26 @@ class ModelTask extends BakeTask {
7575
*
7676
* @return void
7777
*/
78-
public function execute() {
78+
public function execute($name = null) {
7979
parent::execute();
8080

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

85-
if (empty($this->args)) {
85+
if (empty($name)) {
8686
$this->out(__d('cake_console', 'Choose a model to bake from the following:'));
8787
foreach ($this->listAll() as $table) {
8888
$this->out('- ' . $this->_modelName($table));
8989
}
9090
return true;
9191
}
9292

93-
if (strtolower($this->args[0]) === 'all') {
93+
if (strtolower($name) === 'all') {
9494
return $this->all();
9595
}
9696

97-
$this->bake($this->_modelName($this->args[0]));
97+
$this->bake($this->_modelName($name));
9898
}
9999

100100
/**

src/Console/Command/Task/PluginTask.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public function initialize() {
5656
*
5757
* @return void
5858
*/
59-
public function execute() {
60-
if (empty($this->args[0])) {
59+
public function execute($name = null) {
60+
if (empty($name)) {
6161
$this->err('<error>You must provide a plugin name in CamelCase format.</error>');
6262
$this->err('To make an "Example" plugin, run <info>Console/cake bake plugin Example</info>.');
6363
return false;
6464
}
65-
$plugin = $this->_camelize($this->args[0]);
65+
$plugin = $this->_camelize($name);
6666
$pluginPath = $this->_pluginPath($plugin);
6767
if (is_dir($pluginPath)) {
6868
$this->out(__d('cake_console', 'Plugin: %s already exists, no action taken', $plugin));

src/Console/Command/Task/SimpleBakeTask.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public function templateData() {
7272
*
7373
* @return void
7474
*/
75-
public function execute() {
75+
public function execute($name = null) {
7676
parent::execute();
77-
$name = Inflector::classify($this->args[0]);
77+
$name = Inflector::classify($name);
7878
$this->bake($name);
7979
$this->bakeTest($name);
8080
}

src/Console/Command/Task/TestTask.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,17 @@ class TestTask extends BakeTask {
7979
*
8080
* @return void
8181
*/
82-
public function execute() {
82+
public function execute($type = null, $name = null) {
8383
parent::execute();
84-
if (empty($this->args)) {
84+
if (empty($type) && empty($name)) {
8585
return $this->outputTypeChoices();
8686
}
8787

88-
$count = count($this->args);
89-
if ($count === 1) {
90-
return $this->outputClassChoices($this->args[0]);
88+
if (empty($name)) {
89+
return $this->outputClassChoices($type);
9190
}
9291

93-
if ($this->bake($this->args[0], $this->args[1])) {
92+
if ($this->bake($type, $name)) {
9493
$this->out('<success>Done</success>');
9594
}
9695
}

src/Console/Command/Task/ViewTask.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ public function initialize() {
9898
*
9999
* @return mixed
100100
*/
101-
public function execute() {
101+
public function execute($name = null, $template = null, $action = null) {
102102
parent::execute();
103103

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

108-
if (empty($this->args)) {
108+
if (empty($name)) {
109109
$this->out(__d('cake_console', 'Possible tables to bake views for based on your current database:'));
110110
$this->Model->connection = $this->connection;
111111
foreach ($this->Model->listAll() as $table) {
@@ -114,22 +114,18 @@ public function execute() {
114114
return true;
115115
}
116116

117-
$action = null;
118-
if (strtolower($this->args[0]) === 'all') {
117+
if (strtolower($name) === 'all') {
119118
return $this->all();
120119
}
121120

122121
$controller = null;
123122
if (!empty($this->params['controller'])) {
124123
$controller = $this->params['controller'];
125124
}
126-
$this->controller($this->args[0], $controller);
125+
$this->controller($name, $controller);
127126

128-
if (isset($this->args[1])) {
129-
$this->template = $this->args[1];
130-
}
131-
if (isset($this->args[2])) {
132-
$action = $this->args[2];
127+
if (isset($template)) {
128+
$this->template = $template;
133129
}
134130
if (!$action) {
135131
$action = $this->template;
@@ -223,8 +219,7 @@ public function all() {
223219
$tables = $this->Model->listAll();
224220

225221
foreach ($tables as $table) {
226-
$this->args[0] = $table;
227-
$this->execute();
222+
$this->execute($table);
228223
}
229224
}
230225

tests/TestCase/Console/Command/BakeShellTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function testAllWithModelName() {
7878
->will($this->returnValue(true));
7979

8080
$this->Shell->View->expects($this->once())
81-
->method('execute');
81+
->method('execute')
82+
->with('Comments');
8283

8384
$this->Shell->expects($this->at(0))
8485
->method('out')
@@ -90,10 +91,7 @@ public function testAllWithModelName() {
9091

9192
$this->Shell->connection = '';
9293
$this->Shell->params = [];
93-
$this->Shell->args = ['Comment'];
94-
$this->Shell->all();
95-
96-
$this->assertEquals('Comments', $this->Shell->View->args[0]);
94+
$this->Shell->all('Comment');
9795
}
9896

9997
/**

tests/TestCase/Console/Command/Task/ControllerTaskTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ public function testExecuteIntoAll() {
302302
$this->markTestSkipped('Additional tables detected.');
303303
}
304304
$this->Task->connection = 'test';
305-
$this->Task->args = ['all'];
306305
$this->Task->params = ['helpers' => 'Time,Text'];
307306

308307
$this->Task->Test->expects($this->atLeastOnce())
@@ -317,7 +316,7 @@ public function testExecuteIntoAll() {
317316
))
318317
->will($this->returnValue(true));
319318

320-
$this->Task->execute();
319+
$this->Task->execute('all');
321320
}
322321

323322
/**
@@ -339,13 +338,12 @@ public static function nameVariations() {
339338
*/
340339
public function testExecuteWithControllerNameVariations($name) {
341340
$this->Task->connection = 'test';
342-
$this->Task->args = [$name];
343341

344342
$filename = APP . 'Controller/BakeArticlesController.php';
345343
$this->Task->expects($this->once())
346344
->method('createFile')
347345
->with($filename, $this->stringContains('public function index()'));
348-
$this->Task->execute();
346+
$this->Task->execute($name);
349347
}
350348

351349
}

tests/TestCase/Console/Command/Task/FixtureTaskTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,14 @@ public function testImportRecordsNoEscaping() {
179179
*/
180180
public function testExecuteWithTableOption() {
181181
$this->Task->connection = 'test';
182-
$this->Task->args = array('article');
183182
$this->Task->params = ['table' => 'comments'];
184183
$filename = ROOT . '/Test/Fixture/ArticleFixture.php';
185184

186185
$this->Task->expects($this->at(0))
187186
->method('createFile')
188187
->with($filename, $this->stringContains("public \$table = 'comments';"));
189188

190-
$this->Task->execute();
189+
$this->Task->execute('article');
191190
}
192191

193192
/**
@@ -197,14 +196,13 @@ public function testExecuteWithTableOption() {
197196
*/
198197
public function testExecuteWithNamedModel() {
199198
$this->Task->connection = 'test';
200-
$this->Task->args = array('article');
201199
$filename = ROOT . '/Test/Fixture/ArticleFixture.php';
202200

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

207-
$this->Task->execute();
205+
$this->Task->execute('article');
208206
}
209207

210208
/**
@@ -214,7 +212,6 @@ public function testExecuteWithNamedModel() {
214212
*/
215213
public function testExecuteIntoAll() {
216214
$this->Task->connection = 'test';
217-
$this->Task->args = array('all');
218215
$this->Task->Model->expects($this->any())
219216
->method('listAll')
220217
->will($this->returnValue(array('articles', 'comments')));
@@ -229,7 +226,7 @@ public function testExecuteIntoAll() {
229226
->method('createFile')
230227
->with($filename, $this->stringContains('class CommentFixture'));
231228

232-
$this->Task->execute();
229+
$this->Task->execute('all');
233230
}
234231

235232
/**
@@ -239,7 +236,6 @@ public function testExecuteIntoAll() {
239236
*/
240237
public function testAllWithCountAndRecordsFlags() {
241238
$this->Task->connection = 'test';
242-
$this->Task->args = ['all'];
243239
$this->Task->params = ['count' => 10, 'records' => true];
244240

245241
$this->Task->Model->expects($this->any())->method('listAll')
@@ -266,7 +262,6 @@ public function testAllWithCountAndRecordsFlags() {
266262
*/
267263
public function testAllWithSchemaImport() {
268264
$this->Task->connection = 'test';
269-
$this->Task->args = array('all');
270265
$this->Task->params = array('schema' => true);
271266

272267
$this->Task->Model->expects($this->any())->method('listAll')

0 commit comments

Comments
 (0)