You are here

protected function CssCollectionOptimizerUnitTest::setUp in Drupal 10

Overrides UnitTestCase::setUp

File

core/tests/Drupal/Tests/Core/Asset/CssCollectionOptimizerUnitTest.php, line 34

Class

CssCollectionOptimizerUnitTest
Tests the CSS asset optimizer.

Namespace

Drupal\Tests\Core\Asset

Code

protected function setUp() : void {
  parent::setUp();
  $mock_grouper = $this
    ->createMock(AssetCollectionGrouperInterface::class);
  $mock_grouper
    ->method('group')
    ->willReturnCallback(function ($assets) {
    return [
      [
        'items' => $assets,
        'type' => 'file',
        'preprocess' => TRUE,
      ],
    ];
  });
  $mock_optimizer = $this
    ->createMock(AssetOptimizerInterface::class);
  $mock_optimizer
    ->method('optimize')
    ->willReturn(file_get_contents(__DIR__ . '/css_test_files/css_input_with_import.css.optimized.css'), file_get_contents(__DIR__ . '/css_test_files/css_subfolder/css_input_with_import.css.optimized.css'));
  $mock_dumper = $this
    ->createMock(AssetDumperInterface::class);
  $mock_dumper
    ->method('dump')
    ->willReturnCallback(function ($css) {
    $this->dumperData = $css;
  });
  $mock_state = $this
    ->createMock(StateInterface::class);
  $mock_file_system = $this
    ->createMock(FileSystemInterface::class);
  $this->optimizer = new CssCollectionOptimizer($mock_grouper, $mock_optimizer, $mock_dumper, $mock_state, $mock_file_system);
}