Skip to content

Commit

Permalink
Added test for reserved characters in cache keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Mar 15, 2017
1 parent e6d5d46 commit 506e1c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Connector/CachingConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ public function isCacheEnabled()

private function hash(array $structure)
{
return str_replace(str_split('{}()/\@:'), '.', json_encode($structure));
return str_replace(str_split('{}()/\@:'), '.', json_encode($structure, JSON_UNESCAPED_SLASHES));
}
}
21 changes: 21 additions & 0 deletions test/Integration/Porter/Connector/CachingConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use ScriptFUSION\Porter\Cache\MemoryCache;
use ScriptFUSION\Porter\Connector\CachingConnector;
Expand Down Expand Up @@ -88,4 +89,24 @@ public function testEnableCache()
$this->connector->enableCache();
self::assertTrue($this->connector->isCacheEnabled());
}

public function testCacheKeyExcludesReservedCharacters()
{
$reservedCharacters = '{}()/\@:';

$this->connector->setCache($cache = \Mockery::spy(CacheItemPoolInterface::class));

$cache->shouldReceive('hasItem')
->andReturnUsing(
function ($key) use ($reservedCharacters) {
foreach (str_split($reservedCharacters) as $reservedCharacter) {
self::assertNotContains($reservedCharacter, $key);
}
}
)->once()
->shouldReceive('getItem')->andReturnSelf()
->shouldReceive('set')->andReturn(\Mockery::mock(CacheItemInterface::class));

$this->connector->fetch($reservedCharacters, (new TestOptions)->setFoo($reservedCharacters));
}
}

0 comments on commit 506e1c6

Please sign in to comment.