function MigrateSourceTest::testPrepareRowGlobalPrepareSkip

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowGlobalPrepareSkip()
  2. 8.9.x core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowGlobalPrepareSkip()
  3. 10 core/modules/migrate/tests/src/Unit/MigrateSourceTest.php \Drupal\Tests\migrate\Unit\MigrateSourceTest::testPrepareRowGlobalPrepareSkip()

Tests that global prepare hooks can skip rows.

@covers ::prepareRow

File

core/modules/migrate/tests/src/Unit/MigrateSourceTest.php, line 331

Class

MigrateSourceTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\source\SourcePluginBase[[api-linebreak]] @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testPrepareRowGlobalPrepareSkip() : void {
  $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,
    FALSE,
    TRUE,
  ])
    ->shouldBeCalled();
  $module_handler->invokeAll('migrate_' . $migration->id() . '_prepare_row', [
    $row,
    $source,
    $migration,
  ])
    ->willReturn([
    TRUE,
    TRUE,
  ])
    ->shouldBeCalled();
  $source->setModuleHandler($module_handler->reveal());
  $this->idMap
    ->expects($this->once())
    ->method('saveIdMapping')
    ->with($row, [], MigrateIdMapInterface::STATUS_IGNORED);
  $this->assertFalse($source->prepareRow($row));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.