merged branch hason/chain (PR #1093)

This PR was merged into the master branch.

Discussion
----------

Fixed Twig_Loader_Chain::exists for a loader which implements Twig_ExistsLoaderInterface

Commits
-------

8a662f2 Fixed Twig_Loader_Chain::exists for a loader which implements Twig_ExistsLoaderInterface
This commit is contained in:
Fabien Potencier
2013-05-15 16:22:32 +02:00
2 changed files with 22 additions and 2 deletions
+6 -2
View File
@@ -76,8 +76,12 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
}
foreach ($this->loaders as $loader) {
if ($loader instanceof Twig_ExistsLoaderInterface && $loader->exists($name)) {
return $this->hasSourceCache[$name] = true;
if ($loader instanceof Twig_ExistsLoaderInterface) {
if ($loader->exists($name)) {
return $this->hasSourceCache[$name] = true;
}
continue;
}
try {
+16
View File
@@ -60,4 +60,20 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
$this->assertEquals('bar', $loader->getSource('foo'));
}
public function testExists()
{
$loader1 = $this->getMock('Twig_Loader_Array', array('exists', 'getSource'), array(), '', false);
$loader1->expects($this->once())->method('exists')->will($this->returnValue(false));
$loader1->expects($this->never())->method('getSource');
$loader2 = $this->getMock('Twig_LoaderInterface');
$loader2->expects($this->once())->method('getSource')->will($this->returnValue('content'));
$loader = new Twig_Loader_Chain();
$loader->addLoader($loader1);
$loader->addLoader($loader2);
$this->assertTrue($loader->exists('foo'));
}
}