Skip to content

Commit

Permalink
Remove dead options from fixture task.
Browse files Browse the repository at this point in the history
The `import-records` option doesn't actually do anything anymore, so we
don't need it. The generated import property is now correct as well.

Refs #192
  • Loading branch information
markstory committed Dec 4, 2015
1 parent 20c48a8 commit b72659a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
12 changes: 3 additions & 9 deletions src/Shell/Task/FixtureTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ public function getOptionParser()
' Used with --count and --conditions to limit which records are added to the fixture.',
'short' => 'r',
'boolean' => true
])->addOption('import-records', [
'help' => 'Set to true to import records from the live table when the generated fixture is used.',
'boolean' => true
])->addOption('conditions', [
'help' => 'The SQL snippet to use when importing records.',
'default' => '1=1',
Expand Down Expand Up @@ -158,10 +155,7 @@ public function bake($model, $useTable = null)
$importBits = [];
if (!empty($this->params['schema'])) {
$modelImport = true;
$importBits[] = "'model' => '{$model}'";
}
if (!empty($this->params['import-records'])) {
$importBits[] = "'records' => true";
$importBits[] = "'table' => '{$useTable}'";
}
if (!empty($importBits) && $this->connection !== 'default') {
$importBits[] = "'connection' => '{$this->connection}'";
Expand Down Expand Up @@ -189,14 +183,14 @@ public function bake($model, $useTable = null)
$schema = $this->_generateSchema($data);
}

if (empty($this->params['records']) && empty($this->params['import-records'])) {
if (empty($this->params['records'])) {
$recordCount = 1;
if (isset($this->params['count'])) {
$recordCount = $this->params['count'];
}
$records = $this->_makeRecordString($this->_generateRecords($data, $recordCount));
}
if (!empty($this->params['records']) && empty($this->params['import-records'])) {
if (!empty($this->params['records'])) {
$records = $this->_makeRecordString($this->_getRecordsFromTable($model, $useTable));
}
return $this->generateFixtureFile($model, compact('records', 'table', 'schema', 'import'));
Expand Down
30 changes: 5 additions & 25 deletions tests/TestCase/Shell/Task/FixtureTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ public function testAllWithSchemaImport()

$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/ArticlesFixture.php');
$this->Task->expects($this->at(0))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Articles'"));
->with($filename, $this->stringContains("public \$import = ['table' => 'articles'"));

$filename = $this->_normalizePath(ROOT . DS . 'tests' . DS . 'Fixture/CommentsFixture.php');
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, $this->stringContains("public \$import = ['model' => 'Comments'"));
->with($filename, $this->stringContains("public \$import = ['table' => 'comments'"));
$this->Task->expects($this->exactly(2))->method('createFile');

$this->Task->all();
Expand Down Expand Up @@ -316,26 +316,6 @@ public function testBake()
$result = $this->Task->main('Articles');
}

/**
* test main() with importing records
*
* @return void
*/
public function testMainImportRecords()
{
$this->Task->connection = 'test';
$this->Task->params = ['import-records' => true];

$this->Task->expects($this->at(0))
->method('createFile')
->with($this->anything(), $this->logicalAnd(
$this->stringContains("public \$import = ['records' => true, 'connection' => 'test'];"),
$this->logicalNot($this->stringContains('public $records'))
));

$this->Task->main('Article');
}

/**
* test main() with importing schema.
*
Expand All @@ -344,15 +324,15 @@ public function testMainImportRecords()
public function testMainImportSchema()
{
$this->Task->connection = 'test';
$this->Task->params = ['schema' => true, 'import-records' => true];
$this->Task->params = ['schema' => true];

$importString = "public \$import = ['model' => 'Article', 'records' => true, 'connection' => 'test'];";
$importString = "public \$import = ['table' => 'comments', 'connection' => 'test'];";
$this->Task->expects($this->once())
->method('createFile')
->with($this->anything(), $this->logicalAnd(
$this->stringContains($importString),
$this->logicalNot($this->stringContains('public $fields')),
$this->logicalNot($this->stringContains('public $records'))
$this->stringContains('public $records')
));
$this->Task->bake('Article', 'comments');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UsersFixture extends TestFixture
*
* @var array
*/
public $import = ['model' => 'Users', 'connection' => 'test'];
public $import = ['table' => 'users', 'connection' => 'test'];

/**
* Records
Expand Down

0 comments on commit b72659a

Please sign in to comment.