File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed
lib/internal/Magento/Framework/Code
Test/Unit/Minifier/Adapter/Css Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 3
3
* Copyright © 2016 Magento. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
namespace Magento \Framework \Code \Minifier \Adapter \Css ;
8
7
9
8
use CSSmin as CssMinLibrary ;
@@ -26,10 +25,24 @@ class CSSmin implements AdapterInterface
26
25
27
26
/**
28
27
* @param CssMinLibrary $cssMinifier
28
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
29
29
*/
30
30
public function __construct (CssMinLibrary $ cssMinifier )
31
31
{
32
- $ this ->cssMinifier = $ cssMinifier ;
32
+ // TODO: set $cssMinifier in constructor once MAGETWO-51176 is resolved.
33
+ }
34
+
35
+ /**
36
+ * Get CSS Minifier
37
+ *
38
+ * @return \CSSMin
39
+ */
40
+ private function getCssMin ()
41
+ {
42
+ if (!($ this ->cssMinifier instanceof \CSSMin)) {
43
+ $ this ->cssMinifier = new \CSSmin (false );
44
+ }
45
+ return $ this ->cssMinifier ;
33
46
}
34
47
35
48
/**
@@ -42,7 +55,7 @@ public function minify($content)
42
55
{
43
56
$ pcreRecursionLimit = ini_get ('pcre.recursion_limit ' );
44
57
ini_set ('pcre.recursion_limit ' , self ::PCRE_RECURSION_LIMIT );
45
- $ result = $ this ->cssMinifier ->run ($ content );
58
+ $ result = $ this ->getCssMin () ->run ($ content );
46
59
ini_set ('pcre.recursion_limit ' , $ pcreRecursionLimit );
47
60
return $ result ;
48
61
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Copyright © 2016 Magento. All rights reserved.
4
+ * See COPYING.txt for license details.
5
+ */
6
+ namespace Magento \Framework \Code \Test \Unit \Minifier \Adapter \Css ;
7
+
8
+ class CssMinTest extends \PHPUnit_Framework_TestCase
9
+ {
10
+ public function testMinify ()
11
+ {
12
+ $ cssMinMock = $ this ->getMockBuilder (\CSSmin::class)
13
+ ->disableOriginalConstructor ()
14
+ ->getMock ();
15
+ $ cssMinAdapter = new \Magento \Framework \Code \Minifier \Adapter \Css \CSSmin ($ cssMinMock );
16
+ $ property = new \ReflectionProperty (\Magento \Framework \Code \Minifier \Adapter \Css \CSSmin::class, 'cssMinifier ' );
17
+ $ property ->setAccessible (true );
18
+ $ property ->setValue ($ cssMinAdapter , $ cssMinMock );
19
+
20
+ $ expectedResult = 'minified content ' ;
21
+ $ cssMinMock ->expects ($ this ->once ())->method ('run ' )->willReturn ($ expectedResult );
22
+ $ this ->assertEquals ($ expectedResult , $ cssMinAdapter ->minify ('not minified ' ));
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments