You are here

class ModuleFunctionsTest in Flysystem 3.x

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

Tests module functions.

@group flysystem

Hierarchy

Expanded class hierarchy of ModuleFunctionsTest

File

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

Namespace

Drupal\Tests\flysystem\Unit
View 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

Namesort descending Modifiers Type Description Overrides
ModuleFunctionsTest::$factory protected property The Flysystem factory prophecy object.
ModuleFunctionsTest::setUp public function Overrides UnitTestCase::setUp
ModuleFunctionsTest::testFlysystemCronCallsEnsure public function Tests flysystem_cron() calls ensure.
ModuleFunctionsTest::testFlysystemFileDownloadFindsValidScheme public function Tests flysystem_file_download() handles valid schemes.
ModuleFunctionsTest::testFlysystemFileDownloadIgnoresInvalidScheme public function Tests flysystem_file_download() ignores invalid schemes.
ModuleFunctionsTest::testFlysystemRebuildCallsEnsure public function Tests flysystem_rebuild() calls ensure.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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.
UnitTestCase::setUpBeforeClass public static function