class FlysystemFactoryTest in Flysystem 3.x
Same name and namespace in other branches
- 8 tests/src/Unit/FlysystemFactoryTest.php \Drupal\Tests\flysystem\Unit\FlysystemFactoryTest
- 2.0.x tests/src/Unit/FlysystemFactoryTest.php \Drupal\Tests\flysystem\Unit\FlysystemFactoryTest
- 3.0.x tests/src/Unit/FlysystemFactoryTest.php \Drupal\Tests\flysystem\Unit\FlysystemFactoryTest
@coversDefaultClass \Drupal\flysystem\FlysystemFactory @group flysystem
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\flysystem\Unit\FlysystemFactoryTest
Expanded class hierarchy of FlysystemFactoryTest
File
- tests/
src/ Unit/ FlysystemFactoryTest.php, line 26
Namespace
Drupal\Tests\flysystem\UnitView source
class FlysystemFactoryTest extends UnitTestCase {
/**
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cache;
/**
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $filesystem;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $plugin;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $pluginManager;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->cache = new NullBackend('bin');
$this->eventDispatcher = $this
->createMock(EventDispatcherInterface::class);
$this->pluginManager = $this
->prophesize(PluginManagerInterface::class);
$this->plugin = $this
->prophesize(FlysystemPluginInterface::class);
$this->plugin
->getAdapter()
->willReturn(new NullAdapter());
$this->pluginManager
->createInstance('testdriver', [])
->willReturn($this->plugin
->reveal());
$this->pluginManager
->createInstance('', [])
->willReturn(new Missing());
$this->filesystem = $this
->prophesize(StreamWrapperManager::class);
$this->filesystem
->isValidScheme(Argument::type('string'))
->willReturn(TRUE);
}
/**
* @covers ::getFilesystem
* @covers ::__construct
* @covers ::getAdapter
* @covers ::getSettings
* @covers ::getPlugin
*/
public function testGetFilesystemReturnsValidFilesystem() {
new Settings([
'flysystem' => [
'testscheme' => [
'driver' => 'testdriver',
],
],
]);
$factory = $this
->getFactory();
$this
->assertInstanceOf(FilesystemInterface::class, $factory
->getFilesystem('testscheme'));
$this
->assertInstanceOf(NullAdapter::class, $factory
->getFilesystem('testscheme')
->getAdapter());
}
/**
* @covers ::getFilesystem
*/
public function testGetFilesystemReturnsMissingFilesystem() {
new Settings([]);
$factory = $this
->getFactory();
$this
->assertInstanceOf(MissingAdapter::class, $factory
->getFilesystem('testscheme')
->getAdapter());
}
/**
* @covers ::getFilesystem
* @covers ::getAdapter
*/
public function testGetFilesystemReturnsCachedAdapter() {
new Settings([
'flysystem' => [
'testscheme' => [
'driver' => 'testdriver',
'cache' => TRUE,
],
],
]);
$factory = $this
->getFactory();
$this
->assertInstanceOf(DrupalCacheAdapter::class, $factory
->getFilesystem('testscheme')
->getAdapter());
}
/**
* @covers ::getFilesystem
* @covers ::getAdapter
*/
public function testGetFilesystemReturnsReplicateAdapter() {
// Test replicate.
$this->pluginManager
->createInstance('wrapped', [])
->willReturn($this->plugin
->reveal());
new Settings([
'flysystem' => [
'testscheme' => [
'driver' => 'testdriver',
'replicate' => 'wrapped',
],
'wrapped' => [
'driver' => 'testdriver',
],
],
]);
$factory = $this
->getFactory();
$this
->assertInstanceOf(ReplicateAdapter::class, $factory
->getFilesystem('testscheme')
->getAdapter());
}
/**
* @covers ::getSchemes
* @covers ::__construct
*/
public function testGetSchemesFiltersInvalidSchemes() {
new Settings([
'flysystem' => [
'testscheme' => [
'driver' => 'testdriver',
],
'invalidscheme' => [
'driver' => 'testdriver',
],
],
]);
$this->filesystem
->isValidScheme('invalidscheme')
->willReturn(FALSE);
$this
->assertSame([
'testscheme',
], $this
->getFactory()
->getSchemes());
}
/**
* @covers ::getSchemes
*/
public function testGetSchemesHandlesNoSchemes() {
new Settings([]);
$this
->assertSame([], $this
->getFactory()
->getSchemes());
}
/**
* @covers ::ensure
*/
public function testEnsureReturnsErrors() {
new Settings([
'flysystem' => [
'testscheme' => [
'driver' => 'testdriver',
],
],
]);
$this->plugin
->ensure(FALSE)
->willReturn([
[
'severity' => 'bad',
'message' => 'Something bad',
'context' => [],
],
]);
$errors = $this
->getFactory()
->ensure();
$this
->assertSame('Something bad', $errors['testscheme'][0]['message']);
}
/**
* @return \Drupal\flysystem\FlysystemFactory
*/
protected function getFactory() {
return new FlysystemFactory($this->pluginManager
->reveal(), $this->filesystem
->reveal(), $this->cache, $this->eventDispatcher);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlysystemFactoryTest:: |
protected | property | ||
FlysystemFactoryTest:: |
protected | property | ||
FlysystemFactoryTest:: |
protected | property | ||
FlysystemFactoryTest:: |
protected | property | ||
FlysystemFactoryTest:: |
protected | property | ||
FlysystemFactoryTest:: |
protected | function | ||
FlysystemFactoryTest:: |
public | function |
Overrides UnitTestCase:: |
|
FlysystemFactoryTest:: |
public | function | @covers ::ensure | |
FlysystemFactoryTest:: |
public | function | @covers ::getFilesystem @covers ::getAdapter | |
FlysystemFactoryTest:: |
public | function | @covers ::getFilesystem | |
FlysystemFactoryTest:: |
public | function | @covers ::getFilesystem @covers ::getAdapter | |
FlysystemFactoryTest:: |
public | function | @covers ::getFilesystem @covers ::__construct @covers ::getAdapter @covers ::getSettings @covers ::getPlugin | |
FlysystemFactoryTest:: |
public | function | @covers ::getSchemes @covers ::__construct | |
FlysystemFactoryTest:: |
public | function | @covers ::getSchemes | |
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:: |
public static | function |