function MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException()
  2. 8.9.x core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException()
  3. 10 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException()

Tests the import method with a thrown MigrateException.

The MigrationException in this case is being thrown from a process plugin.

File

core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php, line 200

Class

MigrateExecutableTest
@coversDefaultClass \Drupal\migrate\MigrateExecutable @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testImportWithValidRowWithProcesMigrateException() : void {
    $exception_message = $this->getRandomGenerator()
        ->string();
    $source = $this->getMockSource();
    $row = $this->getMockBuilder('Drupal\\migrate\\Row')
        ->disableOriginalConstructor()
        ->getMock();
    $row->expects($this->once())
        ->method('getSourceIdValues')
        ->willReturn([
        'id' => 'test',
    ]);
    $source->expects($this->once())
        ->method('current')
        ->willReturn($row);
    $this->executable
        ->setSource($source);
    $this->migration
        ->expects($this->once())
        ->method('getProcessPlugins')
        ->willThrowException(new MigrateException($exception_message));
    $destination = $this->createMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
    $destination->expects($this->never())
        ->method('import');
    $this->migration
        ->method('getDestinationPlugin')
        ->willReturn($destination);
    $this->idMap
        ->expects($this->once())
        ->method('saveIdMapping')
        ->with($row, [], MigrateIdMapInterface::STATUS_FAILED, NULL);
    $this->idMap
        ->expects($this->once())
        ->method('saveMessage');
    $this->idMap
        ->expects($this->never())
        ->method('lookupDestinationIds');
    $this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable
        ->import());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.