ChainCacheClearerTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
  12. use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer;
  13. class ChainCacheClearerTest extends \PHPUnit_Framework_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(array($clearer));
  31. $chainClearer->clear(self::$cacheDir);
  32. }
  33. public function testInjectClearerUsingAdd()
  34. {
  35. $clearer = $this->getMockClearer();
  36. $clearer
  37. ->expects($this->once())
  38. ->method('clear');
  39. $chainClearer = new ChainCacheClearer();
  40. $chainClearer->add($clearer);
  41. $chainClearer->clear(self::$cacheDir);
  42. }
  43. protected function getMockClearer()
  44. {
  45. return $this->getMock('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface');
  46. }
  47. }