mirror of
https://github.com/mrclay/minify.git
synced 2025-03-13 17:09:39 +01:00
port MinifyCacheMemcacheTest to phpunit
This commit is contained in:
parent
f71dd4c79f
commit
3cb97e2e47
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
function test_Minify_Cache_Memcache()
|
||||
{
|
||||
$prefix = 'Minify_Cache_Memcache : ';
|
||||
$thisFileActive = (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME']));
|
||||
|
||||
if (! function_exists('memcache_set')) {
|
||||
if ($thisFileActive) {
|
||||
echo " {$prefix}To test this component, install memcache in PHP\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
$mc = new Memcache;
|
||||
if (! @$mc->connect('localhost', 11211)) {
|
||||
if ($thisFileActive) {
|
||||
echo " {$prefix}Memcache server not found on localhost:11211\n";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_memcache';
|
||||
$cache = new Minify_Cache_Memcache($mc);
|
||||
|
||||
assertTrue(true === $cache->store($id, $data), $prefix . 'store');
|
||||
|
||||
assertTrue(countBytes($data) === $cache->getSize($id), $prefix . 'getSize');
|
||||
|
||||
assertTrue(true === $cache->isValid($id, $_SERVER['REQUEST_TIME'] - 10), $prefix . 'isValid');
|
||||
|
||||
ob_start();
|
||||
$cache->display($id);
|
||||
$displayed = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
assertTrue($data === $displayed, $prefix . 'display');
|
||||
|
||||
assertTrue($data === $cache->fetch($id), $prefix . 'fetch');
|
||||
|
||||
if (function_exists('gzencode')) {
|
||||
$data = gzencode($data);
|
||||
$id .= ".gz";
|
||||
$cache->store($id, $data);
|
||||
assertTrue($data === $cache->fetch($id), $prefix . 'store/fetch gzencoded string');
|
||||
}
|
||||
}
|
||||
|
||||
test_Minify_Cache_Memcache();
|
43
tests/MinifyCacheMemcacheTest.php
Normal file
43
tests/MinifyCacheMemcacheTest.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class MinifyCacheMemcacheTest extends TestCase
|
||||
{
|
||||
/** @var Memcache */
|
||||
private $mc;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (!function_exists('memcache_set')) {
|
||||
$this->markTestSkipped("To test this component, install memcache in PHP");
|
||||
}
|
||||
|
||||
$this->mc = new Memcache();
|
||||
if (!$this->mc->connect('localhost', 11211)) {
|
||||
$this->markTestSkipped("Memcache server not found on localhost:11211");
|
||||
}
|
||||
}
|
||||
|
||||
public function test1()
|
||||
{
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_memcache';
|
||||
$cache = new Minify_Cache_Memcache($this->mc);
|
||||
|
||||
$this->assertTestCache($cache, $id, $data);
|
||||
}
|
||||
|
||||
public function test2()
|
||||
{
|
||||
if (!function_exists('gzencode')) {
|
||||
$this->markTestSkipped("enable gzip extension to test this");
|
||||
}
|
||||
|
||||
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
|
||||
$id = 'Minify_test_memcache.gz';
|
||||
$cache = new Minify_Cache_Memcache($this->mc);
|
||||
|
||||
$data = gzencode($data);
|
||||
$this->assertTestCache($cache, $id, $data);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user