|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * PhpUnderControl_PhalApiCacheFile_Test
- *
- * 针对 ../../PhalApi/Cache/File.php PhalApi_Cache_File 类的PHPUnit单元测试
- *
- * @author: dogstar 20150226
- */
-
- require_once dirname(__FILE__) . '/../test_env.php';
-
- if (!class_exists('PhalApi_Cache_File')) {
- require dirname(__FILE__) . '/../../PhalApi/Cache/File.php';
- }
-
- class PhpUnderControl_PhalApiCacheFile_Test extends PHPUnit_Framework_TestCase
- {
- public $phalApiCacheFile;
-
- protected function setUp()
- {
- parent::setUp();
-
- @unlink(dirname(__FILE__) . '/cache');
-
- $config['path'] = dirname(__FILE__);
- $this->phalApiCacheFile = new PhalApi_Cache_File($config);
- }
-
- protected function tearDown()
- {
- }
-
-
- /**
- * @group testSet
- */
- public function testSet()
- {
- $key = 'aYearKey';
- $value = 2015;
- $expire = '200';
-
- $rs = $this->phalApiCacheFile->set($key, $value, $expire);
- }
-
- /**
- * @group testGet
- * @depends testSet
- */
- public function testGet()
- {
- $key = 'aYearKey';
-
- $rs = $this->phalApiCacheFile->get($key);
-
- $this->assertSame(2015, $rs);
- }
-
- /**
- * @group testDelete
- * @depends testSet
- */
- public function testDelete()
- {
- $key = 'aYearKey';
-
- $this->phalApiCacheFile->delete($key);
-
- $rs = $this->phalApiCacheFile->get($key);
-
- $this->assertSame(NULL, $rs);
- }
-
- public function testGetAfterSet()
- {
- $key = 'anotherKey';
-
- $value = array('name' => 'dogstar');
-
- $this->phalApiCacheFile->set($key, $value);
-
- $this->assertSame($value, $this->phalApiCacheFile->get($key));
- }
-
- public function testExpire()
- {
- $key = 'tmpKey';
- $value = 'somethinghere~';
- $expire = 2;
-
- $this->phalApiCacheFile->set($key, $value, $expire);
-
- $this->assertSame($value, $this->phalApiCacheFile->get($key));
-
- sleep(3);
-
- $this->assertSame(NULL, $this->phalApiCacheFile->get($key));
- }
-
- }
|