function ChainedFastBackendFactoryTest::testIdenticalService

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

Test if the same name is provided for consistent and fast services.

File

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

Class

ChainedFastBackendFactoryTest
@coversDefaultClass \Drupal\Core\Cache\ChainedFastBackendFactory[[api-linebreak]] @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testIdenticalService() : void {
  $container = $this->createMock(ContainerInterface::class);
  $testCacheFactory = $this->createMock(CacheFactoryInterface::class);
  $testCacheBackend = $this->createMock(CacheBackendInterface::class);
  $container->expects($this->once())
    ->method('get')
    ->with('cache.backend.test')
    ->willReturn($testCacheFactory);
  $testCacheFactory->expects($this->once())
    ->method('get')
    ->with('test_bin')
    ->willReturn($testCacheBackend);
  $cacheFactory = new ChainedFastBackendFactory(NULL, 'cache.backend.test', 'cache.backend.test');
  $cacheFactory->setContainer($container);
  $cacheBackend = $cacheFactory->get('test_bin');
  // The test backend should be returned directly.
  $this->assertSame($testCacheBackend, $cacheBackend);
}

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