function MigrateSqlIdMapTest::testIterators

Same name in other branches
  1. 8.9.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testIterators()
  2. 10 core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testIterators()
  3. 11.x core/modules/migrate/tests/src/Unit/MigrateSqlIdMapTest.php \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest::testIterators()

Tests all the iterator methods in one swing.

The iterator methods are:

  • Sql::rewind()
  • Sql::next()
  • Sql::valid()
  • Sql::key()
  • Sql::current()

File

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

Class

MigrateSqlIdMapTest
Tests the SQL ID map plugin.

Namespace

Drupal\Tests\migrate\Unit

Code

public function testIterators() {
    for ($i = 0; $i < 3; $i++) {
        $row = $this->idMapDefaults();
        $row['sourceid1'] = "source_id_value_{$i}";
        $row['source_ids_hash'] = $this->getIdMap()
            ->getSourceIdsHash([
            'source_id_property' => $row['sourceid1'],
        ]);
        $row['destid1'] = "destination_id_value_{$i}";
        $row['source_row_status'] = MigrateIdMapInterface::STATUS_IMPORTED;
        $expected_results[serialize([
            'sourceid1' => $row['sourceid1'],
        ])] = [
            'destid1' => $row['destid1'],
        ];
        $this->saveMap($row);
    }
    $this->assertSame(iterator_to_array($this->getIdMap()), $expected_results);
}

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