mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 14:52:47 +08:00
移动 tests 到 thinkphp 目录
This commit is contained in:
135
tests/thinkphp/library/think/cache/driver/CacheTestCase.php
vendored
Normal file
135
tests/thinkphp/library/think/cache/driver/CacheTestCase.php
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace tests\thinkphp\library\think\cache\driver;
|
||||
|
||||
use think\cache;
|
||||
|
||||
/**
|
||||
* 缓存抽象类,提供一些测试
|
||||
* @author simon <mahuan@d1web.top>
|
||||
*/
|
||||
abstract class CacheTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* 获取缓存句柄,子类必须有
|
||||
* @access protected
|
||||
*/
|
||||
abstract protected function getCacheInstance();
|
||||
/**
|
||||
* tearDown函数
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* 设定一组测试值,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function prepare()
|
||||
{
|
||||
$cache = $this->getCacheInstance();
|
||||
$cache->clear();
|
||||
$cache->set('string_test', 'string_test');
|
||||
$cache->set('number_test', 11);
|
||||
$cache->set('array_test', ['array_test' => 'array_test']);
|
||||
return $cache;
|
||||
}
|
||||
/**
|
||||
* 测试缓存设置,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testSet()
|
||||
{
|
||||
$cache = $this->getCacheInstance();
|
||||
$this->assertTrue($cache->set('string_test', 'string_test'));
|
||||
$this->assertTrue($cache->set('number_test', 11));
|
||||
$this->assertTrue($cache->set('array_test', ['array_test' => 'array_test']));
|
||||
}
|
||||
/**
|
||||
* 测试缓存读取,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
$cache = $this->prepare();
|
||||
$this->assertEquals('string_test', $cache->get('string_test'));
|
||||
$this->assertEquals(11, $cache->get('number_test'));
|
||||
$array = $cache->get('array_test');
|
||||
$this->assertArrayHasKey('array_test', $array);
|
||||
$this->assertEquals('array_test', $array['array_test']);
|
||||
}
|
||||
/**
|
||||
* 测试缓存存在情况,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testExists()
|
||||
{
|
||||
$cache = $this->prepare();
|
||||
$this->assertNotEmpty($cache->get('string_test'));
|
||||
$this->assertNotEmpty($cache->get('number_test'));
|
||||
$this->assertFalse($cache->get('not_exists'));
|
||||
}
|
||||
/**
|
||||
* 测试缓存不存在情况,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testGetNonExistent()
|
||||
{
|
||||
$cache = $this->getCacheInstance();
|
||||
$this->assertFalse($cache->get('non_existent_key'));
|
||||
}
|
||||
/**
|
||||
* 测试特殊值缓存,包括测试字符串、整数、数组和对象
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testStoreSpecialValues()
|
||||
{
|
||||
$cache = $this->getCacheInstance();
|
||||
$cache->set('null_value', null);
|
||||
//清空缓存后,返回null而不是false
|
||||
$this->assertTrue(is_null($cache->get('null_value')));
|
||||
}
|
||||
/**
|
||||
* 缓存过期测试
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testExpire()
|
||||
{
|
||||
$cache = $this->getCacheInstance();
|
||||
$this->assertTrue($cache->set('expire_test', 'expire_test', 2));
|
||||
usleep(500000);
|
||||
$this->assertEquals('expire_test', $cache->get('expire_test'));
|
||||
usleep(2500000);
|
||||
$this->assertFalse($cache->get('expire_test'));
|
||||
}
|
||||
/**
|
||||
* 删除缓存测试
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$cache = $this->prepare();
|
||||
$this->assertNotNull($cache->rm('number_test'));
|
||||
$this->assertFalse($cache->get('number_test'));
|
||||
}
|
||||
/**
|
||||
* 清空缓存测试
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testClear()
|
||||
{
|
||||
$cache = $this->prepare();
|
||||
$this->assertTrue($cache->clear());
|
||||
$this->assertFalse($cache->get('number_test'));
|
||||
}
|
||||
}
|
||||
50
tests/thinkphp/library/think/cache/driver/apcTest.php
vendored
Normal file
50
tests/thinkphp/library/think/cache/driver/apcTest.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Apc缓存驱动测试
|
||||
* @author mahuan <mahuan@d1web.top>
|
||||
*/
|
||||
namespace tests\thinkphp\library\think\cache\driver;
|
||||
|
||||
class apcTest extends CacheTestCase
|
||||
{
|
||||
private $_cacheInstance = null;
|
||||
/**
|
||||
* 基境缓存类型
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
\think\Cache::connect(array('type' => 'apc', 'expire' => 2));
|
||||
}
|
||||
/**
|
||||
* @return ApcCache
|
||||
*/
|
||||
protected function getCacheInstance()
|
||||
{
|
||||
if (!extension_loaded("apc")) {
|
||||
$this->markTestSkipped("APC没有安装,已跳过测试!");
|
||||
} elseif ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
|
||||
$this->markTestSkipped("APC模块没有开启,已跳过测试!");
|
||||
}
|
||||
if (null === $this->_cacheInstance) {
|
||||
$this->_cacheInstance = new \think\cache\driver\Apc();
|
||||
}
|
||||
return $this->_cacheInstance;
|
||||
}
|
||||
/**
|
||||
* 缓存过期测试《提出来测试,因为目前看通不过缓存过期测试,所以还需研究》
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public function testExpire()
|
||||
{
|
||||
}
|
||||
}
|
||||
42
tests/thinkphp/library/think/cache/driver/dbTest.php
vendored
Normal file
42
tests/thinkphp/library/think/cache/driver/dbTest.php
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 数据库缓存驱动测试
|
||||
* @author mahuan <mahuan@d1web.top>
|
||||
*/
|
||||
namespace tests\thinkphp\library\think\cache\driver;
|
||||
|
||||
class dbTest extends CacheTestCase
|
||||
{
|
||||
private $_cacheInstance = null;
|
||||
|
||||
/**
|
||||
* 基境缓存类型
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
//数据库缓存测试因为缺少数据库单元测试所以暂时跳过
|
||||
$this->markTestSkipped("暂时跳过测试。");
|
||||
\think\Cache::connect(array('type' => 'db', 'expire' => 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DbCache
|
||||
*/
|
||||
protected function getCacheInstance()
|
||||
{
|
||||
if (null === $this->_cacheInstance) {
|
||||
$this->_cacheInstance = new \think\cache\driver\Db();
|
||||
}
|
||||
return $this->_cacheInstance;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user