function MigrationSourceCacheTest::testCacheCountsUsed
Same name in other branches
- 10 core/modules/migrate/tests/src/Kernel/Plugin/source/MigrationSourceCacheTest.php \Drupal\Tests\migrate\Kernel\Plugin\source\MigrationSourceCacheTest::testCacheCountsUsed()
- 11.x core/modules/migrate/tests/src/Kernel/Plugin/source/MigrationSourceCacheTest.php \Drupal\Tests\migrate\Kernel\Plugin\source\MigrationSourceCacheTest::testCacheCountsUsed()
Test that values are pulled from the cache when appropriate.
File
-
core/
modules/ migrate/ tests/ src/ Kernel/ Plugin/ source/ MigrationSourceCacheTest.php, line 93
Class
- MigrationSourceCacheTest
- Test source counts are correctly cached.
Namespace
Drupal\Tests\migrate\Kernel\Plugin\sourceCode
public function testCacheCountsUsed() {
$migration_definition = [
'source' => [
'plugin' => 'cacheable_embedded_data',
'cache_counts' => TRUE,
'ids' => [
'id' => [
'type' => 'integer',
],
],
'data_rows' => [
[
'id' => 1,
],
[
'id' => 2,
],
],
],
];
$migration = $this->migrationPluginManager
->createStubMigration($migration_definition);
$migration_source = $migration->getSourcePlugin();
$this->assertSame(2, $migration_source->count());
// Pollute the cache.
$cache_key_property = new \ReflectionProperty($migration_source, 'cacheKey');
$cache_key_property->setAccessible(TRUE);
$cache_key = $cache_key_property->getValue($migration_source);
\Drupal::cache('migrate')->set($cache_key, 7);
$this->assertSame(7, $migration_source->count());
$this->assertSame(2, $migration_source->count(TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.