function MigrateSourceTest::testCountCacheKey

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

Tests that the key can be set for the count cache.

@covers ::count

File

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

Class

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

Namespace

Drupal\Tests\migrate\Unit

Code

public function testCountCacheKey() {
    // Mock the cache to validate set() receives appropriate arguments.
    $container = new ContainerBuilder();
    $cache = $this->createMock(CacheBackendInterface::class);
    $cache->expects($this->any())
        ->method('set')
        ->with('test_key', $this->isType('int'), $this->isType('int'));
    $container->set('cache.migrate', $cache);
    \Drupal::setContainer($container);
    // Test caching the count with a configured key works.
    $source = $this->getSource([
        'cache_counts' => TRUE,
        'cache_key' => 'test_key',
    ]);
    $this->assertEquals(1, $source->count());
}

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