You are here

public function MigrateSqlIdMapTest::testProcessedCount in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testProcessedCount()

Tests the number of processed source rows.

Scenarios to test for:

  • No processed rows.
  • One processed row.
  • Multiple processed rows.

File

core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php, line 750

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testProcessedCount() {
  $id_map = $this
    ->getIdMap();

  // Assert zero rows have been processed before adding rows.
  $this
    ->assertSame(0, $id_map
    ->processedCount());
  $row_statuses = [
    MigrateIdMapInterface::STATUS_IMPORTED,
    MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
    MigrateIdMapInterface::STATUS_IGNORED,
    MigrateIdMapInterface::STATUS_FAILED,
  ];

  // Create a mapping row for each STATUS constant.
  foreach ($row_statuses as $status) {
    $source = [
      'source_id_property' => 'source_value_' . $status,
    ];
    $row = new Row($source, [
      'source_id_property' => [],
    ]);
    $destination = [
      'destination_id_property' => 'destination_value_' . $status,
    ];
    $id_map
      ->saveIdMapping($row, $destination, $status);
    if ($status == MigrateIdMapInterface::STATUS_IMPORTED) {

      // Assert a single row has been processed.
      $this
        ->assertSame(1, $id_map
        ->processedCount());
    }
  }

  // Assert multiple rows have been processed.
  $this
    ->assertSame(count($row_statuses), $id_map
    ->processedCount());
}