Permalink
Browse files

Implementing -records flag to enable quick access to building fixture…

…s off of live data. Refs #196
  • Loading branch information...
1 parent 857b7c2 commit 102f10365f1f604668db020975a1e4a4cc45b28e @markstory markstory committed Oct 24, 2009
Showing with 13 additions and 7 deletions.
  1. +11 −5 cake/console/libs/tasks/fixture.php
  2. +2 −2 cake/tests/cases/console/libs/tasks/fixture.test.php
@@ -90,6 +90,7 @@ function execute() {
}
if (isset($this->args[0])) {
+ $this->interactive = false;
if (!isset($this->connection)) {
$this->connection = 'default';
}
@@ -109,6 +110,7 @@ function execute() {
**/
function all() {
$this->interactive = false;
+ $this->Model->interactive = false;
$tables = $this->Model->listAll($this->connection, false);
foreach ($tables as $table) {
$model = $this->_modelName($table);
@@ -215,7 +217,7 @@ function bake($model, $useTable = false, $importOptions = array()) {
}
$records = $this->_makeRecordString($this->_generateRecords($tableInfo, $recordCount));
}
- if (isset($importOptions['fromTable'])) {
+ if (isset($this->params['records']) || isset($importOptions['fromTable'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
$out = $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import', 'fields'));
@@ -359,10 +361,14 @@ function _makeRecordString($records) {
* @return array Array of records.
**/
function _getRecordsFromTable($modelName, $useTable = null) {
- $condition = null;
- $prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
- while (!$condition) {
- $condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
+ if ($this->interactive) {
+ $condition = null;
+ $prompt = __("Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1 LIMIT 10", true);
+ while (!$condition) {
+ $condition = $this->in($prompt, null, 'WHERE 1=1 LIMIT 10');
+ }
+ } else {
+ $condition = 'WHERE 1=1 ' . isset($this->params['count']) ? $this->params['count'] : 10;
}
App::import('Model', 'Model', false);
$modelObject =& new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
@@ -198,10 +198,10 @@ function testAllWithCountAndRecordsFlags() {
$this->Task->Model->setReturnValue('listAll', array('articles', 'comments'));
$filename = '/my/path/article_fixture.php';
- $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticleFixture/')));
+ $this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/title\' => \'Third Article\'/')));
$filename = '/my/path/comment_fixture.php';
- $this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class CommentFixture/')));
+ $this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/comment\' => \'First Comment for First Article/')));
$this->Task->expectCallCount('createFile', 2);
$this->Task->all();
}

0 comments on commit 102f103

Please sign in to comment.