convert inline migrations in tests from PHP arrays to YAML

Created on 2 September 2024, 4 months ago

Problem/Motivation

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

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024