Skip to content

Commit 6a9571a

Browse files
committed
add test for ChainCompressor
1 parent 30da491 commit 6a9571a

File tree

4 files changed

+84
-21
lines changed

4 files changed

+84
-21
lines changed

src/Symfony/Component/AssetMapper/Tests/Compressor/BrotliCompressorTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
*/
2121
class BrotliCompressorTest extends TestCase
2222
{
23+
private const WRITABLE_ROOT = __DIR__.'/../Fixtures/brotli_compressor_filesystem';
24+
2325
private Filesystem $filesystem;
24-
private static string $writableRoot = __DIR__.'/../Fixtures/brotli_compressor_filesystem';
2526

2627
protected function setUp(): void
2728
{
@@ -30,22 +31,22 @@ protected function setUp(): void
3031
}
3132

3233
$this->filesystem = new Filesystem();
33-
if (!file_exists(__DIR__.'/../Fixtures/brotli_compressor_filesystem')) {
34-
$this->filesystem->mkdir(self::$writableRoot);
34+
if (!file_exists(self::WRITABLE_ROOT)) {
35+
$this->filesystem->mkdir(self::WRITABLE_ROOT);
3536
}
3637
}
3738

3839
protected function tearDown(): void
3940
{
40-
$this->filesystem->remove(self::$writableRoot);
41+
$this->filesystem->remove(self::WRITABLE_ROOT);
4142
}
4243

4344
public function testCompress()
4445
{
45-
$this->filesystem->dumpFile(self::$writableRoot.'/foo/bar.js', 'foobar');
46+
$this->filesystem->dumpFile(self::WRITABLE_ROOT.'/foo/bar.js', 'foobar');
4647

47-
(new BrotliCompressor())->compress(self::$writableRoot.'/foo/bar.js');
48+
(new BrotliCompressor())->compress(self::WRITABLE_ROOT.'/foo/bar.js');
4849

49-
$this->assertFileExists(self::$writableRoot.'/foo/bar.js.br');
50+
$this->assertFileExists(self::WRITABLE_ROOT.'/foo/bar.js.br');
5051
}
5152
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\AssetMapper\Tests\Compressor;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\AssetMapper\Compressor\BrotliCompressor;
16+
use Symfony\Component\AssetMapper\Compressor\ChainCompressor;
17+
use Symfony\Component\AssetMapper\Compressor\ZstandardCompressor;
18+
use Symfony\Component\Filesystem\Filesystem;
19+
20+
/**
21+
* @author Kévin Dunglas <kevin@dunglas.dev>
22+
*/
23+
class ChainCompressorTest extends TestCase
24+
{
25+
private const WRITABLE_ROOT = __DIR__.'/../Fixtures/chain_compressor_filesystem';
26+
27+
private Filesystem $filesystem;
28+
29+
protected function setUp(): void
30+
{
31+
$this->filesystem = new Filesystem();
32+
if (!file_exists(self::WRITABLE_ROOT)) {
33+
$this->filesystem->mkdir(self::WRITABLE_ROOT);
34+
}
35+
}
36+
37+
protected function tearDown(): void
38+
{
39+
$this->filesystem->remove(self::WRITABLE_ROOT);
40+
}
41+
42+
public function testCompress()
43+
{
44+
$extensions = ['gz'];
45+
if (null === (new BrotliCompressor())->getUnsupportedReason()) {
46+
$extensions[] = 'br';
47+
}
48+
if (null === (new ZstandardCompressor())->getUnsupportedReason()) {
49+
$extensions[] = 'zst';
50+
}
51+
52+
$this->filesystem->dumpFile(self::WRITABLE_ROOT.'/foo/bar.js', 'foobar');
53+
54+
(new ChainCompressor())->compress(self::WRITABLE_ROOT.'/foo/bar.js');
55+
56+
foreach ($extensions as $extension) {
57+
$this->assertFileExists(self::WRITABLE_ROOT.'/foo/bar.js.'.$extension);
58+
}
59+
}
60+
}

src/Symfony/Component/AssetMapper/Tests/Compressor/GzipCompressorTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@
2020
*/
2121
class GzipCompressorTest extends TestCase
2222
{
23+
private const WRITABLE_ROOT = __DIR__.'/../Fixtures/gzip_compressor_filesystem';
24+
2325
private Filesystem $filesystem;
24-
private static string $writableRoot = __DIR__.'/../Fixtures/gzip_compressor_filesystem';
2526

2627
protected function setUp(): void
2728
{
2829
$this->filesystem = new Filesystem();
29-
if (!file_exists(__DIR__.'/../Fixtures/gzip_compressor_filesystem')) {
30-
$this->filesystem->mkdir(self::$writableRoot);
30+
if (!file_exists(self::WRITABLE_ROOT)) {
31+
$this->filesystem->mkdir(self::WRITABLE_ROOT);
3132
}
3233
}
3334

3435
protected function tearDown(): void
3536
{
36-
$this->filesystem->remove(self::$writableRoot);
37+
$this->filesystem->remove(self::WRITABLE_ROOT);
3738
}
3839

3940
public function testCompress()
4041
{
41-
$this->filesystem->dumpFile(self::$writableRoot.'/foo/bar.js', 'foobar');
42+
$this->filesystem->dumpFile(self::WRITABLE_ROOT.'/foo/bar.js', 'foobar');
4243

43-
(new GzipCompressor())->compress(self::$writableRoot.'/foo/bar.js');
44+
(new GzipCompressor())->compress(self::WRITABLE_ROOT.'/foo/bar.js');
4445

45-
$this->assertFileExists(self::$writableRoot.'/foo/bar.js.gz');
46+
$this->assertFileExists(self::WRITABLE_ROOT.'/foo/bar.js.gz');
4647
}
4748
}

src/Symfony/Component/AssetMapper/Tests/Compressor/ZstandardCompressorTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
*/
2121
class ZstandardCompressorTest extends TestCase
2222
{
23+
private const WRITABLE_ROOT = __DIR__.'/../Fixtures/zstandard_compressor_filesystem';
24+
2325
private Filesystem $filesystem;
24-
private static string $writableRoot = __DIR__.'/../Fixtures/zstandard_compressor_filesystem';
2526

2627
protected function setUp(): void
2728
{
@@ -30,22 +31,22 @@ protected function setUp(): void
3031
}
3132

3233
$this->filesystem = new Filesystem();
33-
if (!file_exists(__DIR__.'/../Fixtures/zstandard_compressor_filesystem')) {
34-
$this->filesystem->mkdir(self::$writableRoot);
34+
if (!file_exists(self::WRITABLE_ROOT)) {
35+
$this->filesystem->mkdir(self::WRITABLE_ROOT);
3536
}
3637
}
3738

3839
protected function tearDown(): void
3940
{
40-
$this->filesystem->remove(self::$writableRoot);
41+
$this->filesystem->remove(self::WRITABLE_ROOT);
4142
}
4243

4344
public function testCompress()
4445
{
45-
$this->filesystem->dumpFile(self::$writableRoot.'/foo/bar.js', 'foobar');
46+
$this->filesystem->dumpFile(self::WRITABLE_ROOT.'/foo/bar.js', 'foobar');
4647

47-
(new ZstandardCompressor())->compress(self::$writableRoot.'/foo/bar.js');
48+
(new ZstandardCompressor())->compress(self::WRITABLE_ROOT.'/foo/bar.js');
4849

49-
$this->assertFileExists(self::$writableRoot.'/foo/bar.js.zst');
50+
$this->assertFileExists(self::WRITABLE_ROOT.'/foo/bar.js.zst');
5051
}
5152
}

0 commit comments

Comments
 (0)