class MigrateInterruptionTest
Same name and namespace in other branches
- 11.x core/modules/migrate/tests/src/Kernel/MigrateInterruptionTest.php \Drupal\Tests\migrate\Kernel\MigrateInterruptionTest
- 10 core/modules/migrate/tests/src/Kernel/MigrateInterruptionTest.php \Drupal\Tests\migrate\Kernel\MigrateInterruptionTest
- 8.9.x core/modules/migrate/tests/src/Kernel/MigrateInterruptionTest.php \Drupal\Tests\migrate\Kernel\MigrateInterruptionTest
Tests interruptions triggered during migrations.
@group migrate
Hierarchy
- class \Drupal\KernelTests\KernelTestBase implements \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\migrate\Kernel\MigrateInterruptionTest extends \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of MigrateInterruptionTest
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ MigrateInterruptionTest.php, line 16
Namespace
Drupal\Tests\migrate\KernelView source
class MigrateInterruptionTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'migrate',
'migrate_events_test',
];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
\Drupal::service('event_dispatcher')->addListener(MigrateEvents::POST_ROW_SAVE, [
$this,
'postRowSaveEventRecorder',
]);
}
/**
* Tests migration interruptions.
*/
public function testMigrateEvents() {
// Run a simple little migration, which should trigger one of each event
// other than map_delete.
$definition = [
'migration_tags' => [
'Interruption test',
],
'source' => [
'plugin' => 'embedded_data',
'data_rows' => [
[
'data' => 'dummy value',
],
[
'data' => 'dummy value2',
],
],
'ids' => [
'data' => [
'type' => 'string',
],
],
],
'process' => [
'value' => 'data',
],
'destination' => [
'plugin' => 'dummy',
],
];
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
$executable = new MigrateExecutable($migration);
// When the import runs, the first row imported will trigger an
// interruption.
$result = $executable->import();
$this->assertEquals(MigrationInterface::RESULT_INCOMPLETE, $result);
// The status should have been reset to IDLE.
$this->assertEquals(MigrationInterface::STATUS_IDLE, $migration->getStatus());
}
/**
* Reacts to post-row-save event.
*
* @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event
* The migration event.
* @param string $name
* The event name.
*/
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
$event->getMigration()
->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.