Initial commit cache

This commit is contained in:
2018-02-28 15:01:45 +01:00
commit 01a13b7f2b
20 changed files with 1117 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace IQParts\CacheTest\Unit\Adapter;
use IQParts\Cache\Adapter\MemoryAdapter;
use IQParts\CacheTest\AbstractTestCase;
use IQParts\Cache\Adapter\CacheAdapterInterface;
use IQParts\Cache\Adapter\NamespaceAdapter;
use PhpParser\Node\Name;
final class NamespaceAdapterTest extends AbstractTestCase
{
/**
* @var CacheAdapterInterface
*/
private $adapter;
public function setUp()
{
$this->adapter = new MemoryAdapter();
}
public function testGet()
{
$adapter = new NamespaceAdapter('test', $this->adapter);
$adapter->set('mykey', 'a');
$this->assertEquals('test:mykey', $this->adapter->keys()[0]);
$this->assertEquals('a', $adapter->get('mykey'));
}
public function testSet()
{
$adapter = new NamespaceAdapter('test', $this->adapter);
$adapter->set('mykey', null);
$this->assertEquals('test:mykey', $this->adapter->keys()[0]);
}
public function testDelete()
{
$adapter = new NamespaceAdapter('test', $this->adapter);
$adapter->delete('mykey');
$this->assertEquals(null, $this->adapter->get('mykey'));
}
public function testKeys()
{
$adapter = new NamespaceAdapter('test', $this->adapter);
$adapter->set('a-keys', 'a');
$adapter->set('b-keys', 'b');
$this->assertEquals(['a-keys'], $adapter->keys('a-*'));
$this->assertEquals(['a-keys'], $adapter->keys('a-'));
}
public function testTtl()
{
$adapter = new NamespaceAdapter('test', $this->adapter);
$adapter->set('a', 'b', 10);
$this->assertTrue($adapter->ttl('a') > 0);
}
}