MigrateInterruptionTest.php in Drupal 8
File
core/modules/migrate/tests/src/Kernel/MigrateInterruptionTest.php
View source
<?php
namespace Drupal\Tests\migrate\Kernel;
use Drupal\migrate\Event\MigratePostRowSaveEvent;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\MigrateExecutable;
use Drupal\KernelTests\KernelTestBase;
class MigrateInterruptionTest extends KernelTestBase {
public static $modules = [
'migrate',
'migrate_events_test',
];
protected function setUp() {
parent::setUp();
\Drupal::service('event_dispatcher')
->addListener(MigrateEvents::POST_ROW_SAVE, [
$this,
'postRowSaveEventRecorder',
]);
}
public function testMigrateEvents() {
$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);
$result = $executable
->import();
$this
->assertEqual($result, MigrationInterface::RESULT_INCOMPLETE);
$this
->assertEqual($migration
->getStatus(), MigrationInterface::STATUS_IDLE);
}
public function postRowSaveEventRecorder(MigratePostRowSaveEvent $event, $name) {
$event
->getMigration()
->interruptMigration(MigrationInterface::RESULT_INCOMPLETE);
}
}