FlysystemBridgeTest.php in Flysystem 8
File
tests/src/Unit/FlysystemBridgeTest.php
View source
<?php
namespace Drupal\Tests\flysystem\Unit;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\flysystem\FlysystemBridge;
use Drupal\flysystem\FlysystemFactory;
use Drupal\flysystem\Flysystem\Adapter\MissingAdapter;
use Drupal\flysystem\Flysystem\Missing;
use League\Flysystem\Filesystem;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class FlysystemBridgeTest extends UnitTestCase {
protected $bridge;
protected $filesystem;
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);
}
public function testGetTypeReturnsWriteVisible() {
$this
->assertSame(StreamWrapperInterface::WRITE_VISIBLE, FlysystemBridge::getType());
}
public function testGetNameFormattingCorrect() {
$this
->assertSame('Flysystem: testscheme', (string) $this->bridge
->getName());
}
public function testGetDescriptionFormattingCorrect() {
$this
->assertSame('Flysystem: testscheme', (string) $this->bridge
->getDescription());
}
public function testGetUriMatchesSetUri() {
$this->bridge
->setUri('beep://boop');
$this
->assertSame('beep://boop', $this->bridge
->getUri());
}
public function testGetExternalUrlDelegatesToPlugin() {
$this
->assertSame('', $this->bridge
->getExternalUrl('testscheme://testfile.txt'));
}
public function testRealpathIsFalse() {
$this
->assertFalse($this->bridge
->realpath());
}
public function testDirname() {
$this
->assertSame('testscheme://', $this->bridge
->dirname());
$this
->assertSame('testscheme://dir://dir', $this->bridge
->dirname('testscheme:///dir://dir/file.txt'));
}
public function testGetFilesystemOverridden() {
$method = new \ReflectionMethod($this->bridge, 'getFilesystem');
$method
->setAccessible(TRUE);
$this
->assertSame($this->filesystem, $method
->invoke($this->bridge));
}
}