-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMinifyTest.php
More file actions
86 lines (66 loc) · 2.73 KB
/
Copy pathMinifyTest.php
File metadata and controls
86 lines (66 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
/*
* This file is part of the SensioLabs MinifyBundle package.
*
* (c) Simon André - Sensiolabs
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sensiolabs\MinifyBundle\Tests;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Sensiolabs\MinifyBundle\Exception\RuntimeException;
use Sensiolabs\MinifyBundle\Minifier\Options\HtmlOptions;
use Sensiolabs\MinifyBundle\Minify;
use Symfony\Component\Filesystem\Filesystem;
#[CoversClass(Minify::class)]
class MinifyTest extends TestCase
{
private const FIXTURES_PATH = __DIR__.'/Fixtures';
private const FIXTURES_BINARY_PATH = __DIR__.'/Fixtures/bin/fakify';
protected function setUp(): void
{
(new Filesystem())->chmod(self::FIXTURES_BINARY_PATH, 0755);
}
public function testMinifyReturnsOutputOnSuccess(): void
{
$minify = new Minify(self::FIXTURES_BINARY_PATH);
$input = file_get_contents(self::FIXTURES_PATH.'/assets/css/style.css');
$this->assertSame($input, $minify->minify($input, 'css'));
}
public function testMinifyThrowsRuntimeExceptionOnProcessException(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Minify error 127: "Command not found".');
$minify = new Minify('foo');
$minify->minify('input content', 'foo');
}
public function testMinifyThrowsRuntimeExceptionOnProcessFailure(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Minify error 1: "General error".');
$minify = new Minify(self::FIXTURES_BINARY_PATH);
$minify->minify('input content', 'foo');
}
public function testMinifyForwardsOptionsCliArgs(): void
{
$minify = new Minify(self::FIXTURES_BINARY_PATH);
$output = $minify->minify('<html></html>', 'html', new HtmlOptions(keepDocumentTags: true));
$this->assertSame('<html></html>|args=--html-keep-document-tags', $output);
}
public function testMinifyPassesNoExtraArgsWhenOptionsHaveNoFlags(): void
{
$minify = new Minify(self::FIXTURES_BINARY_PATH);
$output = $minify->minify('<html></html>', 'html', new HtmlOptions());
$this->assertSame('<html></html>|args=', $output);
}
public function testMinifyThrowsWhenOptionsTypeDoesNotMatch(): void
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Options type "html" does not match minify type "css".');
$minify = new Minify(self::FIXTURES_BINARY_PATH);
$minify->minify('input', 'css', new HtmlOptions());
}
}