scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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(array(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(array(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 public function testNotImplementsSetState()
49 {
50 $cache = $this->_getCacheDriver();
51  
52 $this->setExpectedException('InvalidArgumentException');
53 $cache->save('test_not_set_state', new NotSetStateClass(array(1,2,3)));
54 }
55  
56 public function testGetStats()
57 {
58 $cache = $this->_getCacheDriver();
59 $stats = $cache->getStats();
60  
61 $this->assertNull($stats[Cache::STATS_HITS]);
62 $this->assertNull($stats[Cache::STATS_MISSES]);
63 $this->assertNull($stats[Cache::STATS_UPTIME]);
64 $this->assertEquals(0, $stats[Cache::STATS_MEMORY_USAGE]);
65 $this->assertGreaterThan(0, $stats[Cache::STATS_MEMORY_AVAILABLE]);
66 }
67  
68 protected function _getCacheDriver()
69 {
70 return new PhpFileCache($this->directory);
71 }
72 }
73  
74 class NotSetStateClass
75 {
76 private $value;
77  
78 public function __construct($value)
79 {
80 $this->value = $value;
81 }
82  
83 public function getValue()
84 {
85 return $this->value;
86 }
87 }
88  
89 class SetStateClass extends NotSetStateClass
90 {
91 public static $values = array();
92  
93 public static function __set_state($data)
94 {
95 self::$values = $data;
96 return new self($data['value']);
97 }
98 }