Skip to content

Commit 1556e1a

Browse files
prisisNyholm
authored andcommitted
Fix invalid exception call (#210)
* styleci cs fixes * Fix invalid exception call to a interface
1 parent 3640bc4 commit 1556e1a

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

EncryptedCachePool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Cache\Encryption;
1313

14+
use Cache\Adapter\Common\Exception\InvalidArgumentException;
1415
use Cache\TagInterop\TaggableCacheItemPoolInterface;
1516
use Defuse\Crypto\Key;
1617
use Psr\Cache\CacheItemInterface;
17-
use Psr\Cache\InvalidArgumentException;
1818

1919
/**
2020
* Wraps a CacheItemInterface with EncryptedItemDecorator.
@@ -59,7 +59,7 @@ public function getItem($key)
5959
public function getItems(array $keys = [])
6060
{
6161
return array_map(function (CacheItemInterface $inner) {
62-
if (!($inner instanceof EncryptedItemDecorator)) {
62+
if (!$inner instanceof EncryptedItemDecorator) {
6363
return new EncryptedItemDecorator($inner, $this->key);
6464
}
6565

Tests/IntegrationPoolTest.php

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,60 @@
1111

1212
namespace Cache\Encryption\Tests;
1313

14-
use Cache\Adapter\PHPArray\ArrayCachePool;
14+
use Cache\Adapter\Common\CacheItem;
15+
use Cache\Adapter\Common\Exception\InvalidArgumentException;
16+
use Cache\Adapter\Filesystem\FilesystemCachePool;
1517
use Cache\Encryption\EncryptedCachePool;
1618
use Cache\IntegrationTests\CachePoolTest;
1719
use Defuse\Crypto\Key;
20+
use League\Flysystem\Adapter\Local;
21+
use League\Flysystem\Filesystem;
1822

1923
class IntegrationPoolTest extends CachePoolTest
2024
{
21-
private $cacheArray = [];
25+
/**
26+
* @type Filesystem
27+
*/
28+
private $filesystem;
2229

30+
/**
31+
* @throws \Defuse\Crypto\Exception\BadFormatException
32+
* @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException
33+
*
34+
* @return EncryptedCachePool|\Psr\Cache\CacheItemPoolInterface
35+
*/
2336
public function createCachePool()
2437
{
2538
return new EncryptedCachePool(
26-
new ArrayCachePool(null, $this->cacheArray),
39+
new FilesystemCachePool($this->getFilesystem()),
2740
Key::loadFromAsciiSafeString('def000007c57b06c65b0df4bcac939924e42605d8d76e1462b619318bf94107c28db30c5394b4242db5e45563e1226cffcdff8123fa214ea1fcc4aa10b0ddb1b4a587b7e')
2841
);
2942
}
43+
44+
public function testSaveToThrowAInvalidArgumentException()
45+
{
46+
$this->expectException(InvalidArgumentException::class);
47+
48+
$pool = $this->createCachePool();
49+
50+
$pool->save(new CacheItem('save_valid_exceptiond'));
51+
}
52+
53+
public function testSaveDeferredToThrowAInvalidArgumentException()
54+
{
55+
$this->expectException(InvalidArgumentException::class);
56+
57+
$pool = $this->createCachePool();
58+
59+
$pool->saveDeferred(new CacheItem('save_valid_exceptiond'));
60+
}
61+
62+
private function getFilesystem()
63+
{
64+
if ($this->filesystem === null) {
65+
$this->filesystem = new Filesystem(new Local(__DIR__.'/cache'.rand(1, 100000)));
66+
}
67+
68+
return $this->filesystem;
69+
}
3070
}

0 commit comments

Comments
 (0)