11<?php
22
3- use MatthiasMullie \Minify ;
3+ namespace MatthiasMullie \Minify \Test ;
4+
5+ use PHPUnit \Framework \TestCase ;
6+ use ReflectionObject ;
47
58/**
69 * CSS minifier test case.
710 */
8- class CSSTest extends PHPUnit_Framework_TestCase
11+ class CSSTest extends TestCase
912{
10- /**
11- * @var Minify\CSS
12- */
13- private $ minifier ;
14-
15- /**
16- * Prepares the environment before running a test.
17- */
18- protected function setUp ()
13+ protected function mockMinifier ()
1914 {
20- parent ::setUp ();
21-
2215 // override save method, there's no point in writing the result out here
23- $ this -> minifier = $ this ->getMockBuilder ('\MatthiasMullie\Minify\CSS ' )
16+ return $ this ->getMockBuilder ('\MatthiasMullie\Minify\CSS ' )
2417 ->setMethods (array ('save ' ))
2518 ->getMock ();
2619 }
2720
28- /**
29- * Cleans up the environment after running a test.
30- */
31- protected function tearDown ()
32- {
33- $ this ->minifier = null ;
34- parent ::tearDown ();
35- }
36-
3721 /**
3822 * Test CSS minifier rules, provided by dataProvider.
3923 *
40- * @test
4124 * @dataProvider dataProvider
4225 */
43- public function minify ($ input , $ expected )
26+ public function testMinify ($ input , $ expected )
4427 {
45- $ this ->minifier ->add ($ input );
46- $ result = $ this ->minifier ->minify ();
28+ $ minifier = $ this ->mockMinifier ();
29+ $ minifier ->add ($ input );
30+ $ result = $ minifier ->minify ();
4731 $ this ->assertEquals ($ expected , $ result );
4832 }
4933
5034 /**
5135 * Test conversion of relative paths, provided by dataProviderPaths.
5236 *
53- * @test
5437 * @dataProvider dataProviderPaths
5538 */
56- public function convertRelativePath ($ source , $ target , $ expected )
39+ public function testConvertRelativePath ($ source , $ target , $ expected )
5740 {
41+ $ minifier = $ this ->mockMinifier ();
5842 $ source = (array ) $ source ;
5943 foreach ($ source as $ path => $ css ) {
60- $ this -> minifier ->add ($ css );
44+ $ minifier ->add ($ css );
6145
6246 // $source also accepts an array where the key is a bogus path
6347 if (is_string ($ path )) {
64- $ object = new ReflectionObject ($ this -> minifier );
48+ $ object = new ReflectionObject ($ minifier );
6549 $ property = $ object ->getProperty ('data ' );
6650 $ property ->setAccessible (true );
67- $ data = $ property ->getValue ($ this -> minifier );
51+ $ data = $ property ->getValue ($ minifier );
6852
6953 // keep content, but make it appear from the given path
7054 $ data [$ path ] = array_pop ($ data );
71- $ property ->setValue ($ this -> minifier , $ data );
55+ $ property ->setValue ($ minifier , $ data );
7256 $ property ->setAccessible (false );
7357 }
7458 }
7559
76- $ result = $ this -> minifier ->minify ($ target );
60+ $ result = $ minifier ->minify ($ target );
7761
7862 $ this ->assertEquals ($ expected , $ result );
7963 }
8064
8165 /**
8266 * Test loop while importing file.
83- *
84- * @test
85- *
86- * @expectedException MatthiasMullie\Minify\Exceptions\FileImportException
8767 */
88- public function fileImportLoop ()
68+ public function testFileImportLoop ()
8969 {
70+ $ this ->expectException ('MatthiasMullie\Minify\Exceptions\FileImportException ' );
71+
9072 $ testFile = __DIR__ .'/sample/loop/first.css ' ;
9173
92- $ this ->minifier ->add ($ testFile );
74+ $ minifier = $ this ->mockMinifier ();
75+ $ minifier ->add ($ testFile );
9376
94- $ this -> minifier ->minify ();
77+ $ minifier ->minify ();
9578 }
9679
9780 /**
9881 * Test minifier import configuration methods.
99- *
100- * @test
10182 */
102- public function setConfig ()
83+ public function testSetConfig ()
10384 {
104- $ this ->minifier ->setMaxImportSize (10 );
105- $ this ->minifier ->setImportExtensions (array ('gif ' => 'data:image/gif ' ));
85+ $ minifier = $ this ->mockMinifier ();
86+ $ minifier ->setMaxImportSize (10 );
87+ $ minifier ->setImportExtensions (array ('gif ' => 'data:image/gif ' ));
10688
107- $ object = new ReflectionObject ($ this -> minifier );
89+ $ object = new ReflectionObject ($ minifier );
10890
10991 $ property = $ object ->getProperty ('maxImportSize ' );
11092 $ property ->setAccessible (true );
111- $ this ->assertEquals ($ property ->getValue ($ this -> minifier ), 10 );
93+ $ this ->assertEquals ($ property ->getValue ($ minifier ), 10 );
11294
11395 $ property = $ object ->getProperty ('importExtensions ' );
11496 $ property ->setAccessible (true );
115- $ this ->assertEquals ($ property ->getValue ($ this -> minifier ), array ('gif ' => 'data:image/gif ' ));
97+ $ this ->assertEquals ($ property ->getValue ($ minifier ), array ('gif ' => 'data:image/gif ' ));
11698 }
11799
118100 /**
@@ -124,11 +106,11 @@ public function dataProvider()
124106
125107 // passing in an array of css inputs
126108 $ tests [] = array (
127- [
109+ array (
128110 __DIR__ .'/sample/combine_imports/index.css ' ,
129111 __DIR__ .'/sample/bom/bom.css ' ,
130112 'p { width: 55px , margin: 0 0 0 0} ' ,
131- ] ,
113+ ) ,
132114 'body{color:red}body{color:red}p{width:55px,margin:0 0 0 0} ' ,
133115 );
134116
0 commit comments