class MigrationTest
Same name in this branch
- 8.9.x core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 8.9.x core/modules/migrate/tests/src/Kernel/MigrationTest.php \Drupal\Tests\migrate\Kernel\MigrationTest
- 8.9.x core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php \Drupal\Tests\migrate\Kernel\Plugin\MigrationTest
Same name in other branches
- 9 core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 9 core/modules/migrate/tests/src/Kernel/MigrationTest.php \Drupal\Tests\migrate\Kernel\MigrationTest
- 9 core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php \Drupal\Tests\migrate\Kernel\Plugin\MigrationTest
- 10 core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 10 core/modules/migrate/tests/src/Kernel/MigrationTest.php \Drupal\Tests\migrate\Kernel\MigrationTest
- 10 core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php \Drupal\Tests\migrate\Kernel\Plugin\MigrationTest
- 11.x core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 11.x core/modules/migrate/tests/src/Kernel/MigrationTest.php \Drupal\Tests\migrate\Kernel\MigrationTest
- 11.x core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php \Drupal\Tests\migrate\Kernel\Plugin\MigrationTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration @group migrate @group legacy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrateTestCase extends \Drupal\Tests\UnitTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase extends \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrationLookupTestCase extends \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrationTest extends \Drupal\Tests\migrate\Unit\process\MigrationLookupTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrationLookupTestCase extends \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase
- class \Drupal\Tests\migrate\Unit\process\MigrateProcessTestCase extends \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of MigrationTest
File
-
core/
modules/ migrate/ tests/ src/ Unit/ process/ MigrationTest.php, line 18
Namespace
Drupal\Tests\migrate\Unit\processView source
class MigrationTest extends MigrationLookupTestCase {
/**
* @var \Drupal\migrate\Plugin\MigrationInterface
*/
protected $migration_plugin;
/**
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $migration_plugin_manager;
/**
* @var \Drupal\migrate\Plugin\MigratePluginManager
*/
protected $process_plugin_manager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migration_plugin = $this->prophesize(MigrationInterface::class);
$this->migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$this->process_plugin_manager = $this->prophesize(MigratePluginManager::class);
}
/**
* Tests a lookup with no stubbing.
*
* @covers ::transform
*
* @expectedDeprecation Not passing the migrate lookup service as the fifth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateLookupInterface. See https://www.drupal.org/node/3047268
* @expectedDeprecation Not passing the migrate stub service as the sixth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateStubInterface. See https://www.drupal.org/node/3047268
*/
public function testTransformWithStubSkipping() {
$configuration = [
'no_stub' => TRUE,
'migration' => 'destination_migration',
];
$this->migrateLookup
->lookup('destination_migration', [
1,
])
->willReturn([]);
$this->prepareContainer();
$migration = new Migration($configuration, '', [], $this->migration_plugin
->reveal(), $this->migration_plugin_manager
->reveal(), $this->process_plugin_manager
->reveal());
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
$this->assertNull($result);
}
/**
* Tests a lookup with stubbing.
*
* @covers ::transform
*
* @expectedDeprecation Not passing the migrate lookup service as the fifth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateLookupInterface. See https://www.drupal.org/node/3047268
* @expectedDeprecation Not passing the migrate stub service as the sixth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateStubInterface. See https://www.drupal.org/node/3047268
*/
public function testTransformWithStubbing() {
$configuration = [
'no_stub' => FALSE,
'migration' => 'destination_migration',
];
$this->migrateLookup
->lookup('destination_migration', [
1,
])
->willReturn([]);
$this->migrateStub
->createStub('destination_migration', [
1,
], [], FALSE)
->willReturn([
2,
]);
$this->prepareContainer();
$migration = new Migration($configuration, '', [], $this->migration_plugin
->reveal(), $this->migration_plugin_manager
->reveal(), $this->process_plugin_manager
->reveal());
$result = $migration->transform(1, $this->migrateExecutable, $this->row, '');
$this->assertEquals(2, $result);
}
/**
* Creates a mock Migration instance.
*
* @return \Prophecy\Prophecy\ObjectProphecy
* A mock Migration instance.
*/
protected function getMigration() {
$id_map = $this->prophesize(MigrateIdMapInterface::class);
$id_map->lookupDestinationIds([
1,
])
->willReturn(NULL);
$id_map->saveIdMapping(Argument::any(), Argument::any(), MigrateIdMapInterface::STATUS_NEEDS_UPDATE)
->willReturn(NULL);
$migration = $this->prophesize(MigrationInterface::class);
$migration->getIdMap()
->willReturn($id_map->reveal());
return $migration;
}
/**
* Tests that processing is skipped when the input value is empty.
*
* @expectedDeprecation Not passing the migrate lookup service as the fifth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateLookupInterface. See https://www.drupal.org/node/3047268
* @expectedDeprecation Not passing the migrate stub service as the sixth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateStubInterface. See https://www.drupal.org/node/3047268
*/
public function testSkipOnEmpty() {
$configuration = [
'migration' => 'foobaz',
];
$this->migration_plugin
->id()
->willReturn(uniqid());
$this->migration_plugin_manager
->createInstances([
'foobaz',
])
->willReturn([
'foobaz' => $this->migration_plugin
->reveal(),
]);
$this->prepareContainer();
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin
->reveal(), $this->migration_plugin_manager
->reveal(), $this->process_plugin_manager
->reveal());
$this->expectException(MigrateSkipProcessException::class);
$migration->transform(FALSE, $this->migrateExecutable, $this->row, 'foo');
}
/**
* Tests a successful lookup.
*
* @param array $source_id_values
* The source id(s) of the migration map.
* @param array $destination_id_values
* The destination id(s) of the migration map.
* @param string|array $source_value
* The source value(s) for the migration process plugin.
* @param string|array $expected_value
* The expected value(s) of the migration process plugin.
*
* @dataProvider successfulLookupDataProvider
*
* @expectedDeprecation Not passing the migrate lookup service as the fifth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateLookupInterface. See https://www.drupal.org/node/3047268
* @expectedDeprecation Not passing the migrate stub service as the sixth parameter to Drupal\migrate\Plugin\migrate\process\MigrationLookup::__construct is deprecated in drupal:8.8.0 and will throw a type error in drupal:9.0.0. Pass an instance of \Drupal\migrate\MigrateStubInterface. See https://www.drupal.org/node/3047268
*
* @throws \Drupal\migrate\MigrateSkipProcessException
*/
public function testSuccessfulLookup(array $source_id_values, array $destination_id_values, $source_value, $expected_value) {
$configuration = [
'migration' => 'foobaz',
];
$this->migrateLookup
->lookup('foobaz', $source_id_values)
->willReturn([
$destination_id_values,
]);
$this->prepareContainer();
$migration = new Migration($configuration, 'migration', [], $this->migration_plugin
->reveal(), $this->migration_plugin_manager
->reveal(), $this->process_plugin_manager
->reveal());
$this->assertSame($expected_value, $migration->transform($source_value, $this->migrateExecutable, $this->row, 'foo'));
}
/**
* Provides data for the successful lookup test.
*
* @return array
* The data.
*/
public function successfulLookupDataProvider() {
return [
'scalar_to_scalar' => [
'source_ids' => [
1,
],
'destination_ids' => [
3,
],
'input_value' => 1,
'expected_value' => 3,
],
'scalar_to_array' => [
'source_ids' => [
1,
],
'destination_ids' => [
3,
'foo',
],
'input_value' => 1,
'expected_value' => [
3,
'foo',
],
],
'array_to_scalar' => [
'source_ids' => [
1,
3,
],
'destination_ids' => [
'foo',
],
'input_value' => [
1,
3,
],
'expected_value' => 'foo',
],
'array_to_array' => [
'source_ids' => [
1,
3,
],
'destination_ids' => [
3,
'foo',
],
'input_value' => [
1,
3,
],
'expected_value' => [
3,
'foo',
],
],
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
MigrateProcessTestCase::$migrateExecutable | protected | property | ||||
MigrateProcessTestCase::$plugin | protected | property | ||||
MigrateProcessTestCase::$row | protected | property | ||||
MigrateTestCase::$idMap | protected | property | The migration ID map. | |||
MigrateTestCase::$migrationConfiguration | protected | property | An array of migration configuration values. | 16 | ||
MigrateTestCase::$migrationStatus | protected | property | Local store for mocking setStatus()/getStatus(). | |||
MigrateTestCase::createSchemaFromRow | protected | function | Generates a table schema from a row. | |||
MigrateTestCase::getDatabase | protected | function | Gets an SQLite database connection object for use in tests. | |||
MigrateTestCase::getValue | protected | function | Gets the value on a row for a given key. | 1 | ||
MigrateTestCase::queryResultTest | public | function | Tests a query. | |||
MigrateTestCase::retrievalAssertHelper | protected | function | Asserts tested values during test retrieval. | |||
MigrationLookupTestCase::$migrateLookup | protected | property | The prophecy of the migrate lookup service. | |||
MigrationLookupTestCase::$migrateStub | protected | property | The prophecy of the migrate stub service. | |||
MigrationLookupTestCase::prepareContainer | protected | function | Prepares and sets the container. | |||
MigrationTest::$migration_plugin | protected | property | ||||
MigrationTest::$migration_plugin_manager | protected | property | ||||
MigrationTest::$process_plugin_manager | protected | property | ||||
MigrationTest::getMigration | protected | function | Creates a mock Migration instance. | Overrides MigrateTestCase::getMigration | ||
MigrationTest::setUp | protected | function | Overrides MigrationLookupTestCase::setUp | |||
MigrationTest::successfulLookupDataProvider | public | function | Provides data for the successful lookup test. | |||
MigrationTest::testSkipOnEmpty | public | function | Tests that processing is skipped when the input value is empty. | |||
MigrationTest::testSuccessfulLookup | public | function | Tests a successful lookup. | |||
MigrationTest::testTransformWithStubbing | public | function | Tests a lookup with stubbing. | |||
MigrationTest::testTransformWithStubSkipping | public | function | Tests a lookup with no stubbing. | |||
PhpunitCompatibilityTrait::getMock | Deprecated | public | function | Returns a mock object for the specified class using the available method. | ||
PhpunitCompatibilityTrait::setExpectedException | Deprecated | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | ||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | protected | function | Asserts if two arrays are equal by sorting them first. | |||
UnitTestCase::getBlockMockWithMachineName | Deprecated | protected | function | Mocks a block with a block plugin. | 1 | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.