Psr6CacheClearerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\CacheClearer;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
  13. use Psr\Cache\CacheItemPoolInterface;
  14. class Psr6CacheClearerTest extends TestCase
  15. {
  16. public function testClearPoolsInjectedInConstructor()
  17. {
  18. $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
  19. $pool
  20. ->expects($this->once())
  21. ->method('clear');
  22. (new Psr6CacheClearer(array('pool' => $pool)))->clear('');
  23. }
  24. public function testClearPool()
  25. {
  26. $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
  27. $pool
  28. ->expects($this->once())
  29. ->method('clear');
  30. (new Psr6CacheClearer(array('pool' => $pool)))->clearPool('pool');
  31. }
  32. /**
  33. * @expectedException \InvalidArgumentException
  34. * @expectedExceptionMessage Cache pool not found: unknown
  35. */
  36. public function testClearPoolThrowsExceptionOnUnreferencedPool()
  37. {
  38. (new Psr6CacheClearer())->clearPool('unknown');
  39. }
  40. /**
  41. * @group legacy
  42. * @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.
  43. */
  44. public function testClearPoolsInjectedByAdder()
  45. {
  46. $pool1 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
  47. $pool1
  48. ->expects($this->once())
  49. ->method('clear');
  50. $pool2 = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock();
  51. $pool2
  52. ->expects($this->once())
  53. ->method('clear');
  54. $clearer = new Psr6CacheClearer(array('pool1' => $pool1));
  55. $clearer->addPool($pool2);
  56. $clearer->clear('');
  57. }
  58. }