You are here

class CacheItemBackendTest in Flysystem 8

Same name and namespace in other branches
  1. 3.x tests/src/Unit/Flysystem/Adapter/CacheItemBackendTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\CacheItemBackendTest
  2. 2.0.x tests/src/Unit/Flysystem/Adapter/CacheItemBackendTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\CacheItemBackendTest
  3. 3.0.x tests/src/Unit/Flysystem/Adapter/CacheItemBackendTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\CacheItemBackendTest

@group flysystem

@coversDefaultClass \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend @covers \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend

Hierarchy

Expanded class hierarchy of CacheItemBackendTest

File

tests/src/Unit/Flysystem/Adapter/CacheItemBackendTest.php, line 16

Namespace

Drupal\Tests\flysystem\Unit\Flysystem\Adapter
View source
class CacheItemBackendTest extends UnitTestCase {

  /**
   * The cache backend used in the CacheItemBackend.
   *
   * @var \Drupal\Core\Cache\CacheBackendInterface
   */
  protected $cacheBackend;

  /**
   * The cache item backend to test.
   *
   * @var \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend
   */
  protected $cacheItemBackend;

  /**
   * {@inheritdoc}
   */
  public function setup() {
    $this->cacheBackend = new MemoryBackend('foo');
    $this->cacheItemBackend = new CacheItemBackend('test-scheme', $this->cacheBackend);
  }

  /**
   * Tests whether a cache item exists.
   */
  public function testHas() {
    $this
      ->assertFalse($this->cacheItemBackend
      ->has('test.txt'));
  }

  /**
   * Tests loading a cache item from the cache.
   */
  public function testSetIsLoaded() {
    $cache_item = new CacheItem();
    $cache_item
      ->updateMetadata([
      'mimetype' => 'test_mimetype',
    ]);
    $this->cacheItemBackend
      ->set('test_path', $cache_item);
    $metadata = $this->cacheItemBackend
      ->load('test_path')
      ->getMetadata();
    $this
      ->assertSame('test_mimetype', $metadata['mimetype']);
  }

  /**
   * Tests when loading a cache item creates a new item.
   */
  public function testLoadMiss() {
    $item = $this->cacheItemBackend
      ->load('test_path');
    $this
      ->assertInstanceOf(CacheItem::class, $item);
  }

  /**
   * Tests deleting by a path.
   */
  public function testDelete() {
    $cache_item = new CacheItem();
    $cache_item
      ->updateMetadata([
      'mimetype' => 'test_mimetype',
    ]);
    $this->cacheItemBackend
      ->set('test_path', $cache_item);
    $this->cacheItemBackend
      ->delete('test_path');
    $metadata = $this->cacheItemBackend
      ->load('test_path')
      ->getMetadata();
    $this
      ->assertTrue(empty($metadata['mimetype']));
  }

  /**
   * Tests deleting multiple items at once.
   */
  public function testDeleteMultiple() {
    $cache_item_one = new CacheItem();
    $cache_item_two = new CacheItem();
    $this->cacheItemBackend
      ->set('one', $cache_item_one);
    $this->cacheItemBackend
      ->set('two', $cache_item_two);
    $this->cacheItemBackend
      ->deleteMultiple([
      'one',
      'two',
    ]);
    $this
      ->assertNotSame($cache_item_one, $this->cacheItemBackend
      ->load('one'));
    $this
      ->assertNotSame($cache_item_two, $this->cacheItemBackend
      ->load('two'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheItemBackendTest::$cacheBackend protected property The cache backend used in the CacheItemBackend.
CacheItemBackendTest::$cacheItemBackend protected property The cache item backend to test.
CacheItemBackendTest::setup public function
CacheItemBackendTest::testDelete public function Tests deleting by a path.
CacheItemBackendTest::testDeleteMultiple public function Tests deleting multiple items at once.
CacheItemBackendTest::testHas public function Tests whether a cache item exists.
CacheItemBackendTest::testLoadMiss public function Tests when loading a cache item creates a new item.
CacheItemBackendTest::testSetIsLoaded public function Tests loading a cache item from the cache.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340