Psr6CacheClearerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 Psr\Cache\CacheItemPoolInterface;
  13. use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
  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(['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(['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 Symfony 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(['pool1' => $pool1]);
  55. $clearer->addPool($pool2);
  56. $clearer->clear('');
  57. }
  58. }