TwigResourceTest.php 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Assetic package, an OpenSky project.
  4. *
  5. * (c) 2010-2011 OpenSky Project Inc
  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 Assetic\Test\Extension\Twig;
  11. use Assetic\Extension\Twig\TwigResource;
  12. class TwigResourceTest extends \PHPUnit_Framework_TestCase
  13. {
  14. protected function setUp()
  15. {
  16. if (!class_exists('Twig_Environment')) {
  17. $this->markTestSkipped('Twig is not installed.');
  18. }
  19. }
  20. public function testInvalidTemplateNameGetContent()
  21. {
  22. $loader = $this->getMock('Twig_LoaderInterface');
  23. $loader->expects($this->once())
  24. ->method('getSource')
  25. ->with('asdf')
  26. ->will($this->throwException(new \Twig_Error_Loader('')));
  27. $resource = new TwigResource($loader, 'asdf');
  28. $this->assertEquals('', $resource->getContent());
  29. }
  30. public function testInvalidTemplateNameIsFresh()
  31. {
  32. $loader = $this->getMock('Twig_LoaderInterface');
  33. $loader->expects($this->once())
  34. ->method('isFresh')
  35. ->with('asdf', 1234)
  36. ->will($this->throwException(new \Twig_Error_Loader('')));
  37. $resource = new TwigResource($loader, 'asdf');
  38. $this->assertFalse($resource->isFresh(1234));
  39. }
  40. }