You are here

public function CacheFactoryTest::testCacheFactoryWithDefaultSettings in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithDefaultSettings()
  2. 9 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithDefaultSettings()

Tests that the cache factory falls back to the built-in default service.

@covers ::__construct @covers ::get

File

core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php, line 22

Class

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

Namespace

Drupal\Tests\Core\Cache

Code

public function testCacheFactoryWithDefaultSettings() {
  $settings = new Settings([]);
  $cache_factory = new CacheFactory($settings);
  $container = new ContainerBuilder();
  $cache_factory
    ->setContainer($container);
  $builtin_default_backend_factory = $this
    ->createMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface');
  $container
    ->set('cache.backend.database', $builtin_default_backend_factory);
  $render_bin = $this
    ->createMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
  $builtin_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);
}