class CacheFactoryTest in Drupal 8
Same name and namespace in other branches
- 9 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest
- 10 core/tests/Drupal/Tests/Core/Cache/CacheFactoryTest.php \Drupal\Tests\Core\Cache\CacheFactoryTest
@coversDefaultClass \Drupal\Core\Cache\CacheFactory @group Cache
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\Core\Cache\CacheFactoryTest
Expanded class hierarchy of CacheFactoryTest
File
- core/
tests/ Drupal/ Tests/ Core/ Cache/ CacheFactoryTest.php, line 14
Namespace
Drupal\Tests\Core\CacheView source
class CacheFactoryTest extends UnitTestCase {
/**
* Test that the cache factory falls back to the built-in default service.
*
* @covers ::__construct
* @covers ::get
*/
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);
}
/**
* Test that the cache factory falls back to customized default service.
*
* @covers ::__construct
* @covers ::get
*/
public function testCacheFactoryWithCustomizedDefaultBackend() {
$settings = new Settings([
'cache' => [
'default' => 'cache.backend.custom',
],
]);
$cache_factory = new CacheFactory($settings);
$container = new ContainerBuilder();
$cache_factory
->setContainer($container);
$custom_default_backend_factory = $this
->createMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface');
$container
->set('cache.backend.custom', $custom_default_backend_factory);
$render_bin = $this
->createMock('\\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);
}
/**
* Test that the cache factory uses the correct default bin backend.
*
* @covers ::__construct
* @covers ::get
*/
public function testCacheFactoryWithDefaultBinBackend() {
// Ensure the default bin backends are used before the configured default.
$settings = new Settings([
'cache' => [
'default' => 'cache.backend.unused',
],
]);
$default_bin_backends = [
'render' => 'cache.backend.custom',
];
$cache_factory = new CacheFactory($settings, $default_bin_backends);
$container = new ContainerBuilder();
$cache_factory
->setContainer($container);
$custom_default_backend_factory = $this
->createMock('\\Drupal\\Core\\Cache\\CacheFactoryInterface');
$container
->set('cache.backend.custom', $custom_default_backend_factory);
$render_bin = $this
->createMock('\\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);
}
/**
* 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([
'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')
->will($this
->returnValue($render_bin));
$actual_bin = $cache_factory
->get('render');
$this
->assertSame($render_bin, $actual_bin);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheFactoryTest:: |
public | function | Test that the cache factory falls back to customized default service. | |
CacheFactoryTest:: |
public | function | Test that the cache factory uses the correct default bin backend. | |
CacheFactoryTest:: |
public | function | Test that the cache factory falls back to the built-in default service. | |
CacheFactoryTest:: |
public | function | Test that the cache factory picks the correct per-bin service. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |