Code tweaks for slightly better test coverage
This commit is contained in:
parent
cef8d2c944
commit
df61334bb4
@ -76,7 +76,7 @@ class ApcuDriver extends AbstractDriver {
|
||||
$this->validateKeys($keys);
|
||||
|
||||
$status = FALSE;
|
||||
return apcu_fetch($keys, $status);
|
||||
return (array)apcu_fetch($keys, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,13 +78,11 @@ class RedisDriver extends AbstractDriver {
|
||||
*/
|
||||
public function get(string $key): mixed
|
||||
{
|
||||
$raw = $this->conn->get($key);
|
||||
if ($raw === NULL)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$raw = $this->conn->get($key) ?? '';
|
||||
$parsed = @unserialize($raw);
|
||||
$hasError = is_array(error_get_last());
|
||||
|
||||
return unserialize($raw);
|
||||
return ($hasError) ? NULL : $parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,6 +25,7 @@ use JsonSerializable;
|
||||
*
|
||||
* @see http://php.net/manual/en/class.arrayiterator.php
|
||||
* @see http://php.net/manual/en/class.jsonserializable.php
|
||||
* @extends ArrayIterator<string, CacheItemInterface>
|
||||
*/
|
||||
class ItemCollection extends ArrayIterator implements JsonSerializable {
|
||||
|
||||
@ -39,7 +40,7 @@ class ItemCollection extends ArrayIterator implements JsonSerializable {
|
||||
* Create the collection object from the raw
|
||||
* CacheItemInterface array
|
||||
*
|
||||
* @param array $items - array of CacheItemInterface objects
|
||||
* @param CacheItemInterface[] $items - array of CacheItemInterface objects
|
||||
* @param int $flags - flags
|
||||
*/
|
||||
public function __construct(array $items = [], int $flags = 0)
|
||||
@ -51,7 +52,7 @@ class ItemCollection extends ArrayIterator implements JsonSerializable {
|
||||
/**
|
||||
* Specify what data to serialize when using `json_encode`
|
||||
*
|
||||
* @return array - The full set of data to be serialized
|
||||
* @return CacheItemInterface[] - The full set of data to be serialized
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
|
@ -26,6 +26,7 @@ use function is_string;
|
||||
*/
|
||||
final class Pool implements CacheItemPoolInterface, LoggerAwareInterface {
|
||||
use _Driver;
|
||||
use KeyValidateTrait;
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,7 @@ use Psr\SimpleCache;
|
||||
*/
|
||||
class Teller implements LoggerAwareInterface, SimpleCache\CacheInterface {
|
||||
use _Driver;
|
||||
use KeyValidateTrait;
|
||||
use LoggerTrait;
|
||||
|
||||
/**
|
||||
|
@ -21,20 +21,13 @@ use Aviat\Banker\Driver\AbstractDriver;
|
||||
* Private trait for shared driver-related functionality
|
||||
*/
|
||||
trait _Driver {
|
||||
use KeyValidateTrait;
|
||||
|
||||
/**
|
||||
* Driver class for handling the chosen caching backend
|
||||
*
|
||||
* @var AbstractDriver
|
||||
*/
|
||||
private AbstractDriver $driver;
|
||||
|
||||
/**
|
||||
* Instantiate the appropriate cache backend based on the config
|
||||
*
|
||||
* @param array $driverConfig
|
||||
* @return AbstractDriver
|
||||
*/
|
||||
protected function loadDriver(array $driverConfig = []): AbstractDriver
|
||||
{
|
||||
@ -44,6 +37,7 @@ trait _Driver {
|
||||
$driverConfig['connection'] = $driverConfig['connection'] ?? [];
|
||||
$driverConfig['options'] = $driverConfig['options'] ?? [];
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
return new $class($driverConfig['connection'], $driverConfig['options']);
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ItemCollectionTest extends TestCase {
|
||||
|
||||
protected $collection;
|
||||
protected ItemCollection $collection;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user