You are here

protected function MigrateTestBase::mockFailure in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/src/Tests/MigrateTestBase.php \Drupal\migrate\Tests\MigrateTestBase::mockFailure()

Records a failure in the map table of a specific migration in order to test scenarios which require a failed row.

Parameters

string|\Drupal\migrate\Entity\MigrationInterface $migration: The migration entity, or its ID.

array $row: The raw source row which "failed".

int $status: (optional) The failure status. Should be one of the MigrateIdMapInterface::STATUS_* constants.

1 call to MigrateTestBase::mockFailure()
MigrateTermNodeTest::testSkipNonExistentNode in core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTest.php
Tests that term associations are ignored when they belong to nodes which were not migrated.

File

core/modules/migrate/src/Tests/MigrateTestBase.php, line 214
Contains \Drupal\migrate\Tests\MigrateTestBase.

Class

MigrateTestBase
Base class for migration tests.

Namespace

Drupal\migrate\Tests

Code

protected function mockFailure($migration, array $row, $status = MigrateIdMapInterface::STATUS_FAILED) {
  if (is_string($migration)) {
    $migration = Migration::load($migration);
  }

  /** @var \Drupal\migrate\Entity\MigrationInterface $migration */
  $destination = array_map(function () {
    return NULL;
  }, $migration
    ->getDestinationPlugin()
    ->getIds());
  $row = new Row($row, $migration
    ->getSourcePlugin()
    ->getIds());
  $migration
    ->getIdMap()
    ->saveIdMapping($row, $destination, $status);
}