class MigrateStubTest in Drupal 9
Same name in this branch
- 9 core/modules/migrate/tests/src/Unit/MigrateStubTest.php \Drupal\Tests\migrate\Unit\MigrateStubTest
- 9 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest
Same name and namespace in other branches
- 8 core/modules/migrate/tests/src/Unit/MigrateStubTest.php \Drupal\Tests\migrate\Unit\MigrateStubTest
Tests the migrate stub service.
@group migrate
@coversDefaultClass \Drupal\migrate\MigrateStub
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\migrate\Unit\MigrateStubTest
Expanded class hierarchy of MigrateStubTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrateStubTest.php, line 23
Namespace
Drupal\Tests\migrate\UnitView source
class MigrateStubTest extends UnitTestCase {
/**
* The plugin manager prophecy.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $migrationPluginManager;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->migrationPluginManager = $this
->prophesize(MigrationPluginManagerInterface::class);
}
/**
* Tests stubbing.
*
* @covers ::createStub
*/
public function testCreateStub() {
$destination_plugin = $this
->prophesize(MigrateDestinationInterface::class);
$destination_plugin
->import(Argument::type(Row::class))
->willReturn([
'id' => 2,
]);
$source_plugin = $this
->prophesize(MigrateSourceInterface::class);
$source_plugin
->getIds()
->willReturn([
'id' => [
'type' => 'integer',
],
]);
$id_map = $this
->prophesize(MigrateIdMapInterface::class);
$migration = $this
->prophesize(MigrationInterface::class);
$migration
->getIdMap()
->willReturn($id_map
->reveal());
$migration
->getDestinationPlugin(TRUE)
->willReturn($destination_plugin
->reveal());
$migration
->getProcessPlugins([])
->willReturn([]);
$migration
->getProcess()
->willReturn([]);
$migration
->getSourceConfiguration()
->willReturn([]);
$migration
->getSourcePlugin()
->willReturn($source_plugin
->reveal());
$this->migrationPluginManager
->createInstances([
'test_migration',
])
->willReturn([
$migration
->reveal(),
]);
$stub = new MigrateStub($this->migrationPluginManager
->reveal());
$this
->assertSame([
'id' => 2,
], $stub
->createStub('test_migration', [
'id' => 1,
], []));
}
/**
* Tests that an error is logged if the plugin manager throws an exception.
*/
public function testExceptionOnPluginNotFound() {
$this->migrationPluginManager
->createInstances([
'test_migration',
])
->willReturn([]);
$this
->expectException(PluginNotFoundException::class);
$this
->expectExceptionMessage("Plugin ID 'test_migration' was not found.");
$stub = new MigrateStub($this->migrationPluginManager
->reveal());
$stub
->createStub('test_migration', [
1,
]);
}
/**
* Tests that an error is logged on derived migrations.
*/
public function testExceptionOnDerivedMigration() {
$this->migrationPluginManager
->createInstances([
'test_migration',
])
->willReturn([
'test_migration:d1' => $this
->prophesize(MigrationInterface::class)
->reveal(),
'test_migration:d2' => $this
->prophesize(MigrationInterface::class)
->reveal(),
]);
$this
->expectException(\LogicException::class);
$this
->expectExceptionMessage('Cannot stub derivable migration "test_migration". You must specify the id of a specific derivative to stub.');
$stub = new MigrateStub($this->migrationPluginManager
->reveal());
$stub
->createStub('test_migration', [
1,
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateStubTest:: |
protected | property | The plugin manager prophecy. | |
MigrateStubTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MigrateStubTest:: |
public | function | Tests stubbing. | |
MigrateStubTest:: |
public | function | Tests that an error is logged on derived migrations. | |
MigrateStubTest:: |
public | function | Tests that an error is logged if the plugin manager throws an exception. | |
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
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 | 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:: |
public static | function |