mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
添加缓存类静态调用测试方法
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
namespace tests\thinkphp\library\think\cache\driver;
|
namespace tests\thinkphp\library\think\cache\driver;
|
||||||
|
|
||||||
use think\cache;
|
use think\Cache;
|
||||||
|
|
||||||
abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@@ -26,12 +26,14 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
abstract protected function getCacheInstance();
|
abstract protected function getCacheInstance();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tearDown函数
|
* tearDown函数
|
||||||
*/
|
*/
|
||||||
protected function tearDown()
|
protected function tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设定一组测试值,包括测试字符串、整数、数组和对象
|
* 设定一组测试值,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -46,6 +48,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$cache->set('array_test', ['array_test' => 'array_test']);
|
$cache->set('array_test', ['array_test' => 'array_test']);
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存设置,包括测试字符串、整数、数组和对象
|
* 测试缓存设置,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -58,6 +61,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($cache->set('number_test', 11));
|
$this->assertTrue($cache->set('number_test', 11));
|
||||||
$this->assertTrue($cache->set('array_test', ['array_test' => 'array_test']));
|
$this->assertTrue($cache->set('array_test', ['array_test' => 'array_test']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存读取,包括测试字符串、整数、数组和对象
|
* 测试缓存读取,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -72,6 +76,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertArrayHasKey('array_test', $array);
|
$this->assertArrayHasKey('array_test', $array);
|
||||||
$this->assertEquals('array_test', $array['array_test']);
|
$this->assertEquals('array_test', $array['array_test']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存存在情况,包括测试字符串、整数、数组和对象
|
* 测试缓存存在情况,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -84,6 +89,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotEmpty($cache->get('number_test'));
|
$this->assertNotEmpty($cache->get('number_test'));
|
||||||
$this->assertFalse($cache->get('not_exists'));
|
$this->assertFalse($cache->get('not_exists'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试缓存不存在情况,包括测试字符串、整数、数组和对象
|
* 测试缓存不存在情况,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -94,6 +100,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$cache = $this->getCacheInstance();
|
$cache = $this->getCacheInstance();
|
||||||
$this->assertFalse($cache->get('non_existent_key'));
|
$this->assertFalse($cache->get('non_existent_key'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试特殊值缓存,包括测试字符串、整数、数组和对象
|
* 测试特殊值缓存,包括测试字符串、整数、数组和对象
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -106,6 +113,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
//清空缓存后,返回null而不是false
|
//清空缓存后,返回null而不是false
|
||||||
$this->assertTrue(is_null($cache->get('null_value')));
|
$this->assertTrue(is_null($cache->get('null_value')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存过期测试
|
* 缓存过期测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -120,6 +128,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
usleep(800000);
|
usleep(800000);
|
||||||
$this->assertFalse($cache->get('expire_test'));
|
$this->assertFalse($cache->get('expire_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除缓存测试
|
* 删除缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -131,6 +140,7 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotNull($cache->rm('number_test'));
|
$this->assertNotNull($cache->rm('number_test'));
|
||||||
$this->assertFalse($cache->get('number_test'));
|
$this->assertFalse($cache->get('number_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清空缓存测试
|
* 清空缓存测试
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@@ -142,4 +152,11 @@ abstract class cacheTestCase extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($cache->clear());
|
$this->assertTrue($cache->clear());
|
||||||
$this->assertFalse($cache->get('number_test'));
|
$this->assertFalse($cache->get('number_test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testStaticCall()
|
||||||
|
{
|
||||||
|
$this->assertTrue(Cache::set('a', 'a'));
|
||||||
|
$this->assertEquals('a', Cache::get('a'));
|
||||||
|
$this->assertTrue(Cache::rm('a'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user