function MigrateSourceTest::testCount

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

Test that the source count is correct.

@covers ::count

File

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

Class

MigrateSourceTest
@coversDefaultClass \Drupal\migrate\Plugin\migrate\source\SourcePluginBase @group migrate

Namespace

Drupal\Tests\migrate\Unit

Code

public function testCount() {
    // Mock the cache to validate set() receives appropriate arguments.
    $container = new ContainerBuilder();
    $cache = $this->createMock(CacheBackendInterface::class);
    $cache->expects($this->any())
        ->method('set')
        ->with($this->isType('string'), $this->isType('int'), $this->isType('int'));
    $container->set('cache.migrate', $cache);
    \Drupal::setContainer($container);
    // Test that the basic count works.
    $source = $this->getSource();
    $this->assertEquals(1, $source->count());
    // Test caching the count works.
    $source = $this->getSource([
        'cache_counts' => TRUE,
    ]);
    $this->assertEquals(1, $source->count());
    // Test the skip argument.
    $source = $this->getSource([
        'skip_count' => TRUE,
    ]);
    $this->assertEquals(-1, $source->count());
    $this->migrationConfiguration['id'] = 'test_migration';
    $migration = $this->getMigration();
    $source = new StubSourceGeneratorPlugin([], '', [], $migration);
    // Test the skipCount property's default value.
    $this->assertEquals(-1, $source->count());
    // Test the count value using a generator.
    $source = new StubSourceGeneratorPlugin([
        'skip_count' => FALSE,
    ], '', [], $migration);
    $this->assertEquals(3, $source->count());
}

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