From fe57edd9e87832dbd14ea8ffd2dc2f16ac1ceb6f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 20 Sep 2015 12:38:35 -0400 Subject: Add abstract cache layer --- tests/units/Core/Cache/MemoryCacheTest.php | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/units/Core/Cache/MemoryCacheTest.php (limited to 'tests/units/Core') diff --git a/tests/units/Core/Cache/MemoryCacheTest.php b/tests/units/Core/Cache/MemoryCacheTest.php new file mode 100644 index 00000000..b28604ed --- /dev/null +++ b/tests/units/Core/Cache/MemoryCacheTest.php @@ -0,0 +1,62 @@ +assertEquals(null, $c->get('mykey')); + } + + public function testSetValue() + { + $c = new MemoryCache; + $c->set('mykey', 'myvalue'); + $this->assertEquals('myvalue', $c->get('mykey')); + } + + public function testRemoveValue() + { + $c = new MemoryCache; + $c->set('mykey', 'myvalue'); + $c->remove('mykey'); + $this->assertEquals(null, $c->get('mykey')); + } + + public function testFlushAll() + { + $c = new MemoryCache; + $c->set('mykey', 'myvalue'); + $c->flush(); + $this->assertEquals(null, $c->get('mykey')); + } + + public function testProxy() + { + $c = new MemoryCache; + + $class = $this + ->getMockBuilder('stdClass') + ->setMethods(array('doSomething')) + ->getMock(); + + $class + ->expects($this->once()) + ->method('doSomething') + ->with( + $this->equalTo(1), + $this->equalTo(2) + ) + ->will($this->returnValue(3)); + + // First call will store the computed value + $this->assertEquals(3, $c->proxy($class, 'doSomething', 1, 2)); + + // Second call get directly the cached value + $this->assertEquals(3, $c->proxy($class, 'doSomething', 1, 2)); + } +} -- cgit v1.2.3