function HighWaterTest::testZeroHighwater

Same name and namespace in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/HighWaterTest.php \Drupal\Tests\migrate\Kernel\HighWaterTest::testZeroHighwater()
  2. 8.9.x core/modules/migrate/tests/src/Kernel/HighWaterTest.php \Drupal\Tests\migrate\Kernel\HighWaterTest::testZeroHighwater()
  3. 11.x core/modules/migrate/tests/src/Kernel/HighWaterTest.php \Drupal\Tests\migrate\Kernel\HighWaterTest::testZeroHighwater()

Tests that the high water value can be 0.

File

core/modules/migrate/tests/src/Kernel/HighWaterTest.php, line 146

Class

HighWaterTest
Tests migration high water property.

Namespace

Drupal\Tests\migrate\Kernel

Code

public function testZeroHighwater() : void {
  // Assert all of the nodes have been imported.
  $this->assertNodeExists('Item 1');
  $this->assertNodeExists('Item 2');
  $this->assertNodeExists('Item 3');
  $migration = $this->container
    ->get('plugin.manager.migration')
    ->CreateInstance('high_water_test', []);
  $source = $migration->getSourcePlugin();
  $source->rewind();
  $count = 0;
  while ($source->valid()) {
    $count++;
    $source->next();
  }
  // Expect no rows as everything is below the high water mark.
  $this->assertSame(0, $count);
  // Test resetting the high water mark to 0.
  $this->container
    ->get('keyvalue')
    ->get('migrate:high_water')
    ->set('high_water_test', 0);
  $migration = $this->container
    ->get('plugin.manager.migration')
    ->CreateInstance('high_water_test', []);
  $source = $migration->getSourcePlugin();
  $source->rewind();
  $count = 0;
  while ($source->valid()) {
    $count++;
    $source->next();
  }
  $this->assertSame(3, $count);
}

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