PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / kriswallsmith / assetic / tests / Assetic / Test / Cache / ExpiringCacheTest.php

ExpiringCacheTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/kriswallsmith/assetic/tests/Assetic/Test/Cache/ExpiringCacheTest.php

119 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Assetic package, an OpenSky project.
5 *
6 * (c) 2010-2014 OpenSky Project Inc
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Assetic\Test\Cache;
13
14 use Assetic\Cache\ExpiringCache;
15
16 class ExpiringCacheTest extends \PHPUnit_Framework_TestCase
17 {
18 private $inner;
19 private $lifetime;
20 private $cache;
21
22 protected function setUp()
23 {
24 $this->inner = $this->getMockBuilder('Assetic\\Cache\\CacheInterface')->getMock();
25 $this->lifetime = 3600;
26 $this->cache = new ExpiringCache($this->inner, $this->lifetime);
27 }
28
29 protected function tearDown()
30 {
31 $this->inner = null;
32 $this->lifetime = null;
33 $this->cache = null;
34 }
35
36 public function testHasExpired()
37 {
38 $key = 'asdf';
39 $expiresKey = 'asdf.expires';
40 $thePast = 0;
41
42 $this->inner->expects($this->once())
43 ->method('has')
44 ->with($key)
45 ->will($this->returnValue(true));
46 $this->inner->expects($this->once())
47 ->method('get')
48 ->with($expiresKey)
49 ->will($this->returnValue($thePast));
50 $this->inner->expects($this->at(2))
51 ->method('remove')
52 ->with($expiresKey);
53 $this->inner->expects($this->at(3))
54 ->method('remove')
55 ->with($key);
56
57 $this->assertFalse($this->cache->has($key), '->has() returns false if an expired value exists');
58 }
59
60 public function testHasNotExpired()
61 {
62 $key = 'asdf';
63 $expiresKey = 'asdf.expires';
64 $theFuture = time() * 2;
65
66 $this->inner->expects($this->once())
67 ->method('has')
68 ->with($key)
69 ->will($this->returnValue(true));
70 $this->inner->expects($this->once())
71 ->method('get')
72 ->with($expiresKey)
73 ->will($this->returnValue($theFuture));
74
75 $this->assertTrue($this->cache->has($key), '->has() returns true if a value the not expired');
76 }
77
78 public function testSetLifetime()
79 {
80 $key = 'asdf';
81 $expiresKey = 'asdf.expires';
82 $value = 'qwerty';
83
84 $this->inner->expects($this->at(0))
85 ->method('set')
86 ->with($expiresKey, $this->greaterThanOrEqual(time() + $this->lifetime));
87 $this->inner->expects($this->at(1))
88 ->method('set')
89 ->with($key, $value);
90
91 $this->cache->set($key, $value);
92 }
93
94 public function testRemove()
95 {
96 $key = 'asdf';
97 $expiresKey = 'asdf.expires';
98
99 $this->inner->expects($this->at(0))
100 ->method('remove')
101 ->with($expiresKey);
102 $this->inner->expects($this->at(1))
103 ->method('remove')
104 ->with($key);
105
106 $this->cache->remove($key);
107 }
108
109 public function testGet()
110 {
111 $this->inner->expects($this->once())
112 ->method('get')
113 ->with('foo')
114 ->will($this->returnValue('bar'));
115
116 $this->assertEquals('bar', $this->cache->get('foo'), '->get() returns the cached value');
117 }
118 }
119