-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheTest.php
More file actions
60 lines (52 loc) · 1.65 KB
/
CacheTest.php
File metadata and controls
60 lines (52 loc) · 1.65 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
54
55
56
57
58
59
60
<?php declare(strict_types=1);
namespace Tests\ContextCache;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-context-cache\ContextCache\Cache
*
* @author fdipzone
*/
final class CacheTest extends TestCase
{
/**
* @covers \ContextCache\Cache::getCacheClass
*/
public function testGetCacheClass()
{
$type = \ContextCache\Type::LOCAL;
$class = \ContextCache\Cache::getCacheClass($type);
$this->assertEquals('\ContextCache\LocalContextCache', $class);
}
/**
* @covers \ContextCache\Cache::getCacheClass
*/
public function testGetCacheClassException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage(sprintf('%s type cache not exists', 'not_exists_type'));
$type = 'not_exists_type';
\ContextCache\Cache::getCacheClass($type);
}
/**
* @covers \ContextCache\Cache::getInstance
*/
public function testGetInstance()
{
$type = \ContextCache\Type::LOCAL;
$context_cache = \ContextCache\Cache::getInstance($type);
$this->assertEquals('ContextCache\LocalContextCache', get_class($context_cache));
// 测试单例
$context_cache2 = \ContextCache\Cache::getInstance($type);
$this->assertSame($context_cache, $context_cache2);
}
/**
* @covers \ContextCache\Cache::getInstance
*/
public function testGetInstanceException()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage(sprintf('%s type cache not exists', 'not_exists_type'));
$type = 'not_exists_type';
\ContextCache\Cache::getInstance($type);
}
}