You are here

public function CacheFactoryTest::testCacheFactoryWithCustomizedDefaultBackend in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithCustomizedDefaultBackend()

Test that the cache factory falls back to customized default service.

@covers ::__construct @covers ::get

File

core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php, line 53
Contains \Drupal\Tests\Core\Cache\CacheFactoryTest.

Class

CacheFactoryTest
@coversDefaultClass \Drupal\Core\Cache\CacheFactory @group Cache

Namespace

Drupal\Tests\Core\Cache

Code

public function testCacheFactoryWithCustomizedDefaultBackend() {
  $settings = new Settings(array(
    'cache' => array(
      'default' => 'cache.backend.custom',
    ),
  ));
  $cache_factory = new CacheFactory($settings);
  $container = new ContainerBuilder();
  $cache_factory
    ->setContainer($container);
  $custom_default_backend_factory = $this
    ->getMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface');
  $container
    ->set('cache.backend.custom', $custom_default_backend_factory);
  $render_bin = $this
    ->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
  $custom_default_backend_factory
    ->expects($this
    ->once())
    ->method('get')
    ->with('render')
    ->will($this
    ->returnValue($render_bin));
  $actual_bin = $cache_factory
    ->get('render');
  $this
    ->assertSame($render_bin, $actual_bin);
}