/**
  * Tests the import method with a regular Exception being thrown.
  */
 public function testImportWithValidRowWithException()
 {
     $exception_message = $this->getRandomGenerator()->string();
     $source = $this->getMockSource();
     $row = $this->getMockBuilder('Drupal\\migrate\\Row')->disableOriginalConstructor()->getMock();
     $row->expects($this->once())->method('getSourceIdValues')->will($this->returnValue(array('id' => 'test')));
     $source->expects($this->once())->method('current')->will($this->returnValue($row));
     $this->executable->setSource($source);
     $this->migration->expects($this->once())->method('getProcessPlugins')->will($this->returnValue(array()));
     $destination = $this->getMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
     $destination->expects($this->once())->method('import')->with($row, array('test'))->will($this->throwException(new \Exception($exception_message)));
     $this->migration->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->once())->method('lookupDestinationId')->with(array('id' => 'test'))->will($this->returnValue(array('test')));
     $this->message->expects($this->once())->method('display')->with($exception_message);
     $this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
 }
 /**
  * Gets the source plugin to test.
  *
  * @param array $configuration
  *   (optional) The source configuration. Defaults to an empty array.
  * @param array $migrate_config
  *   (optional) The migration configuration to be used in
  *   parent::getMigration(). Defaults to an empty array.
  * @param int $status
  *   (optional) The default status for the new rows to be imported. Defaults
  *   to MigrateIdMapInterface::STATUS_NEEDS_UPDATE.
  *
  * @return \Drupal\migrate\Plugin\MigrateSourceInterface
  *   A mocked source plugin.
  */
 protected function getSource($configuration = [], $migrate_config = [], $status = MigrateIdMapInterface::STATUS_NEEDS_UPDATE, $high_water_value = NULL)
 {
     $container = new ContainerBuilder();
     \Drupal::setContainer($container);
     $key_value = $this->getMock(KeyValueStoreInterface::class);
     $key_value_factory = $this->getMock(KeyValueFactoryInterface::class);
     $key_value_factory->method('get')->with('migrate:high_water')->willReturn($key_value);
     $container->set('keyvalue', $key_value_factory);
     $container->set('cache.migrate', $this->getMock(CacheBackendInterface::class));
     $this->migrationConfiguration = $this->defaultMigrationConfiguration + $migrate_config;
     $this->migration = parent::getMigration();
     $this->executable = $this->getMigrateExecutable($this->migration);
     // Update the idMap for Source so the default is that the row has already
     // been imported. This allows us to use the highwater mark to decide on the
     // outcome of whether we choose to import the row.
     $id_map_array = ['original_hash' => '', 'hash' => '', 'source_row_status' => $status];
     $this->idMap->expects($this->any())->method('getRowBySource')->willReturn($id_map_array);
     $constructor_args = [$configuration, 'd6_action', [], $this->migration];
     $methods = ['getModuleHandler', 'fields', 'getIds', '__toString', 'prepareRow', 'initializeIterator'];
     $source_plugin = $this->getMock(SourcePluginBase::class, $methods, $constructor_args);
     $source_plugin->method('fields')->willReturn([]);
     $source_plugin->method('getIds')->willReturn([]);
     $source_plugin->method('__toString')->willReturn('');
     $source_plugin->method('prepareRow')->willReturn(empty($migrate_config['prepare_row_false']));
     $rows = [$this->row];
     if (isset($configuration['high_water_property']) && isset($high_water_value)) {
         $property = $configuration['high_water_property']['name'];
         $rows = array_filter($rows, function (array $row) use($property, $high_water_value) {
             return $row[$property] >= $high_water_value;
         });
     }
     $iterator = new \ArrayIterator($rows);
     $source_plugin->method('initializeIterator')->willReturn($iterator);
     $module_handler = $this->getMock(ModuleHandlerInterface::class);
     $source_plugin->method('getModuleHandler')->willReturn($module_handler);
     $this->migration->method('getSourcePlugin')->willReturn($source_plugin);
     return $source_plugin;
 }