ChainCacheClearerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\ChainCacheClearer;
  13. class ChainCacheClearerTest extends TestCase
  14. {
  15. protected static $cacheDir;
  16. public static function setUpBeforeClass()
  17. {
  18. self::$cacheDir = tempnam(sys_get_temp_dir(), 'sf2_cache_clearer_dir');
  19. }
  20. public static function tearDownAfterClass()
  21. {
  22. @unlink(self::$cacheDir);
  23. }
  24. public function testInjectClearersInConstructor()
  25. {
  26. $clearer = $this->getMockClearer();
  27. $clearer
  28. ->expects($this->once())
  29. ->method('clear');
  30. $chainClearer = new ChainCacheClearer([$clearer]);
  31. $chainClearer->clear(self::$cacheDir);
  32. }
  33. /**
  34. * @group legacy
  35. */
  36. public function testInjectClearerUsingAdd()
  37. {
  38. $clearer = $this->getMockClearer();
  39. $clearer
  40. ->expects($this->once())
  41. ->method('clear');
  42. $chainClearer = new ChainCacheClearer();
  43. $chainClearer->add($clearer);
  44. $chainClearer->clear(self::$cacheDir);
  45. }
  46. protected function getMockClearer()
  47. {
  48. return $this->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock();
  49. }
  50. }