Passed
Push — main ( 82104f...ee6fb2 )
by Thierry
05:16
created

MinifierTest::testJsMinifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A MinifierTest::testJsFileMinifier() 0 9 1
1
<?php
2
3
namespace Jaxon\Utils\Tests\TestMinifier;
4
5
use Jaxon\Utils\File\FileMinifier;
6
use PHPUnit\Framework\TestCase;
7
8
use function file_exists;
9
use function file_get_contents;
10
use function filesize;
11
use function strlen;
12
13
final class MinifierTest extends TestCase
14
{
15
    /**
16
     * @var FileMinifier
17
     */
18
    protected $xMinifier;
19
20
    protected function setUp(): void
21
    {
22
        $this->xMinifier = new FileMinifier();
23
    }
24
25
    public function testFileNotFound()
26
    {
27
        $sSrcFile = __DIR__ . '/../minifier/nosrc.js';
28
        $sDstMinFile = __DIR__ . '/../minifier/dst.min.js';
29
30
        $this->assertFalse($this->xMinifier->minify($sSrcFile, $sDstMinFile));
31
    }
32
33
    public function testFileError()
34
    {
35
        $sSrcFile = __DIR__ . '/../minifier/error.js';
36
        $sDstMinFile = __DIR__ . '/../minifier/error.min.js';
37
38
        $this->assertFalse($this->xMinifier->minify($sSrcFile, $sDstMinFile));
39
    }
40
41
    public function testJsFileMinifier()
42
    {
43
        $sSrcFile = __DIR__ . '/../minifier/src.js';
44
        $sSrcMinFile = __DIR__ . '/../minifier/src.min.js';
45
        $sDstMinFile = __DIR__ . '/../minifier/dst.min.js';
46
47
        $this->assertTrue($this->xMinifier->minifyJsFile($sSrcFile, $sDstMinFile));
48
        $this->assertTrue(file_exists($sDstMinFile));
49
        $this->assertEquals(filesize($sSrcMinFile), filesize($sDstMinFile));
50
    }
51
52
    public function testCssFileMinifier()
53
    {
54
        $sSrcFile = __DIR__ . '/../minifier/src.css';
55
        $sSrcMinFile = __DIR__ . '/../minifier/src.min.css';
56
        $sDstMinFile = __DIR__ . '/../minifier/dst.min.css';
57
58
        $this->assertTrue($this->xMinifier->minifyCssFile($sSrcFile, $sDstMinFile));
59
        $this->assertTrue(file_exists($sDstMinFile));
60
        $this->assertEquals(filesize($sSrcMinFile), filesize($sDstMinFile));
61
    }
62
63
    public function testJsCodeMinifier()
64
    {
65
        $sSrcFile = __DIR__ . '/../minifier/src.js';
66
        $sSrcMinFile = __DIR__ . '/../minifier/src.min.js';
67
68
        $sMinCode = $this->xMinifier->minifyJsCode(file_get_contents($sSrcFile));
69
70
        $this->assertNotFalse($sMinCode);
71
        $this->assertEquals(filesize($sSrcMinFile), strlen($sMinCode));
0 ignored issues
show
Bug introduced by
It seems like $sMinCode can also be of type false; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

71
        $this->assertEquals(filesize($sSrcMinFile), strlen(/** @scrutinizer ignore-type */ $sMinCode));
Loading history...
72
    }
73
74
    public function testCssCodeMinifier()
75
    {
76
        $sSrcFile = __DIR__ . '/../minifier/src.css';
77
        $sSrcMinFile = __DIR__ . '/../minifier/src.min.css';
78
79
        $sMinCode = $this->xMinifier->minifyCssCode(file_get_contents($sSrcFile));
80
81
        $this->assertNotFalse($sMinCode);
82
        $this->assertEquals(filesize($sSrcMinFile), strlen($sMinCode));
0 ignored issues
show
Bug introduced by
It seems like $sMinCode can also be of type false; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

82
        $this->assertEquals(filesize($sSrcMinFile), strlen(/** @scrutinizer ignore-type */ $sMinCode));
Loading history...
83
    }
84
}
85