ChainCacheClearerTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(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->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock();
  46. }
  47. }