function CacheFactoryTest::testCacheFactoryWithSpecifiedPerBinBackend

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithSpecifiedPerBinBackend()
  2. 10 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithSpecifiedPerBinBackend()
  3. 11.x core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest::testCacheFactoryWithSpecifiedPerBinBackend()

Tests that the cache factory picks the correct per-bin service.

@covers ::__construct @covers ::get

File

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

Class

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

Namespace

Drupal\Tests\Core\Cache

Code

public function testCacheFactoryWithSpecifiedPerBinBackend() {
    // Ensure the per-bin configuration is used before the configured default
    // and per-bin defaults.
    $settings = new Settings([
        'cache' => [
            'default' => 'cache.backend.unused',
            'bins' => [
                'render' => 'cache.backend.custom',
            ],
        ],
    ]);
    $default_bin_backends = [
        'render' => 'cache.backend.unused',
    ];
    $cache_factory = new CacheFactory($settings, $default_bin_backends);
    $container = new ContainerBuilder();
    $cache_factory->setContainer($container);
    $custom_render_backend_factory = $this->createMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface');
    $container->set('cache.backend.custom', $custom_render_backend_factory);
    $render_bin = $this->createMock('\\Drupal\\Core\\Cache\\CacheBackendInterface');
    $custom_render_backend_factory->expects($this->once())
        ->method('get')
        ->with('render')
        ->willReturn($render_bin);
    $actual_bin = $cache_factory->get('render');
    $this->assertSame($render_bin, $actual_bin);
}

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