class MigrationTest in Drupal 8
Same name in this branch
- 8 core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 8 core/modules/migrate/tests/src/Kernel/MigrationTest.php \Drupal\Tests\migrate\Kernel\MigrationTest
- 8 core/modules/migrate/tests/src/Unit/process/MigrationTest.php \Drupal\Tests\migrate\Unit\process\MigrationTest
- 8 core/modules/migrate/tests/src/Kernel/Plugin/MigrationTest.php \Drupal\Tests\migrate\Kernel\Plugin\MigrationTest
Same name and namespace in other branches
- 9 core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
- 10 core/modules/migrate/tests/src/Unit/MigrationTest.php \Drupal\Tests\migrate\Unit\MigrationTest
@coversDefaultClass \Drupal\migrate\Plugin\Migration
@group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\migrate\Unit\MigrationTest
Expanded class hierarchy of MigrationTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrationTest.php, line 25 - Contains \Drupal\Tests\migrate\Unit\MigrationTest.
Namespace
Drupal\Tests\migrate\UnitView source
class MigrationTest extends UnitTestCase {
/**
* Tests checking requirements for source plugins.
*
* @covers ::checkRequirements
*/
public function testRequirementsForSourcePlugin() {
$migration = new TestMigration();
$source_plugin = $this
->createMock('Drupal\\Tests\\migrate\\Unit\\RequirementsAwareSourceInterface');
$source_plugin
->expects($this
->once())
->method('checkRequirements')
->willThrowException(new RequirementsException('Missing source requirement', [
'key' => 'value',
]));
$destination_plugin = $this
->createMock('Drupal\\Tests\\migrate\\Unit\\RequirementsAwareDestinationInterface');
$migration
->setSourcePlugin($source_plugin);
$migration
->setDestinationPlugin($destination_plugin);
$this
->expectException(RequirementsException::class);
$this
->expectExceptionMessage('Missing source requirement');
$migration
->checkRequirements();
}
/**
* Tests checking requirements for destination plugins.
*
* @covers ::checkRequirements
*/
public function testRequirementsForDestinationPlugin() {
$migration = new TestMigration();
$source_plugin = $this
->createMock('Drupal\\migrate\\Plugin\\MigrateSourceInterface');
$destination_plugin = $this
->createMock('Drupal\\Tests\\migrate\\Unit\\RequirementsAwareDestinationInterface');
$destination_plugin
->expects($this
->once())
->method('checkRequirements')
->willThrowException(new RequirementsException('Missing destination requirement', [
'key' => 'value',
]));
$migration
->setSourcePlugin($source_plugin);
$migration
->setDestinationPlugin($destination_plugin);
$this
->expectException(RequirementsException::class);
$this
->expectExceptionMessage('Missing destination requirement');
$migration
->checkRequirements();
}
/**
* Tests checking requirements for destination plugins.
*
* @covers ::checkRequirements
*/
public function testRequirementsForMigrations() {
$migration = new TestMigration();
// Setup source and destination plugins without any requirements.
$source_plugin = $this
->createMock('Drupal\\migrate\\Plugin\\MigrateSourceInterface');
$destination_plugin = $this
->createMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
$migration
->setSourcePlugin($source_plugin);
$migration
->setDestinationPlugin($destination_plugin);
$plugin_manager = $this
->createMock('Drupal\\migrate\\Plugin\\MigrationPluginManagerInterface');
$migration
->setMigrationPluginManager($plugin_manager);
// We setup the requirements that test_a doesn't exist and test_c is not
// completed yet.
$migration
->setRequirements([
'test_a',
'test_b',
'test_c',
'test_d',
]);
$migration_b = $this
->createMock(MigrationInterface::class);
$migration_c = $this
->createMock(MigrationInterface::class);
$migration_d = $this
->createMock(MigrationInterface::class);
$migration_b
->expects($this
->once())
->method('allRowsProcessed')
->willReturn(TRUE);
$migration_c
->expects($this
->once())
->method('allRowsProcessed')
->willReturn(FALSE);
$migration_d
->expects($this
->once())
->method('allRowsProcessed')
->willReturn(TRUE);
$plugin_manager
->expects($this
->once())
->method('createInstances')
->with([
'test_a',
'test_b',
'test_c',
'test_d',
])
->willReturn([
'test_b' => $migration_b,
'test_c' => $migration_c,
'test_d' => $migration_d,
]);
$this
->expectException(RequirementsException::class);
$this
->expectExceptionMessage('Missing migrations test_a, test_c');
$migration
->checkRequirements();
}
/**
* Tests valid migration dependencies configuration returns expected values.
*
* @param array|null $source
* The migration dependencies configuration being tested.
* @param array $expected_value
* The migration dependencies configuration array expected.
*
* @covers ::getMigrationDependencies
* @dataProvider getValidMigrationDependenciesProvider
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function testMigrationDependenciesWithValidConfig($source, array $expected_value) {
$migration = new TestMigration();
if (!is_null($source)) {
$migration
->set('migration_dependencies', $source);
}
$this
->assertSame($migration
->getMigrationDependencies(), $expected_value);
}
/**
* Tests that getting migration dependencies fails with invalid configuration.
*
* @covers ::getMigrationDependencies
*/
public function testMigrationDependenciesWithInvalidConfig() {
$migration = new TestMigration();
// Set the plugin ID to test the returned message.
$plugin_id = 'test_migration';
$migration
->setPluginId($plugin_id);
// Migration dependencies expects ['optional' => []] or ['required' => []]].
$migration
->set('migration_dependencies', [
'test_migration_dependency',
]);
$this
->expectException(InvalidPluginDefinitionException::class);
$this
->expectExceptionMessage("Invalid migration dependencies configuration for migration {$plugin_id}");
$migration
->getMigrationDependencies();
}
/**
* Provides data for valid migration configuration test.
*/
public function getValidMigrationDependenciesProvider() {
return [
[
'source' => NULL,
'expected_value' => [
'required' => [],
'optional' => [],
],
],
[
'source' => [],
'expected_value' => [
'required' => [],
'optional' => [],
],
],
[
'source' => [
'required' => [
'test_migration',
],
],
'expected_value' => [
'required' => [
'test_migration',
],
'optional' => [],
],
],
[
'source' => [
'optional' => [
'test_migration',
],
],
'expected_value' => [
'optional' => [
'test_migration',
],
'required' => [],
],
],
[
'source' => [
'required' => [
'req_test_migration',
],
'optional' => [
'opt_test_migration',
],
],
'expected_value' => [
'required' => [
'req_test_migration',
],
'optional' => [
'opt_test_migration',
],
],
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrationTest:: |
public | function | Provides data for valid migration configuration test. | |
MigrationTest:: |
public | function | Tests that getting migration dependencies fails with invalid configuration. | |
MigrationTest:: |
public | function | Tests valid migration dependencies configuration returns expected values. | |
MigrationTest:: |
public | function | Tests checking requirements for destination plugins. | |
MigrationTest:: |
public | function | Tests checking requirements for destination plugins. | |
MigrationTest:: |
public | function | Tests checking requirements for source plugins. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |