- Issue created by @joachim
Migration kernel tests often define a migration plugin in the body of the test. This is defined as a PHP array of the migration plugin's definition, e.g.
$definition = [
'id' => 'terms',
'migration_tags' => ['Bundle test'],
'source' => [
'plugin' => 'embedded_data',
'data_rows' => $term_data_rows,
'ids' => $ids,
],
'process' => [
'tid' => 'id',
'name' => 'name',
],
'destination' => [
'plugin' => 'entity:taxonomy_term',
'default_bundle' => 'categories',
],
'migration_dependencies' => [],
];
This is fine within the context of the test, but a PHP array is a fundamentally different format from what developers use for real migrations, which is YAML.
Tests could instead define migrations in YAML, like this:
$no_fields_definition = Yaml::decode(
<<<EOT
id: no_fields
label: Migrate to no bundle specified destination
source:
plugin: embedded_data
data_rows: {}
constants:
type: test_bundle_no_fields
process:
type: constants/type
title: title
destination:
plugin: entity:entity_test_with_bundle
default_bundle: test_bundle_no_fields
EOT
);
The advantage of doing this is that migration configuration can be easily copy-pasted between test migrations and real migrations:
- Developers writing a migration can look at migration tests as example of best practice, and can easily use copy pieces of migration configuration from tests
- Developers writing a test for a bug can easily use parts of their real migration in a test
Active
11.0 π₯
Enhances developer experience.