function MigrationLookupTest::testTransformWithStubbing

Same name in other branches
  1. 8.9.x core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php \Drupal\Tests\migrate\Unit\process\MigrationLookupTest::testTransformWithStubbing()
  2. 10 core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php \Drupal\Tests\migrate\Unit\process\MigrationLookupTest::testTransformWithStubbing()
  3. 11.x core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php \Drupal\Tests\migrate\Unit\process\MigrationLookupTest::testTransformWithStubbing()

@covers ::transform

File

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

Class

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

Namespace

Drupal\Tests\migrate\Unit\process

Code

public function testTransformWithStubbing() {
    $migration_plugin = $this->prophesize(MigrationInterface::class);
    $this->migrateLookup
        ->lookup('destination_migration', [
        1,
    ])
        ->willReturn(NULL);
    $this->migrateStub
        ->createStub('destination_migration', [
        1,
    ], [], FALSE)
        ->willReturn([
        2,
    ]);
    $configuration = [
        'no_stub' => FALSE,
        'migration' => 'destination_migration',
    ];
    $migration = MigrationLookup::create($this->prepareContainer(), $configuration, '', [], $migration_plugin->reveal());
    $result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
    $this->assertEquals(2, $result);
    $this->migrateStub
        ->createStub('destination_migration', [
        1,
    ], [], FALSE)
        ->willThrow(new \Exception('Oh noes!'));
    $migration = MigrationLookup::create($this->prepareContainer(), $configuration, '', [], $migration_plugin->reveal());
    $this->expectException(MigrateException::class);
    $this->expectExceptionMessage('Exception was thrown while attempting to stub: Oh noes!');
    $migration->transform(1, $this->migrateExecutable, $this->row, '');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.