|
|
@@ -20,6 +20,7 @@ use Cake\Datasource\ConnectionInterface;
|
|
|
use Cake\Datasource\ConnectionManager;
|
|
|
use Cake\Datasource\FixtureInterface;
|
|
|
use Cake\Log\Log;
|
|
|
+use Cake\ORM\TableRegistry;
|
|
|
use Cake\Utility\Inflector;
|
|
|
use Exception;
|
|
|
|
|
|
@@ -58,11 +59,11 @@ class TestFixture implements FixtureInterface
|
|
|
/**
|
|
|
* Configuration for importing fixture schema
|
|
|
*
|
|
|
- * Accepts a `connection` and `table` key, to define
|
|
|
+ * Accepts a `connection` and `model` or `table` key, to define
|
|
|
* which table and which connection contain the schema to be
|
|
|
* imported.
|
|
|
*
|
|
|
- * @var array
|
|
|
+ * @var array|null
|
|
|
*/
|
|
|
public $import = null;
|
|
|
|
|
|
@@ -100,7 +101,7 @@ class TestFixture implements FixtureInterface
|
|
|
$message = sprintf(
|
|
|
'Invalid datasource name "%s" for "%s" fixture. Fixture datasource names must begin with "test".',
|
|
|
$connection,
|
|
|
- $this->name
|
|
|
+ $this->table
|
|
|
);
|
|
|
throw new CakeException($message);
|
|
|
}
|
|
|
@@ -196,17 +197,21 @@ class TestFixture implements FixtureInterface
|
|
|
if (!is_array($this->import)) {
|
|
|
return;
|
|
|
}
|
|
|
- $import = array_merge(
|
|
|
- ['connection' => 'default', 'table' => null],
|
|
|
- $this->import
|
|
|
- );
|
|
|
+ $import = $this->import + ['connection' => 'default', 'table' => null, 'model' => null];
|
|
|
+
|
|
|
+ if (!empty($import['model'])) {
|
|
|
+ if (!empty($import['table'])) {
|
|
|
+ throw new CakeException('You cannot define both table and model.');
|
|
|
+ }
|
|
|
+ $import['table'] = TableRegistry::get($import['model'])->table();
|
|
|
+ }
|
|
|
|
|
|
if (empty($import['table'])) {
|
|
|
throw new CakeException('Cannot import from undefined table.');
|
|
|
- } else {
|
|
|
- $this->table = $import['table'];
|
|
|
}
|
|
|
|
|
|
+ $this->table = $import['table'];
|
|
|
+
|
|
|
$db = ConnectionManager::get($import['connection'], false);
|
|
|
$schemaCollection = $db->schemaCollection();
|
|
|
$table = $schemaCollection->describe($import['table']);
|