mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Use import options when going through execute()
The `records` and `schema` options should work when using execute(). Previously they were not working. Furthermore, the records option did a non-sensical thing where it both set import=>records and generated static records from the live table. The `records` option now enables the generation of static data from a live table, as I think this is a more common scenario. Refs #8693
This commit is contained in:
parent
ce5d64b083
commit
3a75e8aa72
2 changed files with 73 additions and 10 deletions
|
@ -125,7 +125,8 @@ class FixtureTask extends BakeTask {
|
||||||
return $this->all();
|
return $this->all();
|
||||||
}
|
}
|
||||||
$model = $this->_modelName($this->args[0]);
|
$model = $this->_modelName($this->args[0]);
|
||||||
$this->bake($model);
|
$importOptions = $this->importOptions($model);
|
||||||
|
$this->bake($model, false, $importOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,21 +181,22 @@ class FixtureTask extends BakeTask {
|
||||||
|
|
||||||
if (!empty($this->params['schema'])) {
|
if (!empty($this->params['schema'])) {
|
||||||
$options['schema'] = $modelName;
|
$options['schema'] = $modelName;
|
||||||
} else {
|
} elseif ($this->interactive) {
|
||||||
$doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
|
$doSchema = $this->in(__d('cake_console', 'Would you like to import schema for this fixture?'), array('y', 'n'), 'n');
|
||||||
if ($doSchema === 'y') {
|
if ($doSchema === 'y') {
|
||||||
$options['schema'] = $modelName;
|
$options['schema'] = $modelName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->params['records'])) {
|
if (!empty($this->params['records'])) {
|
||||||
$doRecords = 'y';
|
$options['fromTable'] = true;
|
||||||
} else {
|
} elseif ($this->interactive) {
|
||||||
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($doRecords === 'y') {
|
if (!isset($options['records']) && $this->interactive) {
|
||||||
$options['records'] = true;
|
|
||||||
}
|
|
||||||
if ($doRecords === 'n') {
|
|
||||||
$prompt = __d('cake_console', "Would you like to build this fixture with data from %s's table?", $modelName);
|
$prompt = __d('cake_console', "Would you like to build this fixture with data from %s's table?", $modelName);
|
||||||
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
|
$fromTable = $this->in($prompt, array('y', 'n'), 'n');
|
||||||
if (strtolower($fromTable) === 'y') {
|
if (strtolower($fromTable) === 'y') {
|
||||||
|
|
|
@ -98,6 +98,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptionsSchemaRecords() {
|
public function testImportOptionsSchemaRecords() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
|
|
||||||
|
@ -112,6 +113,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptionsNothing() {
|
public function testImportOptionsNothing() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n'));
|
||||||
|
@ -130,7 +132,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->Task->params = array('schema' => true, 'records' => true);
|
$this->Task->params = array('schema' => true, 'records' => true);
|
||||||
|
|
||||||
$result = $this->Task->importOptions('Article');
|
$result = $this->Task->importOptions('Article');
|
||||||
$expected = array('schema' => 'Article', 'records' => true);
|
$expected = array('schema' => 'Article', 'fromTable' => true);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +142,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptionsWithSchema() {
|
public function testImportOptionsWithSchema() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
$this->Task->params = array('schema' => true);
|
$this->Task->params = array('schema' => true);
|
||||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
|
@ -155,11 +158,12 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptionsWithRecords() {
|
public function testImportOptionsWithRecords() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
$this->Task->params = array('records' => true);
|
$this->Task->params = array('records' => true);
|
||||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
|
|
||||||
$result = $this->Task->importOptions('Article');
|
$result = $this->Task->importOptions('Article');
|
||||||
$expected = array('records' => true);
|
$expected = array('fromTable' => true);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,6 +173,7 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testImportOptionsTable() {
|
public function testImportOptionsTable() {
|
||||||
|
$this->Task->interactive = true;
|
||||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('y'));
|
||||||
|
@ -244,6 +249,62 @@ class FixtureTaskTest extends CakeTestCase {
|
||||||
$this->assertContains("'body' => 'Body \"value\"'", $result, 'Data has bad escaping');
|
$this->assertContains("'body' => 'Body \"value\"'", $result, 'Data has bad escaping');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that execute includes import options
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithImportSchema() {
|
||||||
|
$this->Task->connection = 'test';
|
||||||
|
$this->Task->path = '/my/path/';
|
||||||
|
$this->Task->args = array('article');
|
||||||
|
$this->Task->params = array(
|
||||||
|
'schema' => true,
|
||||||
|
'records' => false,
|
||||||
|
);
|
||||||
|
$filename = '/my/path/ArticleFixture.php';
|
||||||
|
|
||||||
|
$this->Task->expects($this->never())
|
||||||
|
->method('in');
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(0))
|
||||||
|
->method('createFile')
|
||||||
|
->with($filename, $this->logicalAnd(
|
||||||
|
$this->stringContains('class ArticleFixture'),
|
||||||
|
$this->stringContains("\$import = array('model' => 'Article'")
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->Task->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that execute includes import options
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithImportRecords() {
|
||||||
|
$this->Task->connection = 'test';
|
||||||
|
$this->Task->path = '/my/path/';
|
||||||
|
$this->Task->args = array('article');
|
||||||
|
$this->Task->params = array(
|
||||||
|
'schema' => true,
|
||||||
|
'records' => true,
|
||||||
|
);
|
||||||
|
$filename = '/my/path/ArticleFixture.php';
|
||||||
|
|
||||||
|
$this->Task->expects($this->never())
|
||||||
|
->method('in');
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(0))
|
||||||
|
->method('createFile')
|
||||||
|
->with($filename, $this->logicalAnd(
|
||||||
|
$this->stringContains('class ArticleFixture'),
|
||||||
|
$this->stringContains("\$import = array('model' => 'Article', 'connection' => 'test')")
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->Task->execute();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that execute passes runs bake depending with named model.
|
* test that execute passes runs bake depending with named model.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue