function ChainedFastBackendFactoryTest::testDifferentServices

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendFactoryTest.php \Drupal\Tests\Core\Cache\ChainedFastBackendFactoryTest::testDifferentServices()

Test if different names are provided for consistent and fast services.

File

core/tests/Drupal/Tests/Core/Cache/ChainedFastBackendFactoryTest.php, line 50

Class

ChainedFastBackendFactoryTest
@coversDefaultClass \Drupal\Core\Cache\ChainedFastBackendFactory @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testDifferentServices() : void {
    $container = $this->createMock(ContainerInterface::class);
    $testConsistentCacheFactory = $this->createMock(CacheFactoryInterface::class);
    $testFastCacheFactory = $this->createMock(CacheFactoryInterface::class);
    $testConsistentCacheBackend = $this->createMock(CacheBackendInterface::class);
    $testFastCacheBackend = $this->createMock(CacheBackendInterface::class);
    $container->expects($this->exactly(2))
        ->method('get')
        ->willReturnCallback(function ($service) use ($testFastCacheFactory, $testConsistentCacheFactory) {
        return match ($service) {    'cache.backend.test_consistent' => $testConsistentCacheFactory,
            'cache.backend.test_fast' => $testFastCacheFactory,
        
        };
    });
    // The same bin should be retrieved from both backends.
    $testConsistentCacheFactory->expects($this->once())
        ->method('get')
        ->with('test_bin')
        ->willReturn($testConsistentCacheBackend);
    $testFastCacheFactory->expects($this->once())
        ->method('get')
        ->with('test_bin')
        ->willReturn($testFastCacheBackend);
    $cacheFactory = new ChainedFastBackendFactory(NULL, 'cache.backend.test_consistent', 'cache.backend.test_fast');
    $cacheFactory->setContainer($container);
    // A wrapping ChainedFastBackend should be returned.
    $cacheBackend = $cacheFactory->get('test_bin');
    $this->assertInstanceOf(ChainedFastBackend::class, $cacheBackend);
}

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