banker/tests/Driver/DriverTestBase.php

121 lines
2.6 KiB
PHP
Raw Normal View History

2016-10-19 09:57:06 -04:00
<?php declare(strict_types=1);
/**
* Banker
*
* A Caching library implementing psr/cache
*
* PHP version 7.0
*
* @package Banker
* @author Timothy J. Warren <tim@timshomepage.net>
2017-03-01 12:33:12 -05:00
* @copyright 2016 - 2017 Timothy J. Warren
2016-10-19 09:57:06 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2017-03-01 12:33:12 -05:00
* @version 1.0.1
2016-10-19 09:57:06 -04:00
* @link https://git.timshomepage.net/timw4mail/banker
*/
2016-09-05 16:43:37 -04:00
namespace Aviat\Banker\Tests\Driver;
use PHPUnit\Framework\TestCase;
class DriverTestBase extends TestCase {
protected $driver;
2016-09-06 20:26:28 -04:00
public function tearDown(): void
2016-09-06 17:03:43 -04:00
{
$this->driver->__destruct();
}
2016-09-05 16:43:37 -04:00
public function testGetSet(): void
2016-09-05 16:43:37 -04:00
{
$this->driver->set('foo', 'bar');
$this->assertTrue($this->driver->exists('foo'));
2016-09-05 16:43:37 -04:00
$this->assertEquals('bar', $this->driver->get('foo'));
$bar = [
'foo' => [
'apple' => 'orange'
],
'bar' => 'baz'
];
$this->driver->set('bar', $bar);
$this->assertEquals($bar, $this->driver->get('bar'));
}
2016-09-06 20:26:28 -04:00
public function testGetMultipleOnBadKey(): void
{
$actual = $this->driver->getMultiple(['x','y']);
$this->assertEquals([], $actual);
}
public function testGetMultiple(): void
2016-09-06 20:26:28 -04:00
{
$this->driver->set('foo', ['bar']);
$this->driver->set('bar', (object) [
'foo' => [
'bar' => 'baz'
]
]);
// Intentionally set the same key with different values
$this->driver->set('baz', 34);
$this->driver->set('baz', 42);
$expected = [
'foo' => ['bar'],
'bar' => (object) [
'foo' => [
'bar' => 'baz'
]
],
];
$actual = $this->driver->getMultiple(['foo', 'bar']);
$this->assertEquals($expected, $actual);
}
public function testSetWithExpires(): void
2016-09-06 20:26:28 -04:00
{
$this->driver->set('foo', 'bar', 30);
$this->assertEquals('bar', $this->driver->get('foo'));
}
public function testDelete(): void
{
$this->driver->set('a1', 'b2');
$this->assertTrue($this->driver->exists('a1'));
$this->assertTrue($this->driver->delete('a1'));
$this->assertFalse($this->driver->exists('a1'));
}
public function testDeleteMultiple(): void
{
$this->driver->set('a', 1);
$this->driver->set('b', 2);
$this->assertTrue($this->driver->exists('a'));
$this->assertTrue($this->driver->exists('b'));
/*$this->assertTrue(*/$this->driver->deleteMultiple(['a', 'b']);//);
$this->assertFalse($this->driver->exists('a'));
$this->assertFalse($this->driver->exists('b'));
}
public function testExpiresAt(): void
{
$this->driver->set('abc', 'def');
$result = $this->driver->expiresAt('abc', 30);
$this->assertTrue($result);
}
public function testExpiresAtBadKey(): void
{
$result = $this->driver->expiresAt('q', 30);
$this->assertFalse($result);
}
2016-09-05 16:43:37 -04:00
}