-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalContextCacheTest.php
More file actions
53 lines (43 loc) · 1.58 KB
/
LocalContextCacheTest.php
File metadata and controls
53 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php declare(strict_types=1);
namespace Tests\ContextCache;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-context-cache\ContextCache\LocalContextCache
*
* @author fdipzone
*/
final class LocalContextCacheTest extends TestCase
{
/**
* @covers \ContextCache\LocalContextCache::put
* @covers \ContextCache\LocalContextCache::get
* @covers \ContextCache\LocalContextCache::remove
* @covers \ContextCache\LocalContextCache::clear
*/
public function testCache()
{
$key = 'name';
$value = 'fdipzone';
$local_context_cache = new \ContextCache\LocalContextCache;
// 测试设置缓存
$ret = $local_context_cache->put($key, $value);
$this->assertTrue($ret);
// 测试获取缓存
$data = $local_context_cache->get($key);
$this->assertEquals($value, $data);
// 测试获取不存在的缓存
$data = $local_context_cache->get('not_exists_key');
$this->assertNull($data);
// 测试移除缓存
$ret = $local_context_cache->remove($key);
$this->assertTrue($ret);
// 测试移除不存在的缓存
$ret = $local_context_cache->remove('not_exists_key');
$this->assertFalse($ret);
// 测试清空所有缓存
$local_context_cache->put($key, $value);
$this->assertSame(1, count(\Tests\Utils\PHPUnitExtension::getVariable($local_context_cache, 'cache')));
$local_context_cache->clear();
$this->assertSame(0, count(\Tests\Utils\PHPUnitExtension::getVariable($local_context_cache, 'cache')));
}
}