You are here

class InstallFunctionsTest in Flysystem 8

Same name and namespace in other branches
  1. 3.x tests/src/Unit/InstallFunctionsTest.php \Drupal\Tests\flysystem\Unit\InstallFunctionsTest
  2. 2.0.x tests/src/Unit/InstallFunctionsTest.php \Drupal\Tests\flysystem\Unit\InstallFunctionsTest
  3. 3.0.x tests/src/Unit/InstallFunctionsTest.php \Drupal\Tests\flysystem\Unit\InstallFunctionsTest

Tests flysystem.install functions.

@group flysystem

Hierarchy

Expanded class hierarchy of InstallFunctionsTest

File

tests/src/Unit/InstallFunctionsTest.php, line 18

Namespace

Drupal\Tests\flysystem\Unit
View source
class InstallFunctionsTest extends UnitTestCase {

  /**
   * The Flysystem factory prophecy object.
   *
   * @var \Prophecy\Prophecy\ObjectProphecy
   */
  protected $factory;

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * Tests flysystem_requirements() handles update.
   */
  public function testFlysystemRequirementsHandlesUpdate() {
    $dependencies_exist = (int) class_exists(FlysystemStreamWrapper::class);
    $return = flysystem_requirements('update');
    $this
      ->assertSame(1 - $dependencies_exist, count($return));
  }

  /**
   * Tests flysystem_requirements() handles install.
   */
  public function testFlysystemRequirementsHandlesInstall() {
    $dependencies_exist = (int) class_exists(FlysystemStreamWrapper::class);
    $return = flysystem_requirements('install');
    $this
      ->assertSame(1 - $dependencies_exist, count($return));
  }

  /**
   * Tests flysystem_requirements() handles runtime.
   */
  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']);
  }

  /**
   * Tests flysystem_requirements() detects invalid schemes.
   */
  public function testFlysystemRequirementsHandlesInvalidSchemes() {
    new Settings([
      'flysystem' => [
        'test_scheme' => [],
      ],
    ]);
    $requirements = flysystem_requirements('update');
    $this
      ->assertTrue(isset($requirements['flysystem_invalid_scheme']));
  }

  /**
   * Tests flysystem_install() calls ensure().
   */
  public function testFlysystemInstallCallsEnsure() {
    $this->factory
      ->ensure()
      ->shouldBeCalled();
    flysystem_install();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InstallFunctionsTest::$factory protected property The Flysystem factory prophecy object.
InstallFunctionsTest::setUp public function Overrides UnitTestCase::setUp
InstallFunctionsTest::testFlysystemInstallCallsEnsure public function Tests flysystem_install() calls ensure().
InstallFunctionsTest::testFlysystemRequirementsHandlesInstall public function Tests flysystem_requirements() handles install.
InstallFunctionsTest::testFlysystemRequirementsHandlesInvalidSchemes public function Tests flysystem_requirements() detects invalid schemes.
InstallFunctionsTest::testFlysystemRequirementsHandlesRuntime public function Tests flysystem_requirements() handles runtime.
InstallFunctionsTest::testFlysystemRequirementsHandlesUpdate public function Tests flysystem_requirements() handles update.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.