You are here

class JsCollectionOptimizerTest in Flysystem 8

@coversDefaultClass \Drupal\flysystem\Asset\JsCollectionOptimizer @group flysystem

Hierarchy

Expanded class hierarchy of JsCollectionOptimizerTest

File

tests/src/Unit/Asset/JsCollectionOptimizerTest.php, line 20

Namespace

Drupal\Tests\flysystem\Unit\Asset
View source
class JsCollectionOptimizerTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    parent::setUp();
    if (!defined('REQUEST_TIME')) {
      define('REQUEST_TIME', time());
    }
    vfsStream::setup('flysystem');
    if (file_exists('vfs://flysystem/test.js')) {
      unlink('vfs://flysystem/test.js');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function tearDown() {
    if (file_exists('vfs://flysystem/test.js')) {
      unlink('vfs://flysystem/test.js');
    }
    parent::tearDown();
  }

  /**
   * @covers \Drupal\flysystem\Asset\JsCollectionOptimizer
   * @covers \Drupal\flysystem\Asset\CssCollectionOptimizer
   */
  public function test() {
    file_put_contents('vfs://flysystem/test.js', 'asdfasdf');
    touch('vfs://flysystem/test.js', REQUEST_TIME - 1000);
    $container = new ContainerBuilder();
    $container
      ->set('config.factory', $this
      ->getConfigFactoryStub([
      'system.performance' => [
        'stale_file_threshold' => 0,
      ],
    ]));
    \Drupal::setContainer($container);
    $grouper = $this
      ->prophesize(AssetCollectionGrouperInterface::class);
    $dumper = new AssetDumper();
    $state = $this
      ->getMock(StateInterface::class);
    $optimizer = new JsCollectionOptimizer($grouper
      ->reveal(), new JsOptimizer(), $dumper, $state);
    $optimizer
      ->deleteAll();
    $this
      ->assertFalse(file_exists('vfs://flysystem/test.js'));
    file_put_contents('vfs://flysystem/test.js', 'asdfasdf');
    touch('vfs://flysystem/test.js', REQUEST_TIME - 1000);
    $optimizer = new CssCollectionOptimizer($grouper
      ->reveal(), new CssOptimizer(), $dumper, $state);
    $optimizer
      ->deleteAll();
    $this
      ->assertFalse(file_exists('vfs://flysystem/test.js'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
JsCollectionOptimizerTest::setUp public function Overrides UnitTestCase::setUp
JsCollectionOptimizerTest::tearDown public function
JsCollectionOptimizerTest::test public function @covers \Drupal\flysystem\Asset\JsCollectionOptimizer @covers \Drupal\flysystem\Asset\CssCollectionOptimizer
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.