Initial commit cache
This commit is contained in:
121
test/Unit/Adapter/FilesystemAdapterTest.php
Normal file
121
test/Unit/Adapter/FilesystemAdapterTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace IQParts\CacheTest\Unit\Adapter;
|
||||
|
||||
use IQParts\Cache\Adapter\FilesystemAdapter;
|
||||
use IQParts\Cache\Serializer\JsonSerializer;
|
||||
use IQParts\CacheTest\AbstractTestCase;
|
||||
|
||||
final class FilesystemAdapterTest extends AbstractTestCase
|
||||
{
|
||||
public function testGetSet()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777
|
||||
);
|
||||
|
||||
|
||||
$adapter->set('a', 'b');
|
||||
$this->assertEquals('b', $adapter->get('a'));
|
||||
|
||||
$adapter->delete('a');
|
||||
$this->assertEquals(null, $adapter->get('a'));
|
||||
|
||||
$adapter->set('ttl', 'b', 200);
|
||||
$this->assertTrue($adapter->ttl('ttl') > 0);
|
||||
$this->assertTrue($adapter->ttl('b') === $adapter::NO_TTL);
|
||||
|
||||
$adapter->set('a-keys', 'a');
|
||||
$adapter->set('b-keys', 'a');
|
||||
$this->assertEquals(['a-keys'], $adapter->keys('a*'));
|
||||
$adapter->delete('b');
|
||||
$adapter->delete('a-keys');
|
||||
$adapter->delete('b-keys');
|
||||
}
|
||||
|
||||
public function testTtl()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777
|
||||
);
|
||||
|
||||
$adapter->set('a', 'b', 10);
|
||||
|
||||
$this->assertEquals('b', $adapter->get('a'));
|
||||
$this->assertTrue($adapter->ttl('a') > 0);
|
||||
|
||||
$adapter->set('b', 'a', -10);
|
||||
$this->assertNull($adapter->get('b'));
|
||||
|
||||
$adapter->delete('b');
|
||||
$adapter->delete('a');
|
||||
}
|
||||
|
||||
public function testDefaultTtl()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777,
|
||||
10
|
||||
);
|
||||
|
||||
$adapter->set('a', 'b');
|
||||
$this->assertTrue($adapter->ttl('a') > 0);
|
||||
$adapter->delete('a');
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777
|
||||
);
|
||||
|
||||
$adapter->set('del-a', 'a');
|
||||
$adapter->set('del-b', 'b');
|
||||
$adapter->delete('del*');
|
||||
$this->assertNull($adapter->get('del-a'));
|
||||
$this->assertNull($adapter->get('del-b'));
|
||||
}
|
||||
|
||||
public function testSubFolder()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777
|
||||
);
|
||||
|
||||
$adapter->set('a/b', 'a');
|
||||
$this->assertEquals('a', $adapter->get('a/b'));
|
||||
$adapter->delete('a/b');
|
||||
}
|
||||
|
||||
public function testSubFolderWithSeperator()
|
||||
{
|
||||
$location = $this->getTmpDirectory();
|
||||
$adapter = new FilesystemAdapter(
|
||||
$location,
|
||||
new JsonSerializer(),
|
||||
0777,
|
||||
null,
|
||||
'/'
|
||||
);
|
||||
|
||||
$adapter->set('a/b', 'a');
|
||||
$this->assertEquals('a', $adapter->get('a/b'));
|
||||
$adapter->delete('a/b');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user