Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add schema param and skip interactive prompts if unnecessary #1261

Merged
merged 1 commit into from

2 participants

@dereuromark
Collaborator

Improvements for schema baking.

-s / --schema option added to allow baking all fixtures with noninteractive "all" while using schema import.

I also removed the interactive prompts for records or schema if already passed in as command line arguments as this is then unnecessary.

@markstory markstory commented on the diff
lib/Cake/Console/Command/Task/FixtureTask.php
@@ -83,8 +83,12 @@ public function getOptionParser() {
))->addOption('plugin', array(
'help' => __d('cake_console', 'CamelCased name of the plugin to bake fixtures for.'),
'short' => 'p',
+ ))->addOption('schema', array(
@markstory Owner

Maybe this should be import-schema?

@dereuromark Collaborator

Should "records" then also be "import-records"?

@markstory Owner

Bah good point. I'm just trying to think about what else we could use 'schema' for in the future.

@dereuromark Collaborator

Any more thoughts? Or good to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@markstory markstory merged commit 293ba4c into from
@markstory
Owner

Merged in, don't forget to update the docs/migration guide :smile:

@dereuromark dereuromark referenced this pull request in cakephp/docs
Merged

schema param for FixtureTask #567

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
28 lib/Cake/Console/Command/Task/FixtureTask.php
@@ -83,8 +83,12 @@ public function getOptionParser() {
))->addOption('plugin', array(
'help' => __d('cake_console', 'CamelCased name of the plugin to bake fixtures for.'),
'short' => 'p',
+ ))->addOption('schema', array(
@markstory Owner

Maybe this should be import-schema?

@dereuromark Collaborator

Should "records" then also be "import-records"?

@markstory Owner

Bah good point. I'm just trying to think about what else we could use 'schema' for in the future.

@dereuromark Collaborator

Any more thoughts? Or good to merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 'help' => __d('cake_console', 'Importing schema for fixtures rather than hardcoding it.'),
+ 'short' => 's',
+ 'boolean' => true
))->addOption('records', array(
- 'help' => __d('cake_console', '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'),
+ 'help' => __d('cake_console', '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
))->epilog(__d('cake_console', 'Omitting all arguments and options will enter into an interactive mode.'));
@@ -124,9 +128,14 @@ public function all() {
$this->interactive = false;
$this->Model->interactive = false;
$tables = $this->Model->listAll($this->connection, false);
+
foreach ($tables as $table) {
$model = $this->_modelName($table);
- $this->bake($model);
+ $importOptions = array();
+ if (!empty($this->params['schema'])) {
+ $importOptions['schema'] = $model;
+ }
+ $this->bake($model, false, $importOptions);
}
}
@@ -158,11 +167,20 @@ protected function _interactive() {
*/
public function importOptions($modelName) {
$options = array();
- $doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
- if ($doSchema === 'y') {
+
+ if (!empty($this->params['schema'])) {
$options['schema'] = $modelName;
+ } else {
+ $doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
+ if ($doSchema === 'y') {
+ $options['schema'] = $modelName;
+ }
+ }
+ if (!empty($this->params['records'])) {
+ $doRecords = 'y';
+ } else {
+ $doRecords = $this->in(__d('cake_console', 'Would you like to use record importing for this fixture?'), array('y', 'n'), 'n');
}
- $doRecords = $this->in(__d('cake_console', 'Would you like to use record importing for this fixture?'), array('y', 'n'), 'n');
if ($doRecords === 'y') {
$options['records'] = true;
}
View
68 lib/Cake/Test/Case/Console/Command/Task/FixtureTaskTest.php
@@ -124,6 +124,48 @@ public function testImportOptionsNothing() {
}
/**
+ * test importOptions with overwriting command line options.
+ *
+ * @return void
+ */
+ public function testImportOptionsWithCommandLineOptions() {
+ $this->Task->params = array('schema' => true, 'records' => true);
+
+ $result = $this->Task->importOptions('Article');
+ $expected = array('schema' => 'Article', 'records' => true);
+ $this->assertEquals($expected, $result);
+ }
+
+/**
+ * test importOptions with schema.
+ *
+ * @return void
+ */
+ public function testImportOptionsWithSchema() {
+ $this->Task->params = array('schema' => true);
+ $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
+ $this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
+
+ $result = $this->Task->importOptions('Article');
+ $expected = array('schema' => 'Article');
+ $this->assertEquals($expected, $result);
+ }
+
+/**
+ * test importOptions with records.
+ *
+ * @return void
+ */
+ public function testImportOptionsWithRecords() {
+ $this->Task->params = array('records' => true);
+ $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
+
+ $result = $this->Task->importOptions('Article');
+ $expected = array('records' => true);
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* test importOptions choosing from Table.
*
* @return void
@@ -273,6 +315,32 @@ public function testAllWithCountAndRecordsFlags() {
}
/**
+ * test using all() with -schema
+ *
+ * @return void
+ */
+ public function testAllWithSchemaImport() {
+ $this->Task->connection = 'test';
+ $this->Task->path = '/my/path/';
+ $this->Task->args = array('all');
+ $this->Task->params = array('schema' => true);
+
+ $this->Task->Model->expects($this->any())->method('listAll')
+ ->will($this->returnValue(array('Articles', 'comments')));
+
+ $filename = '/my/path/ArticleFixture.php';
+ $this->Task->expects($this->at(0))->method('createFile')
+ ->with($filename, $this->stringContains('public $import = array(\'model\' => \'Article\''));
+
+ $filename = '/my/path/CommentFixture.php';
+ $this->Task->expects($this->at(1))->method('createFile')
+ ->with($filename, $this->stringContains('public $import = array(\'model\' => \'Comment\''));
+ $this->Task->expects($this->exactly(2))->method('createFile');
+
+ $this->Task->all();
+ }
+
+/**
* test interactive mode of execute
*
* @return void
Something went wrong with that request. Please try again.