Browse code

made using Twig_SourceContextLoaderInterface required

Fabien Potencier authored on 21/10/2016 23:09:46
Showing 17 changed files
... ...
@@ -1,5 +1,6 @@
1 1
 * 1.27.0 (2016-XX-XX)
2 2
 
3
+ * deprecated Twig_LoaderInterface::getSource() (implement Twig_SourceContextLoaderInterface instead)
3 4
  * fixed the filesystem loader with relative paths
4 5
  * deprecated Twig_Node::getLine() in favor of Twig_Node::getTemplateLine()
5 6
  * deprecated Twig_Template::getSource() in favor of Twig_Template::getSourceContext()
... ...
@@ -271,6 +271,8 @@ All loaders implement the ``Twig_LoaderInterface``::
271 271
          * @param  string $name string The name of the template to load
272 272
          *
273 273
          * @return string The template source code
274
+         *
275
+         * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface
274 276
          */
275 277
         function getSource($name);
276 278
 
... ...
@@ -295,6 +297,11 @@ All loaders implement the ``Twig_LoaderInterface``::
295 297
 The ``isFresh()`` method must return ``true`` if the current cached template
296 298
 is still fresh, given the last modification time, or ``false`` otherwise.
297 299
 
300
+.. note::
301
+
302
+    As of Twig 1.27, you should also implement
303
+    ``Twig_SourceContextLoaderInterface`` to avoid deprecation notices.
304
+
298 305
 .. tip::
299 306
 
300 307
     As of Twig 1.11.0, you can also implement ``Twig_ExistsLoaderInterface``
... ...
@@ -137,6 +137,7 @@ Interfaces
137 137
 * ``Twig_NodeInterface``         (use ``Twig_Node`` instead)
138 138
 * ``Twig_ParserInterface``       (use ``Twig_Parser`` instead)
139 139
 * ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``)
140
+* ``Twig_SourceContextLoaderInterface`` (merged with ``Twig_LoaderInterface``)
140 141
 * ``Twig_TemplateInterface``     (use ``Twig_Template`` instead, and use
141 142
   those constants Twig_Template::ANY_CALL, Twig_Template::ARRAY_CALL,
142 143
   Twig_Template::METHOD_CALL)
... ...
@@ -153,6 +154,10 @@ Loaders
153 154
 * As of Twig 1.x, ``Twig_Loader_String`` is deprecated and will be removed in
154 155
   2.0. You can render a string via ``Twig_Environment::createTemplate()``.
155 156
 
157
+* As of Twig 1.27, ``Twig_LoaderInterface::getSource()`` is deprecated.
158
+  Implement ``Twig_SourceContextLoaderInterface`` instead and use
159
+  ``getSourceContext()``.
160
+
156 161
 Node Visitors
157 162
 -------------
158 163
 
... ...
@@ -417,7 +417,7 @@ We have created a simple ``templates`` table that hosts two templates:
417 417
 
418 418
 Now, let's define a loader able to use this database::
419 419
 
420
-    class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
420
+    class DatabaseTwigLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
421 421
     {
422 422
         protected $dbh;
423 423
 
... ...
@@ -435,6 +435,16 @@ Now, let's define a loader able to use this database::
435 435
             return $source;
436 436
         }
437 437
 
438
+        // Twig_SourceContextLoaderInterface as of Twig 1.27
439
+        public function getSourceContext($name)
440
+        {
441
+            if (false === $source = $this->getValue('source', $name)) {
442
+                throw new Twig_Error_Loader(sprintf('Template "%s" does not exist.', $name));
443
+            }
444
+
445
+            return new Twig_Source($source, $name);
446
+        }
447
+
438 448
         // Twig_ExistsLoaderInterface as of Twig 1.11
439 449
         public function exists($name)
440 450
         {
... ...
@@ -403,13 +403,7 @@ class Twig_Environment
403 403
             }
404 404
 
405 405
             if (!class_exists($cls, false)) {
406
-                $loader = $this->getLoader();
407
-                if ($loader instanceof Twig_SourceContextLoaderInterface) {
408
-                    $source = $loader->getSourceContext($name);
409
-                } else {
410
-                    $source = new Twig_Source($loader->getSource($name), $name);
411
-                }
412
-                $content = $this->compileSource($source);
406
+                $content = $this->compileSource($this->getSourceContext($name));
413 407
 
414 408
                 if ($this->bcWriteCacheFile) {
415 409
                     $this->writeCacheFile($key, $content);
... ...
@@ -735,6 +729,10 @@ class Twig_Environment
735 729
      */
736 730
     public function setLoader(Twig_LoaderInterface $loader)
737 731
     {
732
+        if (!$loader instanceof Twig_SourceContextLoaderInterface && 0 !== strpos(get_class($loader), 'Mock_Twig_LoaderInterface')) {
733
+            @trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', get_class($loader)), E_USER_DEPRECATED);
734
+        }
735
+
738 736
         $this->loader = $loader;
739 737
     }
740 738
 
... ...
@@ -753,6 +751,21 @@ class Twig_Environment
753 751
     }
754 752
 
755 753
     /**
754
+     * Gets the source context for the given template name.
755
+     *
756
+     * @return Twig_Source
757
+     */
758
+    public function getSourceContext($name)
759
+    {
760
+        $loader = $this->getLoader();
761
+        if (!$loader instanceof Twig_SourceContextLoaderInterface) {
762
+            return new Twig_Source($loader->getSource($name), $name);
763
+        }
764
+
765
+        return $loader->getSourceContext($name);
766
+    }
767
+
768
+    /**
756 769
      * Sets the default template charset.
757 770
      *
758 771
      * @param string $charset The default charset
... ...
@@ -1490,7 +1490,7 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = a
1490 1490
 function twig_source(Twig_Environment $env, $name, $ignoreMissing = false)
1491 1491
 {
1492 1492
     try {
1493
-        return $env->getLoader()->getSource($name);
1493
+        return $env->getSourceContext($name)->getCode();
1494 1494
     } catch (Twig_Error_Loader $e) {
1495 1495
         if (!$ignoreMissing) {
1496 1496
             throw $e;
... ...
@@ -21,7 +21,7 @@
21 21
  *
22 22
  * @author Fabien Potencier <fabien@symfony.com>
23 23
  */
24
-class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
24
+class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
25 25
 {
26 26
     protected $templates = array();
27 27
 
... ...
@@ -51,6 +51,8 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
51 51
      */
52 52
     public function getSource($name)
53 53
     {
54
+        @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
55
+
54 56
         $name = (string) $name;
55 57
         if (!isset($this->templates[$name])) {
56 58
             throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
... ...
@@ -62,6 +64,19 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
62 64
     /**
63 65
      * {@inheritdoc}
64 66
      */
67
+    public function getSourceContext($name)
68
+    {
69
+        $name = (string) $name;
70
+        if (!isset($this->templates[$name])) {
71
+            throw new Twig_Error_Loader(sprintf('Template "%s" is not defined.', $name));
72
+        }
73
+
74
+        return new Twig_Source($this->templates[$name], $name);
75
+    }
76
+
77
+    /**
78
+     * {@inheritdoc}
79
+     */
65 80
     public function exists($name)
66 81
     {
67 82
         return isset($this->templates[(string) $name]);
... ...
@@ -47,6 +47,8 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
47 47
      */
48 48
     public function getSource($name)
49 49
     {
50
+        @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
51
+
50 52
         $exceptions = array();
51 53
         foreach ($this->loaders as $loader) {
52 54
             if ($loader instanceof Twig_ExistsLoaderInterface && !$loader->exists($name)) {
... ...
@@ -109,7 +111,11 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf
109 111
             }
110 112
 
111 113
             try {
112
-                $loader->getSource($name);
114
+                if ($loader instanceof Twig_SourceContextLoaderInterface) {
115
+                    $loader->getSourceContext($name);
116
+                } else {
117
+                    $loader->getSource($name);
118
+                }
113 119
 
114 120
                 return $this->hasSourceCache[$name] = true;
115 121
             } catch (Twig_Error_Loader $e) {
... ...
@@ -138,6 +138,8 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI
138 138
      */
139 139
     public function getSource($name)
140 140
     {
141
+        @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
142
+
141 143
         return file_get_contents($this->findTemplate($name));
142 144
     }
143 145
 
... ...
@@ -27,19 +27,29 @@
27 27
  *
28 28
  * @author Fabien Potencier <fabien@symfony.com>
29 29
  */
30
-class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
30
+class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface
31 31
 {
32 32
     /**
33 33
      * {@inheritdoc}
34 34
      */
35 35
     public function getSource($name)
36 36
     {
37
+        @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED);
38
+
37 39
         return $name;
38 40
     }
39 41
 
40 42
     /**
41 43
      * {@inheritdoc}
42 44
      */
45
+    public function getSourceContext($name)
46
+    {
47
+        return new Twig_Source($name, $name);
48
+    }
49
+
50
+    /**
51
+     * {@inheritdoc}
52
+     */
43 53
     public function exists($name)
44 54
     {
45 55
         return true;
... ...
@@ -24,6 +24,8 @@ interface Twig_LoaderInterface
24 24
      * @return string The template source code
25 25
      *
26 26
      * @throws Twig_Error_Loader When $name is not found
27
+     *
28
+     * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface
27 29
      */
28 30
     public function getSource($name);
29 31
 
... ...
@@ -9,6 +9,13 @@
9 9
  * file that was distributed with this source code.
10 10
  */
11 11
 
12
+/**
13
+ * Adds a getSourceContext() method for loaders.
14
+ *
15
+ * @author Fabien Potencier <fabien@symfony.com>
16
+ *
17
+ * @deprecated since 1.27 (to be removed in 3.0)
18
+ */
12 19
 interface Twig_SourceContextLoaderInterface
13 20
 {
14 21
     /**
... ...
@@ -212,8 +212,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
212 212
 
213 213
                 foreach (array_keys($templates) as $name) {
214 214
                     echo "Template: $name\n";
215
-                    $source = $loader->getSource($name);
216
-                    echo $twig->compile($twig->parse($twig->tokenize($source, $name)));
215
+                    echo $twig->compile($twig->parse($twig->tokenize($twig->getSourceContext($name), $name)));
217 216
                 }
218 217
             }
219 218
             $this->assertEquals($expected, $output, $message.' (in '.$file.')');
... ...
@@ -71,9 +71,14 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
71 71
 
72 72
     public function testGlobals()
73 73
     {
74
+        // to be removed in 2.0
75
+        $loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
76
+        //$loader = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
77
+        $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', '')));
78
+
74 79
         // globals can be added after calling getGlobals
75 80
 
76
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
81
+        $twig = new Twig_Environment($loader);
77 82
         $twig->addGlobal('foo', 'foo');
78 83
         $twig->getGlobals();
79 84
         $twig->addGlobal('foo', 'bar');
... ...
@@ -81,7 +86,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
81 86
         $this->assertEquals('bar', $globals['foo']);
82 87
 
83 88
         // globals can be modified after a template has been loaded
84
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
89
+        $twig = new Twig_Environment($loader);
85 90
         $twig->addGlobal('foo', 'foo');
86 91
         $twig->getGlobals();
87 92
         $twig->loadTemplate('index');
... ...
@@ -90,7 +95,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
90 95
         $this->assertEquals('bar', $globals['foo']);
91 96
 
92 97
         // globals can be modified after extensions init
93
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
98
+        $twig = new Twig_Environment($loader);
94 99
         $twig->addGlobal('foo', 'foo');
95 100
         $twig->getGlobals();
96 101
         $twig->getFunctions();
... ...
@@ -99,7 +104,8 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
99 104
         $this->assertEquals('bar', $globals['foo']);
100 105
 
101 106
         // globals can be modified after extensions and a template has been loaded
102
-        $twig = new Twig_Environment($loader = new Twig_Loader_Array(array('index' => '{{foo}}')));
107
+        $arrayLoader = new Twig_Loader_Array(array('index' => '{{foo}}'));
108
+        $twig = new Twig_Environment($arrayLoader);
103 109
         $twig->addGlobal('foo', 'foo');
104 110
         $twig->getGlobals();
105 111
         $twig->getFunctions();
... ...
@@ -108,7 +114,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
108 114
         $globals = $twig->getGlobals();
109 115
         $this->assertEquals('bar', $globals['foo']);
110 116
 
111
-        $twig = new Twig_Environment($loader);
117
+        $twig = new Twig_Environment($arrayLoader);
112 118
         $twig->getGlobals();
113 119
         $twig->addGlobal('foo', 'bar');
114 120
         $template = $twig->loadTemplate('index');
... ...
@@ -116,7 +122,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
116 122
 
117 123
         /* to be uncomment in Twig 2.0
118 124
         // globals cannot be added after a template has been loaded
119
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
125
+        $twig = new Twig_Environment($loader);
120 126
         $twig->addGlobal('foo', 'foo');
121 127
         $twig->getGlobals();
122 128
         $twig->loadTemplate('index');
... ...
@@ -128,7 +134,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
128 134
         }
129 135
 
130 136
         // globals cannot be added after extensions init
131
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
137
+        $twig = new Twig_Environment($loader);
132 138
         $twig->addGlobal('foo', 'foo');
133 139
         $twig->getGlobals();
134 140
         $twig->getFunctions();
... ...
@@ -140,7 +146,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
140 146
         }
141 147
 
142 148
         // globals cannot be added after extensions and a template has been loaded
143
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
149
+        $twig = new Twig_Environment($loader);
144 150
         $twig->addGlobal('foo', 'foo');
145 151
         $twig->getGlobals();
146 152
         $twig->getFunctions();
... ...
@@ -153,7 +159,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
153 159
         }
154 160
 
155 161
         // test adding globals after a template has been loaded without call to getGlobals
156
-        $twig = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock());
162
+        $twig = new Twig_Environment($loader);
157 163
         $twig->loadTemplate('index');
158 164
         try {
159 165
             $twig->addGlobal('bar', 'bar');
... ...
@@ -445,11 +451,13 @@ EOF
445 451
 
446 452
     protected function getMockLoader($templateName, $templateContent)
447 453
     {
448
-        $loader = $this->getMockBuilder('Twig_LoaderInterface')->getMock();
454
+        // to be removed in 2.0
455
+        $loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock();
456
+        //$loader = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
449 457
         $loader->expects($this->any())
450
-          ->method('getSource')
458
+          ->method('getSourceContext')
451 459
           ->with($templateName)
452
-          ->will($this->returnValue($templateContent));
460
+          ->will($this->returnValue(new Twig_Source($templateContent, $templateName)));
453 461
         $loader->expects($this->any())
454 462
           ->method('getCacheKey')
455 463
           ->with($templateName)
... ...
@@ -597,3 +605,7 @@ class Twig_Tests_EnvironmentTest_Runtime
597 605
         return $name;
598 606
     }
599 607
 }
608
+
609
+interface Twig_EnvironmentTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
610
+{
611
+}
... ...
@@ -11,6 +11,9 @@
11 11
 
12 12
 class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
13 13
 {
14
+    /**
15
+     * @group legacy
16
+     */
14 17
     public function testGetSource()
15 18
     {
16 19
         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
... ...
@@ -19,6 +22,7 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
19 22
     }
20 23
 
21 24
     /**
25
+     * @group legacy
22 26
      * @expectedException Twig_Error_Loader
23 27
      */
24 28
     public function testGetSourceWhenTemplateDoesNotExist()
... ...
@@ -28,6 +32,16 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
28 32
         $loader->getSource('foo');
29 33
     }
30 34
 
35
+    /**
36
+     * @expectedException Twig_Error_Loader
37
+     */
38
+    public function testGetSourceContextWhenTemplateDoesNotExist()
39
+    {
40
+        $loader = new Twig_Loader_Array(array());
41
+
42
+        $loader->getSourceContext('foo');
43
+    }
44
+
31 45
     public function testGetCacheKey()
32 46
     {
33 47
         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
... ...
@@ -50,7 +64,7 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
50 64
         $loader = new Twig_Loader_Array(array());
51 65
         $loader->setTemplate('foo', 'bar');
52 66
 
53
-        $this->assertEquals('bar', $loader->getSource('foo'));
67
+        $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
54 68
     }
55 69
 
56 70
     public function testIsFresh()
... ...
@@ -75,7 +89,7 @@ class Twig_Tests_Loader_ArrayTest extends PHPUnit_Framework_TestCase
75 89
         $loader = new Twig_Loader_Array(array('foo' => 'bar'));
76 90
 
77 91
         $loader->getCacheKey($name);
78
-        $loader->getSource($name);
92
+        $loader->getSourceContext($name);
79 93
         $loader->isFresh($name, time());
80 94
         $loader->setTemplate($name, 'foobar');
81 95
     }
... ...
@@ -11,6 +11,9 @@
11 11
 
12 12
 class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
13 13
 {
14
+    /**
15
+     * @group legacy
16
+     */
14 17
     public function testGetSource()
15 18
     {
16 19
         $loader = new Twig_Loader_Chain(array(
... ...
@@ -35,7 +38,7 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
35 38
         $this->assertSame('', $loader->getSourceContext('foo')->getPath());
36 39
 
37 40
         $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName());
38
-        $this->assertNull($loader->getSourceContext('errors/index.html')->getPath());
41
+        $this->assertSame('', $loader->getSourceContext('errors/index.html')->getPath());
39 42
         $this->assertEquals('baz', $loader->getSourceContext('errors/index.html')->getCode());
40 43
 
41 44
         $this->assertEquals('errors/base.html', $loader->getSourceContext('errors/base.html')->getName());
... ...
@@ -46,6 +49,17 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
46 49
     /**
47 50
      * @expectedException Twig_Error_Loader
48 51
      */
52
+    public function testGetSourceContextWhenTemplateDoesNotExist()
53
+    {
54
+        $loader = new Twig_Loader_Chain(array());
55
+
56
+        $loader->getSourceContext('foo');
57
+    }
58
+
59
+    /**
60
+     * @group legacy
61
+     * @expectedException Twig_Error_Loader
62
+     */
49 63
     public function testGetSourceWhenTemplateDoesNotExist()
50 64
     {
51 65
         $loader = new Twig_Loader_Chain(array());
... ...
@@ -79,17 +93,19 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
79 93
         $loader = new Twig_Loader_Chain();
80 94
         $loader->addLoader(new Twig_Loader_Array(array('foo' => 'bar')));
81 95
 
82
-        $this->assertEquals('bar', $loader->getSource('foo'));
96
+        $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode());
83 97
     }
84 98
 
85 99
     public function testExists()
86 100
     {
87
-        $loader1 = $this->getMockBuilder('Twig_Loader_Array')->setMethods(array('exists', 'getSource'))->disableOriginalConstructor()->getMock();
101
+        $loader1 = $this->getMockBuilder('Twig_Loader_Array')->setMethods(array('exists', 'getSourceContext'))->disableOriginalConstructor()->getMock();
88 102
         $loader1->expects($this->once())->method('exists')->will($this->returnValue(false));
89
-        $loader1->expects($this->never())->method('getSource');
103
+        $loader1->expects($this->never())->method('getSourceContext');
90 104
 
91
-        $loader2 = $this->getMockBuilder('Twig_LoaderInterface')->getMock();
92
-        $loader2->expects($this->once())->method('getSource')->will($this->returnValue('content'));
105
+        // can be removed in 2.0
106
+        $loader2 = $this->getMockBuilder('Twig_ChainTestLoaderInterface')->getMock();
107
+        //$loader2 = $this->getMockBuilder(array('Twig_LoaderInterface', 'Twig_SourceContextLoaderInterface'))->getMock();
108
+        $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Twig_Source('content', 'index')));
93 109
 
94 110
         $loader = new Twig_Loader_Chain();
95 111
         $loader->addLoader($loader1);
... ...
@@ -98,3 +114,7 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase
98 114
         $this->assertTrue($loader->exists('foo'));
99 115
     }
100 116
 }
117
+
118
+interface Twig_ChainTestLoaderInterface extends Twig_LoaderInterface, Twig_SourceContextLoaderInterface
119
+{
120
+}
... ...
@@ -88,9 +88,9 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
88 88
 
89 89
         // do not use realpath here as it would make the test unuseful
90 90
         $this->assertEquals($cacheKey, str_replace('\\', '/', $loader->getCacheKey('@named/named_absolute.html')));
91
-        $this->assertEquals("path (final)\n", $loader->getSource('index.html'));
92
-        $this->assertEquals("path (final)\n", $loader->getSource('@__main__/index.html'));
93
-        $this->assertEquals("named path (final)\n", $loader->getSource('@named/index.html'));
91
+        $this->assertEquals("path (final)\n", $loader->getSourceContext('index.html')->getCode());
92
+        $this->assertEquals("path (final)\n", $loader->getSourceContext('@__main__/index.html')->getCode());
93
+        $this->assertEquals("named path (final)\n", $loader->getSourceContext('@named/index.html')->getCode());
94 94
     }
95 95
 
96 96
     public function getBasePaths()
... ...
@@ -147,7 +147,7 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
147 147
         $loader->addPath($basePath.'/named', 'named');
148 148
 
149 149
         try {
150
-            $loader->getSource('@named/nowhere.html');
150
+            $loader->getSourceContext('@named/nowhere.html');
151 151
         } catch (Exception $e) {
152 152
             $this->assertInstanceof('Twig_Error_Loader', $e);
153 153
             $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage());
... ...
@@ -162,11 +162,11 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
162 162
         $loader->addPath($basePath.'/named', 'named');
163 163
 
164 164
         // prime the cache for index.html in the named namespace
165
-        $namedSource = $loader->getSource('@named/index.html');
165
+        $namedSource = $loader->getSourceContext('@named/index.html')->getCode();
166 166
         $this->assertEquals("named path\n", $namedSource);
167 167
 
168 168
         // get index.html from the main namespace
169
-        $this->assertEquals("path\n", $loader->getSource('index.html'));
169
+        $this->assertEquals("path\n", $loader->getSourceContext('index.html')->getCode());
170 170
     }
171 171
 
172 172
     public function testLoadTemplateAndRenderBlockWithCache()
... ...
@@ -221,6 +221,6 @@ class Twig_Tests_Loader_FilesystemTest extends PHPUnit_Framework_TestCase
221 221
         // $f = new Phar('phar-test.phar');
222 222
         // $f->addFromString('hello.twig', 'hello from phar');
223 223
         $loader->addPath('phar://'.dirname(__FILE__).'/Fixtures/phar/phar-sample.phar');
224
-        $this->assertSame('hello from phar', $loader->getSource('hello.twig'));
224
+        $this->assertSame('hello from phar', $loader->getSourceContext('hello.twig')->getCode());
225 225
     }
226 226
 }