function MigrateSourceTest::testPrepareRowPrepareException
Same name in other branches
- 9 core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowPrepareException()
- 10 core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowPrepareException()
- 11.x core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowPrepareException()
Test that a skip exception during prepare hooks correctly skips.
@covers ::prepareRow
File
-
core/
modules/ migrate/ tests/ src/ Unit/ MigrateSourceTest.php, line 388
Class
- MigrateSourceTest
- @coversDefaultClass \Drupal\migrate\Plugin\migrate\source\SourcePluginBase @group migrate
Namespace
Drupal\Tests\migrate\UnitCode
public function testPrepareRowPrepareException() {
$this->migrationConfiguration['id'] = 'test_migration';
$migration = $this->getMigration();
$source = new StubSourcePlugin([], '', [], $migration);
$row = new Row();
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
// Return a failure from a prepare row hook.
$module_handler->invokeAll('migrate_prepare_row', [
$row,
$source,
$migration,
])
->willReturn([
TRUE,
TRUE,
])
->shouldBeCalled();
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [
$row,
$source,
$migration,
])
->willThrow(new MigrateSkipRowException())
->shouldBeCalled();
$source->setModuleHandler($module_handler->reveal());
// This will only be called on the first prepare because the second
// explicitly avoids it.
$this->idMap
->expects($this->once())
->method('saveIdMapping')
->with($row, [], MigrateIdMapInterface::STATUS_IGNORED);
$this->assertFalse($source->prepareRow($row));
// Throw an exception the second time that avoids mapping.
$e = new MigrateSkipRowException('', FALSE);
$module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [
$row,
$source,
$migration,
])
->willThrow($e)
->shouldBeCalled();
$this->assertFalse($source->prepareRow($row));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.