class ModuleFunctionsTest in Flysystem 8
Same name and namespace in other branches
- 3.x 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 PhpunitCompatibilityTrait
- class \Drupal\Tests\flysystem\Unit\ModuleFunctionsTest
Expanded class hierarchy of ModuleFunctionsTest
File
- tests/
src/ Unit/ ModuleFunctionsTest.php, line 20
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(FileSystemInterface::class);
$file_system_helper
->uriScheme(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. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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. |