You are here

public function MigrationLookupTest::testMultipleMigrations in Drupal 10

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php \Drupal\Tests\migrate\Unit\process\MigrationLookupTest::testMultipleMigrations()

Tests processing multiple migrations and source IDs.

File

core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php, line 257

Class

MigrationLookupTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\MigrationLookup @group migrate

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testMultipleMigrations() {
  $migration_plugin = $this
    ->prophesize(MigrationInterface::class);
  $this->migrateLookup
    ->lookup('example', [
    1,
  ])
    ->willReturn([
    [
      2,
    ],
  ]);
  $this->migrateLookup
    ->lookup('example', [
    2,
  ])
    ->willReturn([]);
  $this->migrateLookup
    ->lookup('foobar', [
    1,
    2,
  ])
    ->willReturn([]);
  $this->migrateLookup
    ->lookup('foobar', [
    3,
    4,
  ])
    ->willReturn([
    [
      5,
    ],
  ]);
  $configuration = [
    'migration' => [
      'foobar',
      'example',
    ],
    'source_ids' => [
      'foobar' => [
        'foo',
        'bar',
      ],
    ],
  ];
  $migration = MigrationLookup::create($this
    ->prepareContainer(), $configuration, '', [], $migration_plugin
    ->reveal());
  $row1 = $this->row;
  $row2 = clone $this->row;
  $row1
    ->expects($this
    ->any())
    ->method('getMultiple')
    ->willReturn([
    1,
    2,
  ]);
  $result = $migration
    ->transform([
    1,
  ], $this->migrateExecutable, $row1, '');
  $this
    ->assertEquals(2, $result);
  $row2
    ->expects($this
    ->any())
    ->method('getMultiple')
    ->willReturn([
    3,
    4,
  ]);
  $result = $migration
    ->transform([
    2,
  ], $this->migrateExecutable, $row2, '');
  $this
    ->assertEquals(5, $result);
}