/** * Test that the cache factory picks the correct per-bin service. * * @covers ::__construct * @covers ::get */ public function testCacheFactoryWithSpecifiedPerBinBackend() { $settings = new Settings(array('cache' => array('bins' => array('render' => 'cache.backend.custom')))); $cache_factory = new CacheFactory($settings); $container = new ContainerBuilder(); $cache_factory->setContainer($container); $custom_render_backend_factory = $this->getMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface'); $container->set('cache.backend.custom', $custom_render_backend_factory); $render_bin = $this->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface'); $custom_render_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); }
/** * Test that the cache factory picks the correct per-bin service. * * @covers ::__construct * @covers ::get */ public function testCacheFactoryWithSpecifiedPerBinBackend() { // Ensure the per-bin configuration is used before the configured default // and per-bin defaults. $settings = new Settings(array('cache' => array('default' => 'cache.backend.unused', 'bins' => array('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->getMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface'); $container->set('cache.backend.custom', $custom_render_backend_factory); $render_bin = $this->getMock('\\Drupal\\Core\\Cache\\CacheBackendInterface'); $custom_render_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); }
/** * Overrides Symfony\Component\HttpKernel\Bundle\Bundle::build(). */ public function build(ContainerBuilder $container) { CacheFactory::registerBin($container, 'admin_menu'); }