vendor/symfony/src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the Symfony package.
       
     5  *
       
     6  * (c) Fabien Potencier <fabien@symfony.com>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace Symfony\Bundle\TwigBundle\Tests\Loader;
       
    13 
       
    14 use Symfony\Bundle\TwigBundle\Tests\TestCase;
       
    15 use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader;
       
    16 use Symfony\Component\Config\FileLocatorInterface;
       
    17 use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
       
    18 use Symfony\Component\Templating\TemplateNameParserInterface;
       
    19 use InvalidArgumentException;
       
    20 
       
    21 class FilesystemLoaderTest extends TestCase
       
    22 {
       
    23     /** @var FileLocatorInterface */
       
    24     private $locator;
       
    25     /** @var TemplateNameParserInterface */
       
    26     private $parser;
       
    27     /** @var FilesystemLoader */
       
    28     private $loader;
       
    29 
       
    30     protected function setUp()
       
    31     {
       
    32         parent::setUp();
       
    33 
       
    34         $this->locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
       
    35         $this->parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
       
    36         $this->loader = new FilesystemLoader($this->locator, $this->parser);
       
    37 
       
    38         $this->parser->expects($this->once())
       
    39                 ->method('parse')
       
    40                 ->with('name.format.engine')
       
    41                 ->will($this->returnValue(new TemplateReference('', '', 'name', 'format', 'engine')))
       
    42         ;
       
    43     }
       
    44 
       
    45     protected function tearDown()
       
    46     {
       
    47         parent::tearDown();
       
    48 
       
    49         $this->locator = null;
       
    50         $this->parser = null;
       
    51         $this->loader = null;
       
    52     }
       
    53 
       
    54     public function testTwigErrorIfLocatorThrowsInvalid()
       
    55     {
       
    56         $this->setExpectedException('Twig_Error_Loader');
       
    57         $invalidException = new InvalidArgumentException('Unable to find template "NonExistent".');
       
    58         $this->locator->expects($this->once())
       
    59                       ->method('locate')
       
    60                       ->will($this->throwException($invalidException));
       
    61 
       
    62         $this->loader->getCacheKey('name.format.engine');
       
    63     }
       
    64 
       
    65     public function testTwigErrorIfLocatorReturnsFalse()
       
    66     {
       
    67         $this->setExpectedException('Twig_Error_Loader');
       
    68         $this->locator->expects($this->once())
       
    69                       ->method('locate')
       
    70                       ->will($this->returnValue(false));
       
    71 
       
    72         $this->loader->getCacheKey('name.format.engine');
       
    73     }
       
    74 }