You are here

public function MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithProcesMigrateException()

Tests the import method with a MigrateException being thrown from a process plugin.

File

core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php, line 281
Contains \Drupal\Tests\migrate\Unit\MigrateExecutableTest.

Class

MigrateExecutableTest
@coversDefaultClass \Drupal\Tests\migrate\Unit\MigrateExecutableTest @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testImportWithValidRowWithProcesMigrateException() {
  $exception_message = $this
    ->getRandomGenerator()
    ->string();
  $source = $this
    ->getMockSource();
  $row = $this
    ->getMockBuilder('Drupal\\migrate\\Row')
    ->disableOriginalConstructor()
    ->getMock();
  $row
    ->expects($this
    ->once())
    ->method('getSourceIdValues')
    ->willReturn(array(
    '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
    ->getMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
  $destination
    ->expects($this
    ->never())
    ->method('import');
  $this->migration
    ->expects($this
    ->once())
    ->method('getDestinationPlugin')
    ->willReturn($destination);
  $this->idMap
    ->expects($this
    ->once())
    ->method('saveIdMapping')
    ->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
  $this->idMap
    ->expects($this
    ->once())
    ->method('saveMessage');
  $this->idMap
    ->expects($this
    ->never())
    ->method('lookupDestinationId');
  $this
    ->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable
    ->import());
}