You are here

class FlysystemServiceProviderTest in Flysystem 8

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

@coversDefaultClass \Drupal\flysystem\FlysystemServiceProvider @group flysystem

Hierarchy

Expanded class hierarchy of FlysystemServiceProviderTest

File

tests/src/Unit/FlysystemServiceProviderTest.php, line 24

Namespace

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

  /**
   * @var \Symfony\Component\DependencyInjection\ContainerInterface
   */
  protected $container;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $this->container = new ContainerBuilder();
  }

  /**
   * @covers ::register
   */
  public function testNothingFailsIfContainerIsEmpty() {
    new Settings([]);
    (new FlysystemServiceProvider())
      ->register($this->container);
  }

  /**
   * @covers ::register
   */
  public function testMissingDriverIsSkipped() {
    new Settings([
      'flysystem' => [
        'testscheme' => [],
      ],
    ]);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertFalse($this->container
      ->has('flysystem_stream_wrapper.testscheme'));
  }

  /**
   * @covers ::register
   */
  public function testValidSchemeConfiguration() {
    new Settings([
      'flysystem' => [
        'testscheme' => [
          'driver' => 'whatever',
        ],
      ],
    ]);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertTrue($this->container
      ->has('flysystem_stream_wrapper.testscheme'));
    $this
      ->assertSame(FlysystemBridge::class, $this->container
      ->getDefinition('flysystem_stream_wrapper.testscheme')
      ->getClass());
    $this
      ->assertSame([
      [
        'scheme' => 'testscheme',
      ],
    ], $this->container
      ->getDefinition('flysystem_stream_wrapper.testscheme')
      ->getTag('stream_wrapper'));
  }

  /**
   * @covers ::register
   */
  public function testLocalRouteProviderGetsAdded() {
    new Settings([
      'flysystem' => [
        'testscheme' => [
          'driver' => 'local',
          'config' => [
            'public' => TRUE,
          ],
        ],
      ],
    ]);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertSame(LocalPathProcessor::class, $this->container
      ->getDefinition('flysystem.testscheme.path_processor')
      ->getClass());
  }

  /**
   * @covers \Drupal\flysystem\FlysystemServiceProvider
   */
  public function test() {

    // Test swapping the asset dumper.
    $this->container
      ->register('asset.js.dumper', AssetDumper::class);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertSame(AssetDumper::class, $this->container
      ->getDefinition('asset.js.dumper')
      ->getClass());
    $this->container
      ->register('asset.js.collection_optimizer', JsCollectionOptimizer::class);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertSame(AssetDumper::class, $this->container
      ->getDefinition('asset.js.dumper')
      ->getClass());
    $this
      ->assertSame(JsCollectionOptimizer::class, $this->container
      ->getDefinition('asset.js.collection_optimizer')
      ->getClass());

    // A successful swap.
    new Settings([
      'flysystem' => [
        'testscheme' => [
          'driver' => 'whatever',
          'serve_js' => TRUE,
        ],
      ],
    ]);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertSame(FlysystemAssetDumper::class, $this->container
      ->getDefinition('asset.js.dumper')
      ->getClass());
    $this
      ->assertSame(FlysystemJsCollectionOptimizer::class, $this->container
      ->getDefinition('asset.js.collection_optimizer')
      ->getClass());
  }

  /**
   * @covers \Drupal\flysystem\FlysystemServiceProvider
   */
  public function testSwappingCssServices() {

    // Test swapping the asset dumper.
    $this->container
      ->register('asset.css.dumper', AssetDumper::class);
    $this->container
      ->register('asset.css.collection_optimizer', CssCollectionOptimizer::class);
    $this->container
      ->register('asset.css.optimizer', CssOptimizer::class);
    new Settings([
      'flysystem' => [
        'testscheme' => [
          'driver' => 'whatever',
          'serve_css' => TRUE,
        ],
      ],
    ]);
    (new FlysystemServiceProvider())
      ->register($this->container);
    $this
      ->assertSame(FlysystemAssetDumper::class, $this->container
      ->getDefinition('asset.css.dumper')
      ->getClass());
    $this
      ->assertSame(FlysystemCssCollectionOptimizer::class, $this->container
      ->getDefinition('asset.css.collection_optimizer')
      ->getClass());
    $this
      ->assertSame(FlysystemCssOptimizer::class, $this->container
      ->getDefinition('asset.css.optimizer')
      ->getClass());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlysystemServiceProviderTest::$container protected property
FlysystemServiceProviderTest::setUp public function Overrides UnitTestCase::setUp
FlysystemServiceProviderTest::test public function @covers \Drupal\flysystem\FlysystemServiceProvider
FlysystemServiceProviderTest::testLocalRouteProviderGetsAdded public function @covers ::register
FlysystemServiceProviderTest::testMissingDriverIsSkipped public function @covers ::register
FlysystemServiceProviderTest::testNothingFailsIfContainerIsEmpty public function @covers ::register
FlysystemServiceProviderTest::testSwappingCssServices public function @covers \Drupal\flysystem\FlysystemServiceProvider
FlysystemServiceProviderTest::testValidSchemeConfiguration public function @covers ::register
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.