Initial commit cache
This commit is contained in:
61
test/Unit/Adapter/NamespaceAdapterTest.php
Normal file
61
test/Unit/Adapter/NamespaceAdapterTest.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user