You are here

class FlysystemBridgeTest in Flysystem 8

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

@coversDefaultClass \Drupal\flysystem\FlysystemBridge @group flysystem

Hierarchy

Expanded class hierarchy of FlysystemBridgeTest

File

tests/src/Unit/FlysystemBridgeTest.php, line 18

Namespace

Drupal\Tests\flysystem\Unit
View source
class FlysystemBridgeTest extends UnitTestCase {

  /**
   * @var \Drupal\flysystem\FlysystemBridge
   */
  protected $bridge;

  /**
   * @var \League\Flysystem\FilesystemInterface
   */
  protected $filesystem;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    $this->bridge = new FlysystemBridge();
    $this->bridge
      ->setStringTranslation($this
      ->getStringTranslationStub());
    $this->bridge
      ->setUri('testscheme://file.txt');
    $factory = $this
      ->prophesize(FlysystemFactory::class);
    $factory
      ->getPlugin('testscheme')
      ->willReturn(new Missing());
    $this->filesystem = new Filesystem(new MissingAdapter());
    $factory
      ->getFilesystem('testscheme')
      ->willReturn($this->filesystem);
    $factory
      ->getSettings('testscheme')
      ->willReturn([
      'name' => '',
      'description' => '',
    ]);
    $container = new ContainerBuilder();
    $container
      ->set('flysystem_factory', $factory
      ->reveal());
    \Drupal::setContainer($container);
  }

  /**
   * @covers ::getType
   */
  public function testGetTypeReturnsWriteVisible() {
    $this
      ->assertSame(StreamWrapperInterface::WRITE_VISIBLE, FlysystemBridge::getType());
  }

  /**
   * @covers ::getName
   */
  public function testGetNameFormattingCorrect() {
    $this
      ->assertSame('Flysystem: testscheme', (string) $this->bridge
      ->getName());
  }

  /**
   * @covers ::getDescription
   */
  public function testGetDescriptionFormattingCorrect() {
    $this
      ->assertSame('Flysystem: testscheme', (string) $this->bridge
      ->getDescription());
  }

  /**
   * @covers ::getUri
   * @covers ::setUri
   */
  public function testGetUriMatchesSetUri() {
    $this->bridge
      ->setUri('beep://boop');
    $this
      ->assertSame('beep://boop', $this->bridge
      ->getUri());
  }

  /**
   * @covers ::getExternalUrl
   * @covers ::getFactory
   */
  public function testGetExternalUrlDelegatesToPlugin() {
    $this
      ->assertSame('', $this->bridge
      ->getExternalUrl('testscheme://testfile.txt'));
  }

  /**
   * @covers ::realpath
   */
  public function testRealpathIsFalse() {
    $this
      ->assertFalse($this->bridge
      ->realpath());
  }

  /**
   * @covers ::dirname
   */
  public function testDirname() {
    $this
      ->assertSame('testscheme://', $this->bridge
      ->dirname());
    $this
      ->assertSame('testscheme://dir://dir', $this->bridge
      ->dirname('testscheme:///dir://dir/file.txt'));
  }

  /**
   * @covers ::getFilesystem
   * @covers ::getFilesystemForScheme
   */
  public function testGetFilesystemOverridden() {
    $method = new \ReflectionMethod($this->bridge, 'getFilesystem');
    $method
      ->setAccessible(TRUE);
    $this
      ->assertSame($this->filesystem, $method
      ->invoke($this->bridge));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemBridgeTest::$bridge protected property
FlysystemBridgeTest::$filesystem protected property
FlysystemBridgeTest::setUp public function Overrides UnitTestCase::setUp
FlysystemBridgeTest::testDirname public function @covers ::dirname
FlysystemBridgeTest::testGetDescriptionFormattingCorrect public function @covers ::getDescription
FlysystemBridgeTest::testGetExternalUrlDelegatesToPlugin public function @covers ::getExternalUrl @covers ::getFactory
FlysystemBridgeTest::testGetFilesystemOverridden public function @covers ::getFilesystem @covers ::getFilesystemForScheme
FlysystemBridgeTest::testGetNameFormattingCorrect public function @covers ::getName
FlysystemBridgeTest::testGetTypeReturnsWriteVisible public function @covers ::getType
FlysystemBridgeTest::testGetUriMatchesSetUri public function @covers ::getUri @covers ::setUri
FlysystemBridgeTest::testRealpathIsFalse public function @covers ::realpath
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.