function MigrationSourceCacheTest::testCacheCountsNotContaminated

Same name in other branches
  1. 9 core/modules/migrate/tests/src/Kernel/Plugin/source/MigrationSourceCacheTest.php \Drupal\Tests\migrate\Kernel\Plugin\source\MigrationSourceCacheTest::testCacheCountsNotContaminated()
  2. 10 core/modules/migrate/tests/src/Kernel/Plugin/source/MigrationSourceCacheTest.php \Drupal\Tests\migrate\Kernel\Plugin\source\MigrationSourceCacheTest::testCacheCountsNotContaminated()

Tests that counts for the same plugin ID are not crossed.

File

core/modules/migrate/tests/src/Kernel/Plugin/source/MigrationSourceCacheTest.php, line 40

Class

MigrationSourceCacheTest
Test source counts are correctly cached.

Namespace

Drupal\Tests\migrate\Kernel\Plugin\source

Code

public function testCacheCountsNotContaminated() : void {
    $migration_1_definition = [
        'source' => [
            'plugin' => 'cacheable_embedded_data',
            'cache_counts' => TRUE,
            'ids' => [
                'id' => [
                    'type' => 'integer',
                ],
            ],
            'data_rows' => [
                [
                    [
                        'id' => 1,
                    ],
                ],
            ],
        ],
    ];
    $migration_2_definition = [
        'source' => [
            'plugin' => 'cacheable_embedded_data',
            'cache_counts' => TRUE,
            'ids' => [
                'id' => [
                    'type' => 'integer',
                ],
            ],
            'data_rows' => [
                [
                    'id' => 1,
                ],
                [
                    'id' => 2,
                ],
            ],
        ],
    ];
    $migration_1 = $this->migrationPluginManager
        ->createStubMigration($migration_1_definition);
    $migration_2 = $this->migrationPluginManager
        ->createStubMigration($migration_2_definition);
    $migration_1_source = $migration_1->getSourcePlugin();
    $migration_2_source = $migration_2->getSourcePlugin();
    // Verify correct counts when count is refreshed.
    $this->assertSame(1, $migration_1_source->count(TRUE));
    $this->assertSame(2, $migration_2_source->count(TRUE));
    // Verify correct counts are cached.
    $this->assertCount(1, $migration_1_source);
    $this->assertCount(2, $migration_2_source);
    // Verify the cache keys are different.
    $cache_key_property = new \ReflectionProperty(SourcePluginBase::class, 'cacheKey');
    $this->assertNotEquals($cache_key_property->getValue($migration_1_source), $cache_key_property->getValue($migration_2_source));
}

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