1
0
mirror of https://github.com/mrclay/minify.git synced 2025-01-17 13:18:13 +01:00
minify/tests/TestCase.php

58 lines
1.5 KiB
PHP
Raw Normal View History

2015-11-18 17:17:43 +02:00
<?php
class TestCase extends PHPUnit_Framework_TestCase
{
/** @var string */
protected static $test_files;
public static function setupBeforeClass()
{
self::$test_files = __DIR__ . '/../min_unit_tests/_test_files';
}
2015-11-19 11:22:57 +02:00
/**
* Get number of bytes in a string regardless of mbstring.func_overload
*
* @param string $str
* @return int
*/
protected function countBytes($str)
{
return (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2))
? mb_strlen($str, '8bit')
: strlen($str);
}
/**
* Excluding from phpunit.xml does not work, even using dir,
* hence this dummy test.
*
* @link http://stackoverflow.com/q/2736343/2314626
*/
public function test_does_nothing()
{
}
/**
* Common assertion for cache tests.
*
* @param Minify_CacheInterface $cache
* @param string $id
* @param string $data
*/
protected function assertTestCache(Minify_CacheInterface $cache, $id, $data)
{
$this->assertTrue($cache->store($id, $data), "$id store");
$this->assertEquals($cache->getSize($id), $this->countBytes($data), "$id getSize");
$this->assertTrue($cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), "$id isValid");
ob_start();
$cache->display($id);
$displayed = ob_get_contents();
ob_end_clean();
$this->assertSame($data, $displayed, "$id display");
$this->assertEquals($data, $cache->fetch($id), "$id fetch");
}
2015-11-18 17:17:43 +02:00
}