CachedStorageTest.php

Same filename in this branch
  1. 9 core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php
Same filename in other branches
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php
  3. 10 core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php
  4. 10 core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php
  5. 11.x core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php
  6. 11.x core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php

Namespace

Drupal\Tests\Core\Config

File

core/tests/Drupal/Tests/Core/Config/CachedStorageTest.php

View source
<?php

namespace Drupal\Tests\Core\Config;

use Drupal\Tests\UnitTestCase;
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Cache\NullBackend;

/**
 * Tests the interaction of cache and file storage in CachedStorage.
 *
 * @group Config
 */
class CachedStorageTest extends UnitTestCase {
    
    /**
     * @var \Drupal\Core\Cache\CacheFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $cacheFactory;
    
    /**
     * Tests listAll static cache.
     */
    public function testListAllStaticCache() {
        $prefix = __FUNCTION__;
        $storage = $this->createMock('Drupal\\Core\\Config\\StorageInterface');
        $response = [
            "{$prefix}." . $this->randomMachineName(),
            "{$prefix}." . $this->randomMachineName(),
        ];
        $storage->expects($this->once())
            ->method('listAll')
            ->with($prefix)
            ->willReturn($response);
        $cache = new NullBackend(__FUNCTION__);
        $cachedStorage = new CachedStorage($storage, $cache);
        $this->assertEquals($response, $cachedStorage->listAll($prefix));
        $this->assertEquals($response, $cachedStorage->listAll($prefix));
    }

}

Classes

Title Deprecated Summary
CachedStorageTest Tests the interaction of cache and file storage in CachedStorage.

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