From 202a399634a6f0de139020f7538bbdb6c909f6b4 Mon Sep 17 00:00:00 2001 From: chunice Date: Mon, 7 Mar 2016 17:22:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=8C=E5=96=84File=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/think/cache/driver/fileTest.php | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tests/thinkphp/library/think/cache/driver/fileTest.php b/tests/thinkphp/library/think/cache/driver/fileTest.php index 1b2d3c6f..91cfab4f 100644 --- a/tests/thinkphp/library/think/cache/driver/fileTest.php +++ b/tests/thinkphp/library/think/cache/driver/fileTest.php @@ -25,7 +25,7 @@ class fileTest extends cacheTestCase */ protected function setUp() { - \think\Cache::connect(array('type' => 'File', 'expire' => 2)); + \think\Cache::connect(['type' => 'File', 'path'=> CACHE_PATH]); } /** @@ -34,21 +34,26 @@ class fileTest extends cacheTestCase protected function getCacheInstance() { if (null === $this->_cacheInstance) { - $this->_cacheInstance = new \think\cache\driver\File([ - 'expire'=>2, - 'path'=> CACHE_PATH, - ]); + $this->_cacheInstance = new \think\cache\driver\File(); } return $this->_cacheInstance; } - // 待调整后测试 + // rewrite testQueue + public function testQueue() + { + $cache = $this->prepare(); + $this->assertTrue($cache->set('1', '1')); + $this->assertTrue($cache->set('2', '2')); + $this->assertTrue($cache->set('3', '3')); + $this->assertEquals(1, $cache->get('1')); + $this->assertTrue($cache->set('4', '4')); + $this->assertTrue($cache->set('1', false)); + $this->assertFalse($cache->get('1')); + } + + // skip testExpire public function testExpire() { } - - public function testQueue() - { - } - } From 7cb626e48536e06077ad81951d790232ad3a2eb0 Mon Sep 17 00:00:00 2001 From: chunice Date: Mon, 7 Mar 2016 17:37:49 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Memcache=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=A9=B1=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/cache/driver/memcacheTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/thinkphp/library/think/cache/driver/memcacheTest.php diff --git a/tests/thinkphp/library/think/cache/driver/memcacheTest.php b/tests/thinkphp/library/think/cache/driver/memcacheTest.php new file mode 100644 index 00000000..15dfaa5a --- /dev/null +++ b/tests/thinkphp/library/think/cache/driver/memcacheTest.php @@ -0,0 +1,49 @@ + +// +---------------------------------------------------------------------- + +/** + * Memcache缓存驱动测试 + * @author 刘志淳 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +class memcacheTest extends cacheTestCase +{ + private $_cacheInstance = null; + + /** + * 基境缓存类型 + */ + protected function setUp() + { + if (!extension_loaded('memcache')) { + $this->markTestSkipped("Memcache没有安装,已跳过测试!"); + } + \think\Cache::connect(['type' => 'memcache', 'expire' => 2]); + } + + /** + * @return ApcCache + */ + protected function getCacheInstance() + { + if (null === $this->_cacheInstance) { + $this->_cacheInstance = new \think\cache\driver\Memcache(['length' => 3]); + } + return $this->_cacheInstance; + } + + // skip testExpire + public function testExpire() + { + } +} From e3b6ba6babc53d1e7f1dc8b2c3f3e60139a829b5 Mon Sep 17 00:00:00 2001 From: chunice Date: Mon, 7 Mar 2016 17:54:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A2=9E=E5=8A=A0test=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E9=A9=B1=E5=8A=A8=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../library/think/cache/driver/testTest.php | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/thinkphp/library/think/cache/driver/testTest.php diff --git a/tests/thinkphp/library/think/cache/driver/testTest.php b/tests/thinkphp/library/think/cache/driver/testTest.php new file mode 100644 index 00000000..cb6ae573 --- /dev/null +++ b/tests/thinkphp/library/think/cache/driver/testTest.php @@ -0,0 +1,70 @@ + +// +---------------------------------------------------------------------- + +/** + * Test缓存驱动测试 + * @author 刘志淳 + */ + +namespace tests\thinkphp\library\think\cache\driver; + +use think\Cache; + +class testTest extends \PHPUnit_Framework_TestCase +{ + /** + * 测试缓存读取 + * @return mixed + * @access public + */ + public function testGet() + { + $cache = Cache::connect(['type' => 'Test']); + + $this->assertFalse($cache->get('test')); + } + + /** + * 测试缓存设置 + * @return mixed + * @access public + */ + public function testSet() + { + $cache = Cache::connect(['type' => 'Test']); + + $this->assertTrue($cache->set('test', 'test')); + } + + /** + * 删除缓存测试 + * @return mixed + * @access public + */ + public function testRm() + { + $cache = Cache::connect(['type' => 'Test']); + + $this->assertTrue($cache->rm('test')); + } + + /** + * 清空缓存测试 + * @return mixed + * @access public + */ + public function testClear() + { + $cache = Cache::connect(['type' => 'Test']); + + $this->assertTrue($cache->clear()); + } +}