function MigrateTestCase::getMigration

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

Retrieves a mocked migration.

Parameters

\Drupal\migrate\Plugin\MigrateIdMapInterface|\PHPUnit\Framework\MockObject\MockObject|null $id_map: An ID map plugin to use, or NULL for using a mocked one. Optional, defaults to NULL.

Return value

\Drupal\migrate\Plugin\MigrationInterface|\PHPUnit\Framework\MockObject\MockObject The mocked migration.

24 calls to MigrateTestCase::getMigration()
Drupal6SqlBaseTest::setUp in core/modules/migrate_drupal/tests/src/Unit/source/d6/Drupal6SqlBaseTest.php
DrupalSqlBaseTest::testMinimumVersion in core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
@covers ::checkRequirements
DrupalSqlBaseTest::testSourceDatabaseError in core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
@covers ::checkRequirements
DrupalSqlBaseTest::testSourceProviderNotActive in core/modules/migrate_drupal/tests/src/Unit/source/DrupalSqlBaseTest.php
@covers ::checkRequirements
FileUriTest::doTransform in core/modules/file/tests/src/Unit/Plugin/migrate/process/d6/FileUriTest.php

... See full list

File

core/modules/migrate/tests/src/Unit/MigrateTestCase.php, line 47

Class

MigrateTestCase
Provides setup and helper methods for Migrate module tests.

Namespace

Drupal\Tests\migrate\Unit

Code

protected function getMigration($id_map = NULL) {
    $this->migrationConfiguration += [
        'migrationClass' => 'Drupal\\migrate\\Plugin\\Migration',
    ];
    $this->idMap = $id_map;
    if (is_null($id_map)) {
        $this->idMap = $this->createMock(MigrateIdMapInterface::class);
        $this->idMap
            ->method('getQualifiedMapTableName')
            ->willReturn('test_map');
    }
    $migration = $this->getMockBuilder($this->migrationConfiguration['migrationClass'])
        ->disableOriginalConstructor()
        ->getMock();
    $migration->method('checkRequirements')
        ->willReturn(TRUE);
    $migration->method('getIdMap')
        ->willReturn($this->idMap);
    // We need the state to be toggled throughout the test so we store the value
    // on the test class and use a return callback.
    $migration->expects($this->any())
        ->method('getStatus')
        ->willReturnCallback(function () {
        return $this->migrationStatus;
    });
    $migration->expects($this->any())
        ->method('setStatus')
        ->willReturnCallback(function ($status) {
        $this->migrationStatus = $status;
    });
    $migration->method('getMigrationDependencies')
        ->willReturn([
        'required' => [],
        'optional' => [],
    ]);
    $configuration =& $this->migrationConfiguration;
    $migration->method('set')
        ->willReturnCallback(function ($argument, $value) use (&$configuration) {
        $configuration[$argument] = $value;
    });
    $migration->method('id')
        ->willReturn($configuration['id']);
    return $migration;
}

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