protected function MediaMigrationTestDatabaseTrait::importSourceDatabase in Media Migration 8
Loads a database fixture into the source database connection.
Parameters
array $database: The source data, keyed by table name. Each table is an array containing the rows in that table.
2 calls to MediaMigrationTestDatabaseTrait::importSourceDatabase()
- MediaMigrationFilterFormatTest::testFilterFormatMigration in tests/
src/ Kernel/ Migrate/ MediaMigrationFilterFormatTest.php - Tests the alterations made on the filter format migration.
- MediaMigrationSourceTestBase::testSource in tests/
src/ Kernel/ Plugin/ migrate/ source/ d7/ MediaMigrationSourceTestBase.php - @dataProvider providerSource
File
- tests/
src/ Traits/ MediaMigrationTestDatabaseTrait.php, line 55
Class
- MediaMigrationTestDatabaseTrait
- Trait for importing custom data into the migrate source database.
Namespace
Drupal\Tests\media_migration\TraitsCode
protected function importSourceDatabase(array $database) : void {
// Create the tables and fill them with data.
foreach ($database as $table => $rows) {
// Use the biggest row to build the table schema.
$counts = array_map('count', $rows);
asort($counts);
end($counts);
$pilot = $rows[key($counts)];
$schema = array_map(function ($value) {
$type = is_numeric($value) && !is_float($value + 0) ? 'int' : 'text';
return [
'type' => $type,
];
}, $pilot);
$this->sourceDatabase
->schema()
->createTable($table, [
'fields' => $schema,
]);
$fields = array_keys($pilot);
$insert = $this->sourceDatabase
->insert($table)
->fields($fields);
array_walk($rows, [
$insert,
'values',
]);
$insert
->execute();
}
}