Psr6CacheClearerTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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->createMock(CacheItemPoolInterface::class);
  19. $pool
  20. ->expects($this->once())
  21. ->method('clear');
  22. (new Psr6CacheClearer(['pool' => $pool]))->clear('');
  23. }
  24. public function testClearPool()
  25. {
  26. $pool = $this->createMock(CacheItemPoolInterface::class);
  27. $pool
  28. ->expects($this->once())
  29. ->method('clear')
  30. ->willReturn(true)
  31. ;
  32. $this->assertTrue((new Psr6CacheClearer(['pool' => $pool]))->clearPool('pool'));
  33. }
  34. public function testClearPoolThrowsExceptionOnUnreferencedPool()
  35. {
  36. $this->expectException(\InvalidArgumentException::class);
  37. $this->expectExceptionMessage('Cache pool not found: "unknown"');
  38. (new Psr6CacheClearer())->clearPool('unknown');
  39. }
  40. }