mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-06 20:48:40 +00:00
fix invalid value set/add
This commit is contained in:
parent
71cc73397d
commit
dbfadd4cc3
|
|
@ -76,6 +76,14 @@ class MemCached extends ConnectionAbstract
|
||||||
*/
|
*/
|
||||||
public function set($key, $value, int $expire = -1) : void
|
public function set($key, $value, int $expire = -1) : void
|
||||||
{
|
{
|
||||||
|
if ($this->status !== CacheStatus::OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(\is_scalar($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
$this->con->set($key, $value, \max($expire, 0));
|
$this->con->set($key, $value, \max($expire, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,6 +96,10 @@ class MemCached extends ConnectionAbstract
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(\is_scalar($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->con->add($key, $value, \max($expire, 0));
|
return $this->con->add($key, $value, \max($expire, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,14 @@ class RedisCache extends ConnectionAbstract
|
||||||
*/
|
*/
|
||||||
public function set($key, $value, int $expire = -1) : void
|
public function set($key, $value, int $expire = -1) : void
|
||||||
{
|
{
|
||||||
|
if ($this->status !== CacheStatus::OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(\is_scalar($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
if ($expire > 0) {
|
if ($expire > 0) {
|
||||||
$this->con->set($key, $value, $expire);
|
$this->con->set($key, $value, $expire);
|
||||||
}
|
}
|
||||||
|
|
@ -107,6 +115,10 @@ class RedisCache extends ConnectionAbstract
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(\is_scalar($value) || $value instanceof \JsonSerializable || $value instanceof \Serializable)) {
|
||||||
|
throw new \InvalidArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
if ($expire > 0) {
|
if ($expire > 0) {
|
||||||
return $this->con->setNx($key, $value, $expire);
|
return $this->con->setNx($key, $value, $expire);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -340,14 +340,26 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox A invalid data type will throw an InvalidArgumentException
|
* @testdox Adding a invalid data type will throw an InvalidArgumentException
|
||||||
* @covers phpOMS\DataStorage\Cache\Connection\FileCache<extended>
|
* @covers phpOMS\DataStorage\Cache\Connection\FileCache<extended>
|
||||||
* @group framework
|
* @group framework
|
||||||
*/
|
*/
|
||||||
public function testInvalidDataType() : void
|
public function testInvalidDataTypeAdd() : void
|
||||||
{
|
{
|
||||||
self::expectException(\InvalidArgumentException::class);
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
$this->cache->add('invalid', $this->cache);
|
$this->cache->add('invalid', $this->cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox Setting a invalid data type will throw an InvalidArgumentException
|
||||||
|
* @covers phpOMS\DataStorage\Cache\Connection\FileCache<extended>
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testInvalidDataTypeSet() : void
|
||||||
|
{
|
||||||
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$this->cache->set('invalid', $this->cache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -265,17 +265,29 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox A invalid data type will throw an InvalidArgumentException
|
* @testdox Adding a invalid data type will throw an InvalidArgumentException
|
||||||
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
||||||
* @group framework
|
* @group framework
|
||||||
*/
|
*/
|
||||||
public function testInvalidDataType() : void
|
public function testInvalidDataTypeAdd() : void
|
||||||
{
|
{
|
||||||
self::expectException(\InvalidArgumentException::class);
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
$this->cache->add('invalid', $this->cache);
|
$this->cache->add('invalid', $this->cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox Setting a invalid data type will throw an InvalidArgumentException
|
||||||
|
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testInvalidDataTypeSet() : void
|
||||||
|
{
|
||||||
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$this->cache->set('invalid', $this->cache);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox A invalid host throws a InvalidConnectionConfigException
|
* @testdox A invalid host throws a InvalidConnectionConfigException
|
||||||
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,29 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertEquals([], $this->cache->stats());
|
self::assertEquals([], $this->cache->stats());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox Adding a invalid data type will throw an InvalidArgumentException
|
||||||
|
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testInvalidDataTypeAdd() : void
|
||||||
|
{
|
||||||
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$this->cache->add('invalid', $this->cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @testdox Setting a invalid data type will throw an InvalidArgumentException
|
||||||
|
* @covers phpOMS\DataStorage\Cache\Connection\MemCached<extended>
|
||||||
|
* @group framework
|
||||||
|
*/
|
||||||
|
public function testInvalidDataTypeSet() : void
|
||||||
|
{
|
||||||
|
self::expectException(\InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$this->cache->set('invalid', $this->cache);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @testdox A invalid host throws a InvalidConnectionConfigException
|
* @testdox A invalid host throws a InvalidConnectionConfigException
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user