From 8a662f2ab3e47cba3073927d5bf1cedd72dcfb33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Haso=C5=88?= Date: Wed, 15 May 2013 12:37:17 +0200 Subject: [PATCH] Fixed Twig_Loader_Chain::exists for a loader which implements Twig_ExistsLoaderInterface --- lib/Twig/Loader/Chain.php | 8 ++++++-- test/Twig/Tests/Loader/ChainTest.php | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index cd64b05..1f1cf06 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -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 { diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index 580ae10..4fe0db9 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -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')); + } } -- 1.7.2.5