Commit 744a7ba0 authored by alexpott's avatar alexpott

Issue #2484131 by phenaproxima, neclimdul, mikeryan: Migration process plugin...

Issue #2484131 by phenaproxima, neclimdul, mikeryan: Migration process plugin should log exceptions encountered during stubbing
parent c7f34bdc
......@@ -10,10 +10,8 @@
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateSkipProcessException;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\Plugin\MigrateIdMapInterface;
use Drupal\migrate\Plugin\MigratePluginManager;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Entity\MigrationInterface;
......@@ -133,7 +131,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
try {
$destination_ids = $destination_plugin->import($stub_row);
}
catch (MigrateException $e) {
catch (\Exception $e) {
$migrate_executable->saveMessage($e->getMessage());
}
}
if ($destination_ids) {
......
......@@ -20,7 +20,7 @@ abstract class MigrateTestCase extends UnitTestCase {
/**
* Retrieve a mocked migration.
*
* @return \Drupal\migrate\Entity\MigrationInterface
* @return \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
* The mocked migration.
*/
protected function getMigration() {
......
......@@ -22,7 +22,7 @@ abstract class MigrateProcessTestCase extends MigrateTestCase {
protected $row;
/**
* @var \Drupal\migrate\MigrateExecutable
* @var \Drupal\migrate\MigrateExecutable|\PHPUnit_Framework_MockObject_MockObject
*/
protected $migrateExecutable;
......
<?php
/**
* @file
* Contains \Drupal\Tests\migrate\Unit\process\MigrationTest.
*/
namespace Drupal\Tests\migrate\Unit\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\process\Migration;
/**
* Tests the migration process plugin.
*
* @coversDefaultClass \Drupal\migrate\Plugin\migrate\process\Migration
* @group migrate
*/
class MigrationTest extends MigrateProcessTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->migrationConfiguration = [
'id' => 'test',
'process' => [],
'source' => [],
];
parent::setUp();
}
/**
* Assert that exceptions during import are logged.
* @expectedException \Drupal\migrate\MigrateSkipRowException
* @covers ::transform
*/
public function testSaveOnException() {
// A bunch of mock objects to get thing working
$migration = $this->getMigration();
$migration_source = $this->getMock('\Drupal\migrate\Plugin\MigrateSourceInterface');
$migration_source->expects($this->once())
->method('getIds')
->willReturn([]);
$migration->expects($this->once())
->method('getSourcePlugin')
->willReturn($migration_source);
$migration_destination = $this->getMock('\Drupal\migrate\Plugin\MigrateDestinationInterface');
$migration->expects($this->once())
->method('getDestinationPlugin')
->willReturn($migration_destination);
$storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$storage->expects($this->once())
->method('loadMultiple')
->willReturn([
'id' => $migration
]);
$manager = $this->getMockBuilder('\Drupal\migrate\Plugin\MigratePluginManager')
->disableOriginalConstructor()
->getMock();
// Throw an exception during import so we can log it.
$migration_destination->expects($this->once())
->method('import')
->willThrowException(new MigrateException());
// Build our migration plugin.
$plugin = new Migration(['migration' => []],
'migration', // ?
[],
$migration,
$storage,
$manager);
// Assert that we log exceptions thrown during the import.
$this->migrateExecutable->expects($this->once())
->method('saveMessage');
$plugin->transform('value', $this->migrateExecutable, $this->row, 'prop');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment