Files
cache/test/Unit/Adapter/NamespaceAdapterTest.php
2021-04-10 12:45:25 +02:00

61 lines
1.6 KiB
PHP

<?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(): void
{
$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);
}
}