|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\HttpKernel\Tests\CacheClearer; |
| 13 | + |
| 14 | +use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer; |
| 15 | +use Psr\Cache\CacheItemPoolInterface; |
| 16 | + |
| 17 | +class Psr6CacheClearerTest extends \PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + public function testClearPoolsInjectedInConstructor() |
| 20 | + { |
| 21 | + $pool = $this->getMock(CacheItemPoolInterface::class); |
| 22 | + $pool |
| 23 | + ->expects($this->once()) |
| 24 | + ->method('clear'); |
| 25 | + |
| 26 | + (new Psr6CacheClearer(array('pool' => $pool)))->clear(''); |
| 27 | + } |
| 28 | + |
| 29 | + public function testClearPool() |
| 30 | + { |
| 31 | + $pool = $this->getMock(CacheItemPoolInterface::class); |
| 32 | + $pool |
| 33 | + ->expects($this->once()) |
| 34 | + ->method('clear'); |
| 35 | + |
| 36 | + (new Psr6CacheClearer(array('pool' => $pool)))->clearPool('pool'); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @expectedException \InvalidArgumentException |
| 41 | + * @expectedExceptionMessage Cache pool not found: unknown |
| 42 | + */ |
| 43 | + public function testClearPoolThrowsExceptionOnUnreferencedPool() |
| 44 | + { |
| 45 | + (new Psr6CacheClearer())->clearPool('unknown'); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * @group legacy |
| 50 | + * @expectedDeprecation The Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer::addPool() method is deprecated since version 3.3 and will be removed in 4.0. Pass an array of pools indexed by name to the constructor instead. |
| 51 | + */ |
| 52 | + public function testClearPoolsInjectedByAdder() |
| 53 | + { |
| 54 | + $pool1 = $this->getMock(CacheItemPoolInterface::class); |
| 55 | + $pool1 |
| 56 | + ->expects($this->once()) |
| 57 | + ->method('clear'); |
| 58 | + |
| 59 | + $pool2 = $this->getMock(CacheItemPoolInterface::class); |
| 60 | + $pool2 |
| 61 | + ->expects($this->once()) |
| 62 | + ->method('clear'); |
| 63 | + |
| 64 | + $clearer = new Psr6CacheClearer(array('pool1' => $pool1)); |
| 65 | + $clearer->addPool($pool2); |
| 66 | + $clearer->clear(''); |
| 67 | + } |
| 68 | +} |
0 commit comments