InstallFunctionsTest.php in Flysystem 2.0.x
File
tests/src/Unit/InstallFunctionsTest.php
View source
<?php
namespace Drupal\Tests\flysystem\Unit;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Site\Settings;
use Drupal\Tests\UnitTestCase;
use Drupal\flysystem\FlysystemFactory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Twistor\FlysystemStreamWrapper;
class InstallFunctionsTest extends UnitTestCase {
protected $factory;
public function setUp() {
parent::setUp();
if (!defined('REQUIREMENT_ERROR')) {
define('REQUIREMENT_ERROR', 2);
}
require_once dirname(dirname(dirname(__DIR__))) . '/flysystem.install';
$this->factory = $this
->prophesize(FlysystemFactory::class);
$container = new ContainerBuilder();
$container
->set('flysystem_factory', $this->factory
->reveal());
$container
->set('string_translation', $this
->getStringTranslationStub());
\Drupal::setContainer($container);
}
public function testFlysystemRequirementsHandlesUpdate() {
$dependencies_exist = (int) class_exists(FlysystemStreamWrapper::class);
$return = flysystem_requirements('update');
$this
->assertSame(1 - $dependencies_exist, count($return));
}
public function testFlysystemRequirementsHandlesInstall() {
$dependencies_exist = (int) class_exists(FlysystemStreamWrapper::class);
$return = flysystem_requirements('install');
$this
->assertSame(1 - $dependencies_exist, count($return));
}
public function testFlysystemRequirementsHandlesRuntime() {
$dependencies_exist = (int) class_exists(FlysystemStreamWrapper::class);
$this->factory
->ensure()
->willReturn([
'testscheme' => [
[
'message' => 'Test message',
'context' => [],
'severity' => RfcLogLevel::ERROR,
],
],
]);
$return = flysystem_requirements('runtime');
$this
->assertSame(2 - $dependencies_exist, count($return));
$this
->assertSame('Test message', (string) $return['flysystem:testscheme']['description']);
}
public function testFlysystemRequirementsHandlesInvalidSchemes() {
new Settings([
'flysystem' => [
'test_scheme' => [],
],
]);
$requirements = flysystem_requirements('update');
$this
->assertTrue(isset($requirements['flysystem_invalid_scheme']));
}
public function testFlysystemInstallCallsEnsure() {
$this->factory
->ensure()
->shouldBeCalled();
flysystem_install();
}
}