1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Common\Cache; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\Cache; |
6
|
|
|
use Doctrine\Common\Cache\PhpFileCache; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @group DCOM-101 |
10
|
|
|
*/ |
11
|
|
|
class PhpFileCacheTest extends BaseFileCacheTest |
12
|
|
|
{ |
13
|
|
|
public function provideDataToCache() |
14
|
|
|
{ |
15
|
|
|
$data = parent::provideDataToCache(); |
16
|
|
|
|
17
|
|
|
unset($data['object'], $data['object_recursive']); // PhpFileCache only allows objects that implement __set_state() and fully support var_export() |
18
|
|
|
|
19
|
|
|
if (PHP_VERSION_ID < 70002) { |
20
|
|
|
unset($data['float_zero']); // var_export exports float(0) as int(0): https://bugs.php.net/bug.php?id=66179 |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
return $data; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testImplementsSetState() |
27
|
|
|
{ |
28
|
|
|
$cache = $this->_getCacheDriver(); |
29
|
|
|
|
30
|
|
|
// Test save |
31
|
|
|
$cache->save('test_set_state', new SetStateClass([1,2,3])); |
32
|
|
|
|
33
|
|
|
//Test __set_state call |
34
|
|
|
$this->assertCount(0, SetStateClass::$values); |
35
|
|
|
|
36
|
|
|
// Test fetch |
37
|
|
|
$value = $cache->fetch('test_set_state'); |
38
|
|
|
$this->assertInstanceOf('Doctrine\Tests\Common\Cache\SetStateClass', $value); |
39
|
|
|
$this->assertEquals([1,2,3], $value->getValue()); |
40
|
|
|
|
41
|
|
|
//Test __set_state call |
42
|
|
|
$this->assertCount(1, SetStateClass::$values); |
43
|
|
|
|
44
|
|
|
// Test contains |
45
|
|
|
$this->assertTrue($cache->contains('test_set_state')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @group 154 |
50
|
|
|
*/ |
51
|
|
|
public function testNotImplementsSetState() |
52
|
|
|
{ |
53
|
|
|
$cache = $this->_getCacheDriver(); |
54
|
|
|
|
55
|
|
|
$cache->save('test_not_set_state', new NotSetStateClass([5,6,7])); |
56
|
|
|
$this->assertEquals(new NotSetStateClass([5,6,7]), $cache->fetch('test_not_set_state')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @group 154 |
61
|
|
|
*/ |
62
|
|
|
public function testNotImplementsSetStateInArray() |
63
|
|
|
{ |
64
|
|
|
$cache = $this->_getCacheDriver(); |
65
|
|
|
|
66
|
|
|
$cache->save('test_not_set_state_in_array', [new NotSetStateClass([4,3,2])]); |
67
|
|
|
$this->assertEquals([new NotSetStateClass([4,3,2])], $cache->fetch('test_not_set_state_in_array')); |
68
|
|
|
$this->assertTrue($cache->contains('test_not_set_state_in_array')); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testGetStats() |
72
|
|
|
{ |
73
|
|
|
$cache = $this->_getCacheDriver(); |
74
|
|
|
$stats = $cache->getStats(); |
75
|
|
|
|
76
|
|
|
$this->assertNull($stats[Cache::STATS_HITS]); |
77
|
|
|
$this->assertNull($stats[Cache::STATS_MISSES]); |
78
|
|
|
$this->assertNull($stats[Cache::STATS_UPTIME]); |
79
|
|
|
$this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]); |
80
|
|
|
$this->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_AVAILABLE]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function _getCacheDriver() |
84
|
|
|
{ |
85
|
|
|
return new PhpFileCache($this->directory); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
class NotSetStateClass |
90
|
|
|
{ |
91
|
|
|
private $value; |
92
|
|
|
|
93
|
|
|
public function __construct($value) |
94
|
|
|
{ |
95
|
|
|
$this->value = $value; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getValue() |
99
|
|
|
{ |
100
|
|
|
return $this->value; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
class SetStateClass extends NotSetStateClass |
105
|
|
|
{ |
106
|
|
|
public static $values = []; |
107
|
|
|
|
108
|
|
|
public static function __set_state($data) |
109
|
|
|
{ |
110
|
|
|
self::$values = $data; |
111
|
|
|
return new self($data['value']); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|