class DrupalCacheAdapterTest in Flysystem 2.0.x
Same name and namespace in other branches
- 8 tests/src/Unit/Flysystem/Adapter/DrupalCacheAdapterTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\DrupalCacheAdapterTest
- 3.x tests/src/Unit/Flysystem/Adapter/DrupalCacheAdapterTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\DrupalCacheAdapterTest
- 3.0.x tests/src/Unit/Flysystem/Adapter/DrupalCacheAdapterTest.php \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\DrupalCacheAdapterTest
Test the Drupal Cache Adapter.
@group flysystem
@coversDefaultClass \Drupal\flysystem\Flysystem\Adapter\DrupalCacheAdapter @covers \Drupal\flysystem\Flysystem\Adapter\DrupalCacheAdapter
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings- class \Drupal\Tests\flysystem\Unit\Flysystem\Adapter\DrupalCacheAdapterTest
 
Expanded class hierarchy of DrupalCacheAdapterTest
File
- tests/src/ Unit/ Flysystem/ Adapter/ DrupalCacheAdapterTest.php, line 20 
Namespace
Drupal\Tests\flysystem\Unit\Flysystem\AdapterView source
class DrupalCacheAdapterTest extends UnitTestCase {
  /**
   * URI scheme to use for testing.
   *
   * @var string
   */
  const SCHEME = 'test-scheme';
  /**
   * The main test file.
   *
   * @var string
   */
  const FILE = 'test.txt';
  /**
   * The wrapped Flysytem adaper.
   *
   * @var \League\Flysystem\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
   */
  protected $adapter;
  /**
   * The cache adapter under test.
   *
   * @var \Drupal\flysystem\Flysystem\Adapter\DrupalCacheAdapter
   */
  protected $cacheAdapter;
  /**
   * The flysystem backend for testing.
   *
   * @var \Drupal\flysystem\Flysystem\Adapter\CacheItemBackend
   */
  protected $cacheItemBackend;
  /**
   * {@inheritdoc}
   */
  public function setup() {
    $this->cacheItemBackend = new CacheItemBackend(static::SCHEME, new MemoryBackend('foo'));
    $this->adapter = $this
      ->prophesize(AdapterInterface::class);
    $this->cacheAdapter = new DrupalCacheAdapter(static::SCHEME, $this->adapter
      ->reveal(), $this->cacheItemBackend);
  }
  public function testWriteSuccess() {
    $config = new Config();
    $this->adapter
      ->write(static::FILE, 'contents', $config)
      ->willReturn([
      'visibility' => 'public',
    ]);
    $metadata = $this->cacheAdapter
      ->write(static::FILE, 'contents', $config);
    $this
      ->assertSame('public', $metadata['visibility']);
    $this
      ->assertSame('public', $this->cacheAdapter
      ->getVisibility(static::FILE)['visibility']);
    $this
      ->assertTrue($this->cacheItemBackend
      ->has(static::FILE));
  }
  public function testWriteStreamSuccess() {
    $config = new Config();
    $stream = fopen('data:text/plain,contents', 'rb');
    $this->adapter
      ->writeStream(static::FILE, $stream, $config)
      ->willReturn([
      'timestamp' => 12345,
    ]);
    $metadata = $this->cacheAdapter
      ->writeStream(static::FILE, $stream, $config);
    $this
      ->assertSame(12345, $metadata['timestamp']);
    $this
      ->assertSame(12345, $this->cacheAdapter
      ->getTimestamp(static::FILE)['timestamp']);
    $this
      ->assertTrue($this->cacheItemBackend
      ->has(static::FILE));
  }
  public function testUpdateSuccess() {
    $config = new Config();
    $this->adapter
      ->update(static::FILE, 'contents', $config)
      ->willReturn([
      'visibility' => 'public',
    ]);
    $metadata = $this->cacheAdapter
      ->update(static::FILE, 'contents', $config);
    $this
      ->assertSame('public', $metadata['visibility']);
    $this
      ->assertSame('public', $this->cacheAdapter
      ->getVisibility(static::FILE)['visibility']);
  }
  public function testUpdateStreamSuccess() {
    $config = new Config();
    $stream = fopen('data:text/plain,contents', 'rb');
    $this->adapter
      ->updateStream(static::FILE, $stream, $config)
      ->willReturn([
      'mimetype' => 'test_mimetype',
    ]);
    $metadata = $this->cacheAdapter
      ->updateStream(static::FILE, $stream, $config);
    $this
      ->assertSame('test_mimetype', $metadata['mimetype']);
    $this
      ->assertSame('test_mimetype', $this->cacheAdapter
      ->getMimetype(static::FILE)['mimetype']);
    $this
      ->assertTrue($this->cacheItemBackend
      ->has(static::FILE));
  }
  public function testRenameSuccess() {
    $config = new Config();
    $this->adapter
      ->write(static::FILE, 'contents', $config)
      ->willReturn([
      'size' => 1234,
    ]);
    $this->cacheAdapter
      ->write(static::FILE, 'contents', $config);
    $this->adapter
      ->rename(static::FILE, 'new.txt')
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->rename(static::FILE, 'new.txt'));
    $this
      ->assertSame(1234, $this->cacheAdapter
      ->getSize('new.txt')['size']);
    $this
      ->assertFalse($this->cacheItemBackend
      ->has(static::FILE));
    $this
      ->assertTrue($this->cacheItemBackend
      ->has('new.txt'));
  }
  public function testCopySuccess() {
    $config = new Config();
    $this->adapter
      ->write(static::FILE, 'contents', $config)
      ->willReturn([
      'size' => 1234,
    ]);
    $this->cacheAdapter
      ->write(static::FILE, 'contents', $config);
    $this->adapter
      ->copy(static::FILE, 'new.txt')
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->copy(static::FILE, 'new.txt'));
    $this
      ->assertSame(1234, $this->cacheAdapter
      ->getSize(static::FILE)['size']);
    $this
      ->assertSame(1234, $this->cacheAdapter
      ->getSize('new.txt')['size']);
    $this
      ->assertTrue($this->cacheItemBackend
      ->has(static::FILE));
    $this
      ->assertTrue($this->cacheItemBackend
      ->has('new.txt'));
  }
  public function testDeleteSuccess() {
    $config = new Config();
    $this->adapter
      ->write(static::FILE, 'contents', $config)
      ->willReturn([
      'size' => 1234,
    ]);
    $this->cacheAdapter
      ->write(static::FILE, 'contents', $config);
    $this->adapter
      ->delete(static::FILE)
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->delete(static::FILE));
    $this
      ->assertFalse($this->cacheItemBackend
      ->has(static::FILE));
  }
  public function testDeleteDirSuccess() {
    $config = new Config();
    // Create a directory with one sub file.
    $this->adapter
      ->createDir('testdir', $config)
      ->willReturn([
      'type' => 'dir',
    ]);
    $this->adapter
      ->write('testdir/test.txt', 'contents', $config)
      ->willReturn([
      'size' => 1234,
    ]);
    $this->adapter
      ->deleteDir('testdir')
      ->willReturn(TRUE);
    $this->adapter
      ->listContents('testdir', TRUE)
      ->willReturn([
      [
        'path' => 'testdir',
      ],
      [
        'path' => 'testdir/test.txt',
      ],
    ]);
    $this->cacheAdapter
      ->createDir('testdir', $config);
    $this->cacheAdapter
      ->write('testdir/test.txt', 'contents', $config);
    $this
      ->assertTrue($this->cacheAdapter
      ->deleteDir('testdir'));
    $this
      ->assertFalse($this->cacheItemBackend
      ->has('testdir/test.txt'));
    $this
      ->assertFalse($this->cacheItemBackend
      ->has('testdir'));
  }
  public function testSetVisibilitySuccess() {
    $config = new Config();
    $this->adapter
      ->setVisibility(static::FILE, 'private')
      ->willReturn([
      'visibility' => 'private',
    ]);
    $metadata = $this->cacheAdapter
      ->setVisibility(static::FILE, 'private');
    $this
      ->assertSame('private', $metadata['visibility']);
    $this
      ->assertSame('private', $this->cacheAdapter
      ->getVisibility(static::FILE)['visibility']);
    $this
      ->assertTrue($this->cacheItemBackend
      ->has(static::FILE));
  }
  public function testHasSuccess() {
    $cache_item = $this->cacheItemBackend
      ->load(static::FILE);
    $this->cacheItemBackend
      ->set(static::FILE, $cache_item);
    $this
      ->assertTrue($this->cacheAdapter
      ->has(static::FILE));
  }
  public function testHasFail() {
    $this->adapter
      ->has(static::FILE)
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->has(static::FILE));
  }
  public function testRead() {
    $this->adapter
      ->read(static::FILE)
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->read(static::FILE));
  }
  public function testReadStream() {
    $this->adapter
      ->readStream(static::FILE)
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->readStream(static::FILE));
  }
  public function testListContentsSuccess() {
    $this->adapter
      ->listContents('testdir', TRUE)
      ->willReturn(TRUE);
    $this
      ->assertTrue($this->cacheAdapter
      ->listContents('testdir', TRUE));
  }
  public function testGetMetadataSuccess() {
    $cache_item = $this->cacheItemBackend
      ->load(static::FILE);
    $cache_item
      ->updateMetadata([
      'type' => 'dir',
    ]);
    $this->cacheItemBackend
      ->set(static::FILE, $cache_item);
    $this
      ->assertSame('dir', $this->cacheAdapter
      ->getMetadata(static::FILE)['type']);
  }
  public function testGetMetadataFail() {
    $this->adapter
      ->getMetadata(static::FILE)
      ->willReturn([
      'type' => 'dir',
    ]);
    $this
      ->assertSame('dir', $this->cacheAdapter
      ->getMetadata(static::FILE)['type']);
  }
  public function testGetSizeFail() {
    $this->adapter
      ->getSize(static::FILE)
      ->willReturn([
      'size' => 123,
    ]);
    $this
      ->assertSame(123, $this->cacheAdapter
      ->getSize(static::FILE)['size']);
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| DrupalCacheAdapterTest:: | protected | property | The wrapped Flysytem adaper. | |
| DrupalCacheAdapterTest:: | protected | property | The cache adapter under test. | |
| DrupalCacheAdapterTest:: | protected | property | The flysystem backend for testing. | |
| DrupalCacheAdapterTest:: | constant | The main test file. | ||
| DrupalCacheAdapterTest:: | constant | URI scheme to use for testing. | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| DrupalCacheAdapterTest:: | public | function | ||
| PhpUnitWarnings:: | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
| PhpUnitWarnings:: | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
| 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 | 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 | 308 | |
| UnitTestCase:: | public static | function | 
