Skip to content

Commit

Permalink
Allow int and float to use as cache keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Burtsev committed Jun 1, 2017
1 parent b0ffb35 commit 1096359
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ApcuCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function buildKeyNames(array $keys)
*/
private function assertKeyName($key)
{
if (!is_string($key)) {
if (!is_scalar($key) || is_bool($key)) {
throw new ApcuInvalidCacheKeyException();
}
}
Expand Down
22 changes: 20 additions & 2 deletions tests/ApcuCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,33 @@ public function dataForTestGetWithInvalidKey()
{
return [
'null' => [null],
'int' => [1],
'float' => [1.1],
'object' => [new \stdClass()],
'array' => [[]],
'bool' => [false],
'resource' => [fopen('/tmp/test.1', 'w+')],
];
}

/**
* @dataProvider dataForTestSetAndGetWithAllowedKeys
*
* @param $key
*/
public function testSetAndGetWithAllowedKeys($key)
{
$this->cache->set($key, 'foo');
$this->assertEquals('foo', $this->cache->get($key));
}

public function dataForTestSetAndGetWithAllowedKeys()
{
return [
[5],
[1.1],
['bar'],
];
}

public function testWhenApcuUnavailable()
{
ini_set('apc.enable_cli', 0);
Expand Down

0 comments on commit 1096359

Please sign in to comment.