mirror of
https://github.com/mrclay/minify.git
synced 2025-08-06 14:16:28 +02:00
Test fixes
This commit is contained in:
@@ -122,7 +122,7 @@ class App extends Container
|
|||||||
|
|
||||||
$type = $that->typeOf($ctrl);
|
$type = $that->typeOf($ctrl);
|
||||||
throw new RuntimeException('$min_factories["controller"] callable must return an implementation'
|
throw new RuntimeException('$min_factories["controller"] callable must return an implementation'
|
||||||
." of Minify_CacheInterface. Returned $type");
|
. " of Minify_CacheInterface. Returned $type");
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->docRoot = function (App $app) {
|
$this->docRoot = function (App $app) {
|
||||||
@@ -188,7 +188,7 @@ class App extends Container
|
|||||||
|
|
||||||
$type = $that->typeOf($value);
|
$type = $that->typeOf($value);
|
||||||
throw new RuntimeException('If set, $min_errorLogger must be a PSR-3 logger or a Monolog handler.'
|
throw new RuntimeException('If set, $min_errorLogger must be a PSR-3 logger or a Monolog handler.'
|
||||||
." Given $type");
|
. " Given $type");
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->minify = function (App $app) use ($that) {
|
$this->minify = function (App $app) use ($that) {
|
||||||
@@ -205,7 +205,7 @@ class App extends Container
|
|||||||
|
|
||||||
$type = $that->typeOf($minify);
|
$type = $that->typeOf($minify);
|
||||||
throw new RuntimeException('$min_factories["minify"] callable must return a Minify object.'
|
throw new RuntimeException('$min_factories["minify"] callable must return a Minify object.'
|
||||||
." Returned $type");
|
. " Returned $type");
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->serveOptions = function (App $app) {
|
$this->serveOptions = function (App $app) {
|
||||||
@@ -232,7 +232,7 @@ class App extends Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check for URI versioning
|
// check for URI versioning
|
||||||
if ($env->get('v') !== null || preg_match('/&\\d/', $app->env->server('QUERY_STRING'))) {
|
if ($env->get('v') !== null || preg_match('/&\\d/', $app->env->server('QUERY_STRING') ?? '')) {
|
||||||
$ret['maxAge'] = 31536000;
|
$ret['maxAge'] = 31536000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -188,7 +188,7 @@ class Minify_ClosureCompiler
|
|||||||
*/
|
*/
|
||||||
protected function checkTempdir($tempDir)
|
protected function checkTempdir($tempDir)
|
||||||
{
|
{
|
||||||
if (!is_dir($tempDir)) {
|
if ($tempDir === null || !is_dir($tempDir)) {
|
||||||
throw new Minify_ClosureCompiler_Exception('$tempDir(' . $tempDir . ') is not a valid direcotry.');
|
throw new Minify_ClosureCompiler_Exception('$tempDir(' . $tempDir . ') is not a valid direcotry.');
|
||||||
}
|
}
|
||||||
if (!is_writable($tempDir)) {
|
if (!is_writable($tempDir)) {
|
||||||
|
@@ -156,8 +156,8 @@ class Minify_ScssCssSource extends Minify_Source
|
|||||||
$elapsed = round((microtime(true) - $start), 4);
|
$elapsed = round((microtime(true) - $start), 4);
|
||||||
|
|
||||||
$v = Version::VERSION;
|
$v = Version::VERSION;
|
||||||
$ts = date('r', $start);
|
$ts = date('r', (int) $start);
|
||||||
$css = "/* compiled by scssphp $v on $ts (${elapsed}s) */\n\n" . $css;
|
$css = "/* compiled by scssphp $v on $ts ({$elapsed}s) */\n\n" . $css;
|
||||||
|
|
||||||
$imports = $scss->getParsedFiles();
|
$imports = $scss->getParsedFiles();
|
||||||
|
|
||||||
|
@@ -113,10 +113,12 @@ class HTTPEncoderTest extends TestCase
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ($encodingTests as $test) {
|
foreach ($encodingTests as $test) {
|
||||||
$e = new HTTP_Encoder(array(
|
$e = new HTTP_Encoder(
|
||||||
'content' => $variedContent,
|
array(
|
||||||
'method' => $test['method'],
|
'content' => $variedContent,
|
||||||
));
|
'method' => $test['method'],
|
||||||
|
)
|
||||||
|
);
|
||||||
$e->encode(9);
|
$e->encode(9);
|
||||||
$ret = $this->countBytes($e->getContent());
|
$ret = $this->countBytes($e->getContent());
|
||||||
|
|
||||||
@@ -153,12 +155,12 @@ function _gzdecode($data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// http://www.php.net/manual/en/function.gzdecode.php#82930
|
// http://www.php.net/manual/en/function.gzdecode.php#82930
|
||||||
function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
function _phpman_gzdecode($data, &$filename = '', &$error = '', $maxlength = 0)
|
||||||
{
|
{
|
||||||
$mbIntEnc = null;
|
$mbIntEnc = null;
|
||||||
$hasMbOverload = (function_exists('mb_strlen')
|
$hasMbOverload = (function_exists('mb_strlen')
|
||||||
&& (ini_get('mbstring.func_overload') !== '')
|
&& (ini_get('mbstring.func_overload') !== '')
|
||||||
&& ((int)ini_get('mbstring.func_overload') & 2));
|
&& ((int) ini_get('mbstring.func_overload') & 2));
|
||||||
if ($hasMbOverload) {
|
if ($hasMbOverload) {
|
||||||
$mbIntEnc = mb_internal_encoding();
|
$mbIntEnc = mb_internal_encoding();
|
||||||
mb_internal_encoding('8bit');
|
mb_internal_encoding('8bit');
|
||||||
@@ -174,7 +176,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
return null; // Not GZIP format (See RFC 1952)
|
return null; // Not GZIP format (See RFC 1952)
|
||||||
}
|
}
|
||||||
$method = ord(substr($data, 2, 1)); // Compression method
|
$method = ord(substr($data, 2, 1)); // Compression method
|
||||||
$flags = ord(substr($data, 3, 1)); // Flags
|
$flags = ord(substr($data, 3, 1)); // Flags
|
||||||
if ($flags & 31 != $flags) {
|
if ($flags & 31 != $flags) {
|
||||||
$error = "Reserved bits not allowed.";
|
$error = "Reserved bits not allowed.";
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
@@ -185,11 +187,11 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
// NOTE: $mtime may be negative (PHP integer limitations)
|
// NOTE: $mtime may be negative (PHP integer limitations)
|
||||||
$mtime = unpack("V", substr($data, 4, 4));
|
$mtime = unpack("V", substr($data, 4, 4));
|
||||||
$mtime = $mtime[1];
|
$mtime = $mtime[1];
|
||||||
$xfl = substr($data, 8, 1);
|
$xfl = substr($data, 8, 1);
|
||||||
$os = substr($data, 8, 1);
|
$os = substr($data, 8, 1);
|
||||||
$headerlen = 10;
|
$headerlen = 10;
|
||||||
$extralen = 0;
|
$extralen = 0;
|
||||||
$extra = "";
|
$extra = "";
|
||||||
if ($flags & 4) {
|
if ($flags & 4) {
|
||||||
// 2-byte length prefixed EXTRA data in header
|
// 2-byte length prefixed EXTRA data in header
|
||||||
if ($len - $headerlen - 2 < 8) {
|
if ($len - $headerlen - 2 < 8) {
|
||||||
@@ -276,7 +278,7 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$isize = unpack("V", substr($data, -4));
|
$isize = unpack("V", substr($data, -4));
|
||||||
$isize = $isize[1];
|
$isize = $isize[1];
|
||||||
// decompression:
|
// decompression:
|
||||||
$bodylen = $len-$headerlen-8;
|
$bodylen = $len - $headerlen - 8;
|
||||||
if ($bodylen < 1) {
|
if ($bodylen < 1) {
|
||||||
// IMPLEMENTATION BUG!
|
// IMPLEMENTATION BUG!
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
@@ -288,20 +290,20 @@ function _phpman_gzdecode($data, &$filename='', &$error='', $maxlength=null)
|
|||||||
$data = "";
|
$data = "";
|
||||||
if ($bodylen > 0) {
|
if ($bodylen > 0) {
|
||||||
switch ($method) {
|
switch ($method) {
|
||||||
case 8:
|
case 8:
|
||||||
// Currently the only supported compression method:
|
// Currently the only supported compression method:
|
||||||
$data = gzinflate($body, $maxlength);
|
$data = gzinflate($body, $maxlength);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$error = "Unknown compression method.";
|
$error = "Unknown compression method.";
|
||||||
if ($mbIntEnc !== null) {
|
if ($mbIntEnc !== null) {
|
||||||
mb_internal_encoding($mbIntEnc);
|
mb_internal_encoding($mbIntEnc);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} // zero-byte body content is allowed
|
} // zero-byte body content is allowed
|
||||||
// Verifiy CRC32
|
// Verifiy CRC32
|
||||||
$crc = sprintf("%u", crc32($data));
|
$crc = sprintf("%u", crc32($data));
|
||||||
$crcOK = $crc == $datacrc;
|
$crcOK = $crc == $datacrc;
|
||||||
$lenOK = $isize == strlen($data);
|
$lenOK = $isize == strlen($data);
|
||||||
if (!$lenOK || !$crcOK) {
|
if (!$lenOK || !$crcOK) {
|
||||||
|
@@ -6,7 +6,9 @@ use Minify_HTML_Helper;
|
|||||||
|
|
||||||
class LessSourceTest extends TestCase
|
class LessSourceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public string $realDocRoot;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
||||||
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
||||||
|
@@ -6,7 +6,7 @@ use Minify_CSS_UriRewriter;
|
|||||||
|
|
||||||
class MinifyCSSUriRewriterTest extends TestCase
|
class MinifyCSSUriRewriterTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
Minify_CSS_UriRewriter::$debugText = '';
|
Minify_CSS_UriRewriter::$debugText = '';
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,7 @@ use Minify_Cache_APC;
|
|||||||
|
|
||||||
class MinifyCacheAPCTest extends TestCase
|
class MinifyCacheAPCTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (!function_exists('apc_store')) {
|
if (!function_exists('apc_store')) {
|
||||||
$this->markTestSkipped("To test this component, install APC extension");
|
$this->markTestSkipped("To test this component, install APC extension");
|
||||||
|
@@ -6,7 +6,7 @@ use Minify_Cache_APCu;
|
|||||||
|
|
||||||
class MinifyCacheAPCuTest extends TestCase
|
class MinifyCacheAPCuTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (!function_exists('apcu_store')) {
|
if (!function_exists('apcu_store')) {
|
||||||
$this->markTestSkipped("To test this component, install APCu extension");
|
$this->markTestSkipped("To test this component, install APCu extension");
|
||||||
|
@@ -10,7 +10,7 @@ class MinifyCacheMemcacheTest extends TestCase
|
|||||||
/** @var Memcache */
|
/** @var Memcache */
|
||||||
private $mc;
|
private $mc;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (!function_exists('memcache_set')) {
|
if (!function_exists('memcache_set')) {
|
||||||
$this->markTestSkipped("To test this component, install memcache in PHP");
|
$this->markTestSkipped("To test this component, install memcache in PHP");
|
||||||
|
@@ -6,7 +6,7 @@ use Minify_Cache_WinCache;
|
|||||||
|
|
||||||
class MinifyCacheWinCacheTest extends TestCase
|
class MinifyCacheWinCacheTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (!function_exists('wincache_ucache_info')) {
|
if (!function_exists('wincache_ucache_info')) {
|
||||||
$this->markTestSkipped("To test this component, install WinCache extension");
|
$this->markTestSkipped("To test this component, install WinCache extension");
|
||||||
|
@@ -6,7 +6,7 @@ use Minify_Cache_ZendPlatform;
|
|||||||
|
|
||||||
class MinifyCacheZendPlatformTest extends TestCase
|
class MinifyCacheZendPlatformTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
if (!function_exists('output_cache_put')) {
|
if (!function_exists('output_cache_put')) {
|
||||||
// FIXME: be specific what to actually install
|
// FIXME: be specific what to actually install
|
||||||
|
@@ -7,7 +7,7 @@ use Minify_ClosureCompiler;
|
|||||||
|
|
||||||
class MinifyClosureCompilerTest extends TestCase
|
class MinifyClosureCompilerTest extends TestCase
|
||||||
{
|
{
|
||||||
public static function setupBeforeClass()
|
public static function setupBeforeClass(): void
|
||||||
{
|
{
|
||||||
parent::setupBeforeClass();
|
parent::setupBeforeClass();
|
||||||
Minify_ClosureCompiler::$isDebug = true;
|
Minify_ClosureCompiler::$isDebug = true;
|
||||||
|
@@ -9,14 +9,14 @@ class MinifyHTMLHelperTest extends TestCase
|
|||||||
{
|
{
|
||||||
private $realDocRoot;
|
private $realDocRoot;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
||||||
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: this is probably not needed if backupGlobals is enabled?
|
// TODO: this is probably not needed if backupGlobals is enabled?
|
||||||
public function tearDown()
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
$_SERVER['DOCUMENT_ROOT'] = $this->realDocRoot;
|
$_SERVER['DOCUMENT_ROOT'] = $this->realDocRoot;
|
||||||
}
|
}
|
||||||
@@ -43,13 +43,16 @@ class MinifyHTMLHelperTest extends TestCase
|
|||||||
$this->assertEquals($expected, $actual, 'non-existent group & debug');
|
$this->assertEquals($expected, $actual, 'non-existent group & debug');
|
||||||
|
|
||||||
$expected = "/myApp/min/?g=css&{$maxTime}";
|
$expected = "/myApp/min/?g=css&{$maxTime}";
|
||||||
$actual = Minify_HTML_Helper::getUri('css', array(
|
$actual = Minify_HTML_Helper::getUri(
|
||||||
'rewriteWorks' => false
|
'css',
|
||||||
,
|
array(
|
||||||
'minAppUri' => '/myApp/min/'
|
'rewriteWorks' => false
|
||||||
,
|
,
|
||||||
'groupsConfigFile' => self::$test_files . '/htmlHelper_groupsConfig.php'
|
'minAppUri' => '/myApp/min/'
|
||||||
));
|
,
|
||||||
|
'groupsConfigFile' => self::$test_files . '/htmlHelper_groupsConfig.php'
|
||||||
|
)
|
||||||
|
);
|
||||||
$this->assertEquals($expected, $actual, 'existing group');
|
$this->assertEquals($expected, $actual, 'existing group');
|
||||||
|
|
||||||
|
|
||||||
@@ -58,25 +61,32 @@ class MinifyHTMLHelperTest extends TestCase
|
|||||||
require_once $utilsFile;
|
require_once $utilsFile;
|
||||||
|
|
||||||
$fiveSecondsAgo = $_SERVER['REQUEST_TIME'] - 5;
|
$fiveSecondsAgo = $_SERVER['REQUEST_TIME'] - 5;
|
||||||
$obj = new Minify_Source(array(
|
$obj = new Minify_Source(
|
||||||
'id' => '1',
|
array(
|
||||||
'content' => '1',
|
'id' => '1',
|
||||||
'lastModified' => $fiveSecondsAgo,
|
'content' => '1',
|
||||||
));
|
'lastModified' => $fiveSecondsAgo,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$output = Minify_mtime(array($uri1, $uri2, $obj));
|
$output = Minify_mtime(array($uri1, $uri2, $obj));
|
||||||
$this->assertEquals($fiveSecondsAgo, $output, 'utils.php : Minify_mtime w/ files & obj');
|
$this->assertEquals($fiveSecondsAgo, $output, 'utils.php : Minify_mtime w/ files & obj');
|
||||||
|
|
||||||
$obj = new Minify_Source(array(
|
$obj = new Minify_Source(
|
||||||
'id' => '2',
|
array(
|
||||||
'content' => '2',
|
'id' => '2',
|
||||||
'lastModified' => strtotime('2000-01-01'),
|
'content' => '2',
|
||||||
));
|
'lastModified' => strtotime('2000-01-01'),
|
||||||
$output = Minify_mtime(array(
|
)
|
||||||
$obj
|
);
|
||||||
,
|
$output = Minify_mtime(
|
||||||
'css'
|
array(
|
||||||
), self::$test_files . '/htmlHelper_groupsConfig.php');
|
$obj
|
||||||
|
,
|
||||||
|
'css'
|
||||||
|
),
|
||||||
|
self::$test_files . '/htmlHelper_groupsConfig.php'
|
||||||
|
);
|
||||||
$this->assertEquals($maxTime, $output, 'utils.php : Minify_mtime w/ obj & group');
|
$this->assertEquals($maxTime, $output, 'utils.php : Minify_mtime w/ obj & group');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,7 @@ use Minify_NailgunClosureCompiler;
|
|||||||
|
|
||||||
class MinifyNailgunClosureCompilerTest extends TestCase
|
class MinifyNailgunClosureCompilerTest extends TestCase
|
||||||
{
|
{
|
||||||
public static function setupBeforeClass()
|
public static function setupBeforeClass(): void
|
||||||
{
|
{
|
||||||
parent::setupBeforeClass();
|
parent::setupBeforeClass();
|
||||||
Minify_ClosureCompiler::$isDebug = true;
|
Minify_ClosureCompiler::$isDebug = true;
|
||||||
|
@@ -7,7 +7,7 @@ use Minify_YUICompressor;
|
|||||||
|
|
||||||
class MinifyYuiCSSTest extends TestCase
|
class MinifyYuiCSSTest extends TestCase
|
||||||
{
|
{
|
||||||
public static function setupBeforeClass()
|
public static function setupBeforeClass(): void
|
||||||
{
|
{
|
||||||
parent::setupBeforeClass();
|
parent::setupBeforeClass();
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ class MinifyYuiCSSTest extends TestCase
|
|||||||
Minify_YUICompressor::$tempDir = sys_get_temp_dir();
|
Minify_YUICompressor::$tempDir = sys_get_temp_dir();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->assertHasJar();
|
$this->assertHasJar();
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,9 @@ use Minify_HTML_Helper;
|
|||||||
|
|
||||||
class ScssSourceTest extends TestCase
|
class ScssSourceTest extends TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public string $realDocRoot;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
$this->realDocRoot = $_SERVER['DOCUMENT_ROOT'];
|
||||||
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
$_SERVER['DOCUMENT_ROOT'] = self::$document_root;
|
||||||
|
@@ -11,7 +11,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
/** @var string */
|
/** @var string */
|
||||||
protected static $test_files;
|
protected static $test_files;
|
||||||
|
|
||||||
public static function setupBeforeClass()
|
public static function setupBeforeClass(): void
|
||||||
{
|
{
|
||||||
self::$document_root = __DIR__;
|
self::$document_root = __DIR__;
|
||||||
self::$test_files = __DIR__ . '/_test_files';
|
self::$test_files = __DIR__ . '/_test_files';
|
||||||
@@ -25,7 +25,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
|
|||||||
*/
|
*/
|
||||||
protected function countBytes($str)
|
protected function countBytes($str)
|
||||||
{
|
{
|
||||||
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
|
return (function_exists('mb_strlen') && ((int) ini_get('mbstring.func_overload') & 2))
|
||||||
? mb_strlen($str, '8bit')
|
? mb_strlen($str, '8bit')
|
||||||
: strlen($str);
|
: strlen($str);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user