public function MigrateExecutableTest::testImportWithValidRowWithException in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate/tests/src/Unit/MigrateExecutableTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableTest::testImportWithValidRowWithException()
Tests the import method with a regular Exception being thrown.
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrateExecutableTest.php, line 334
Class
- MigrateExecutableTest
- @coversDefaultClass \Drupal\migrate\MigrateExecutable @group migrate
Namespace
Drupal\Tests\migrate\UnitCode
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([
'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([]));
$destination = $this
->createMock('Drupal\\migrate\\Plugin\\MigrateDestinationInterface');
$destination
->expects($this
->once())
->method('import')
->with($row, [
'test',
])
->will($this
->throwException(new \Exception($exception_message)));
$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
->once())
->method('lookupDestinationIds')
->with([
'id' => 'test',
])
->will($this
->returnValue([
[
'test',
],
]));
$this->message
->expects($this
->once())
->method('display')
->with($exception_message);
$this
->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable
->import());
}