1
0
mirror of https://github.com/mrclay/minify.git synced 2025-03-12 16:39:38 +01:00

port MinifyCacheFileTest to phpunit

This commit is contained in:
Elan Ruusamäe 2015-11-19 18:41:27 +02:00 committed by Steve Clay
parent ed79a279a9
commit 554542401f
3 changed files with 40 additions and 51 deletions

View File

@ -1,50 +0,0 @@
<?php
require_once '_inc.php';
function test_Minify_Cache_File()
{
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
$id = 'Minify_test_cache_noLock';
$prefix = 'Minify_Cache_File : ';
$cache = new Minify_Cache_File();
echo " Minify_Cache_File : path is set to: '" . $cache->getPath() . "'.\n";
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');
// test with locks
$id = 'Minify_test_cache_withLock';
$cache = new Minify_Cache_File('', true);
assertTrue(true === $cache->store($id, $data), $prefix . 'store w/ lock');
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 w/ lock');
assertTrue($data === $cache->fetch($id), $prefix . 'fetch w/ lock');
}
test_Minify_Cache_File();

View File

@ -3,7 +3,6 @@
require 'test_Minify.php';
require 'test_Minify_HTML_Helper.php';
require 'test_Minify_Cache_APC.php';
require 'test_Minify_Cache_File.php';
require 'test_Minify_Cache_Memcache.php';
require 'test_Minify_Cache_WinCache.php';
require 'test_Minify_Cache_ZendPlatform.php';

View File

@ -0,0 +1,40 @@
<?php
class MinifyCacheFileTest extends TestCase
{
public function test1()
{
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
$id = 'Minify_test_cache_noLock';
$cache = new Minify_Cache_File();
$this->assertTestCache($cache, $id, $data);
}
/**
* test with locks
*/
public function test2()
{
$data = str_repeat(md5(time()) . 'í', 100); // 3400 bytes in UTF-8
$id = 'Minify_test_cache_withLock';
$cache = new Minify_Cache_File('', true);
$this->assertTestCache($cache, $id, $data);
}
private function assertTestCache(Minify_Cache_File $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");
}
}