You are here

public function MigrateSourceTest::testCountCacheKey in Drupal 9

Same name and namespace in other branches
  1. 8 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
Contains \Drupal\Tests\migrate\Unit\MigrateSourceTest.

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());
}