File size: 1,518 Bytes
e4f4821 |
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 61 62 63 |
<?php
require_once __DIR__.'/../../Base.php';
use Kanboard\Core\Cache\MemoryCache;
class MemoryCacheTest extends Base
{
public function testKeyNotFound()
{
$c = new MemoryCache;
$this->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));
}
}
|