class ModuleFunctionsTest in Flysystem 3.x
Same name and namespace in other branches
- 8 tests/src/Unit/ModuleFunctionsTest.php \Drupal\Tests\flysystem\Unit\ModuleFunctionsTest
- 2.0.x tests/src/Unit/ModuleFunctionsTest.php \Drupal\Tests\flysystem\Unit\ModuleFunctionsTest
- 3.0.x tests/src/Unit/ModuleFunctionsTest.php \Drupal\Tests\flysystem\Unit\ModuleFunctionsTest
Tests module functions.
@group flysystem
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\flysystem\Unit\ModuleFunctionsTest
Expanded class hierarchy of ModuleFunctionsTest
File
- tests/
src/ Unit/ ModuleFunctionsTest.php, line 18
Namespace
Drupal\Tests\flysystem\UnitView source
class ModuleFunctionsTest extends UnitTestCase {
/**
* The Flysystem factory prophecy object.
*
* @var \Prophecy\Prophecy\ObjectProphecy
*/
protected $factory;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
vfsStream::setup('module_file');
require_once dirname(dirname(dirname(__DIR__))) . '/flysystem.module';
$this->factory = $this
->prophesize(FlysystemFactory::class);
$this->factory
->getSchemes()
->willReturn([
'vfs',
]);
$file_system_helper = $this
->prophesize(StreamWrapperManagerInterface::class);
$file_system_helper
->isValidScheme(Argument::type('string'))
->will(function ($uri) {
list($scheme) = explode('://', $uri[0]);
return $scheme;
});
$guesser = $this
->prophesize(MimeTypeGuesserInterface::class);
$guesser
->guess(Argument::type('string'))
->willReturn('txt/flysystem');
$container = new ContainerBuilder();
$container
->set('file_system', $file_system_helper
->reveal());
$container
->set('flysystem_factory', $this->factory
->reveal());
$container
->set('file.mime_type.guesser.extension', $guesser
->reveal());
\Drupal::setContainer($container);
}
/**
* Tests flysystem_cron() calls ensure.
*/
public function testFlysystemCronCallsEnsure() {
$this->factory
->ensure()
->shouldBeCalled();
flysystem_cron();
}
/**
* Tests flysystem_rebuild() calls ensure.
*/
public function testFlysystemRebuildCallsEnsure() {
$this->factory
->ensure()
->shouldBeCalled();
flysystem_rebuild();
}
/**
* Tests flysystem_file_download() handles valid schemes.
*/
public function testFlysystemFileDownloadFindsValidScheme() {
file_put_contents('vfs://module_file/file.txt', '1234');
$return = flysystem_file_download('vfs://module_file/file.txt');
$this
->assertSame(2, count($return));
$this
->assertSame('txt/flysystem', $return['Content-Type']);
$this
->assertSame(4, $return['Content-Length']);
}
/**
* Tests flysystem_file_download() ignores invalid schemes.
*/
public function testFlysystemFileDownloadIgnoresInvalidScheme() {
$this
->assertNull(flysystem_file_download('invalid://module_file/file.txt'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModuleFunctionsTest:: |
protected | property | The Flysystem factory prophecy object. | |
ModuleFunctionsTest:: |
public | function |
Overrides UnitTestCase:: |
|
ModuleFunctionsTest:: |
public | function | Tests flysystem_cron() calls ensure. | |
ModuleFunctionsTest:: |
public | function | Tests flysystem_file_download() handles valid schemes. | |
ModuleFunctionsTest:: |
public | function | Tests flysystem_file_download() ignores invalid schemes. | |
ModuleFunctionsTest:: |
public | function | Tests flysystem_rebuild() calls ensure. | |
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 |