|
11 | 11 |
|
12 | 12 | namespace Cache\Encryption\Tests; |
13 | 13 |
|
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; |
15 | 17 | use Cache\Encryption\EncryptedCachePool; |
16 | 18 | use Cache\IntegrationTests\CachePoolTest; |
17 | 19 | use Defuse\Crypto\Key; |
| 20 | +use League\Flysystem\Adapter\Local; |
| 21 | +use League\Flysystem\Filesystem; |
18 | 22 |
|
19 | 23 | class IntegrationPoolTest extends CachePoolTest |
20 | 24 | { |
21 | | - private $cacheArray = []; |
| 25 | + /** |
| 26 | + * @type Filesystem |
| 27 | + */ |
| 28 | + private $filesystem; |
22 | 29 |
|
| 30 | + /** |
| 31 | + * @throws \Defuse\Crypto\Exception\BadFormatException |
| 32 | + * @throws \Defuse\Crypto\Exception\EnvironmentIsBrokenException |
| 33 | + * |
| 34 | + * @return EncryptedCachePool|\Psr\Cache\CacheItemPoolInterface |
| 35 | + */ |
23 | 36 | public function createCachePool() |
24 | 37 | { |
25 | 38 | return new EncryptedCachePool( |
26 | | - new ArrayCachePool(null, $this->cacheArray), |
| 39 | + new FilesystemCachePool($this->getFilesystem()), |
27 | 40 | Key::loadFromAsciiSafeString('def000007c57b06c65b0df4bcac939924e42605d8d76e1462b619318bf94107c28db30c5394b4242db5e45563e1226cffcdff8123fa214ea1fcc4aa10b0ddb1b4a587b7e') |
28 | 41 | ); |
29 | 42 | } |
| 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 | + } |
30 | 70 | } |
0 commit comments