This PR was merged into the 1.x branch.
Discussion
----------
make getSourceContext a requirement for any loader
I'm going to follow the same protocol as for `Twig_ExistsLoaderInterface`.
Commits
-------
21ecba8 made using Twig_SourceContextLoaderInterface required
8c33708 made name required for Twig_Source
... | ... |
@@ -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 |
|
... | ... |
@@ -25,7 +25,7 @@ class Twig_Source |
25 | 25 |
* @param string $name The template logical name |
26 | 26 |
* @param string $path The filesystem path of the template if any |
27 | 27 |
*/ |
28 |
- public function __construct($code, $name = null, $path = null) |
|
28 |
+ public function __construct($code, $name, $path = '') |
|
29 | 29 |
{ |
30 | 30 |
$this->code = $code; |
31 | 31 |
$this->name = $name; |
... | ... |
@@ -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 |
+} |
... | ... |
@@ -47,7 +47,7 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase |
47 | 47 |
public function testArrayExpression($template, $expected) |
48 | 48 |
{ |
49 | 49 |
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false)); |
50 |
- $stream = $env->tokenize(new Twig_Source($template)); |
|
50 |
+ $stream = $env->tokenize(new Twig_Source($template, '')); |
|
51 | 51 |
$parser = new Twig_Parser($env); |
52 | 52 |
|
53 | 53 |
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); |
... | ... |
@@ -167,7 +167,7 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase |
167 | 167 |
public function testStringExpression($template, $expected) |
168 | 168 |
{ |
169 | 169 |
$env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock(), array('cache' => false, 'autoescape' => false, 'optimizations' => 0)); |
170 |
- $stream = $env->tokenize(new Twig_Source($template)); |
|
170 |
+ $stream = $env->tokenize(new Twig_Source($template, '')); |
|
171 | 171 |
$parser = new Twig_Parser($env); |
172 | 172 |
|
173 | 173 |
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); |
... | ... |
@@ -26,7 +26,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
26 | 26 |
$template = '{% § %}'; |
27 | 27 |
|
28 | 28 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
29 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
29 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
30 | 30 |
|
31 | 31 |
$stream->expect(Twig_Token::BLOCK_START_TYPE); |
32 | 32 |
$this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); |
... | ... |
@@ -37,7 +37,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
37 | 37 |
$template = '{{ §() }}'; |
38 | 38 |
|
39 | 39 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
40 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
40 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
41 | 41 |
|
42 | 42 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
43 | 43 |
$this->assertSame('§', $stream->expect(Twig_Token::NAME_TYPE)->getValue()); |
... | ... |
@@ -54,7 +54,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
54 | 54 |
protected function countToken($template, $type, $value = null) |
55 | 55 |
{ |
56 | 56 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
57 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
57 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
58 | 58 |
|
59 | 59 |
$count = 0; |
60 | 60 |
while (!$stream->isEOF()) { |
... | ... |
@@ -79,7 +79,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
79 | 79 |
."}}\n"; |
80 | 80 |
|
81 | 81 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
82 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
82 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
83 | 83 |
|
84 | 84 |
// foo\nbar\n |
85 | 85 |
$this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); |
... | ... |
@@ -99,7 +99,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
99 | 99 |
."}}\n"; |
100 | 100 |
|
101 | 101 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
102 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
102 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
103 | 103 |
|
104 | 104 |
// foo\nbar |
105 | 105 |
$this->assertSame(1, $stream->expect(Twig_Token::TEXT_TYPE)->getLine()); |
... | ... |
@@ -114,7 +114,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
114 | 114 |
$template = '{# '.str_repeat('*', 100000).' #}'; |
115 | 115 |
|
116 | 116 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
117 |
- $lexer->tokenize(new Twig_Source($template)); |
|
117 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
118 | 118 |
|
119 | 119 |
// should not throw an exception |
120 | 120 |
} |
... | ... |
@@ -124,7 +124,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
124 | 124 |
$template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}'; |
125 | 125 |
|
126 | 126 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
127 |
- $lexer->tokenize(new Twig_Source($template)); |
|
127 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
128 | 128 |
|
129 | 129 |
// should not throw an exception |
130 | 130 |
} |
... | ... |
@@ -134,7 +134,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
134 | 134 |
$template = '{{ '.str_repeat('x', 100000).' }}'; |
135 | 135 |
|
136 | 136 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
137 |
- $lexer->tokenize(new Twig_Source($template)); |
|
137 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
138 | 138 |
|
139 | 139 |
// should not throw an exception |
140 | 140 |
} |
... | ... |
@@ -144,7 +144,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
144 | 144 |
$template = '{% '.str_repeat('x', 100000).' %}'; |
145 | 145 |
|
146 | 146 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
147 |
- $lexer->tokenize(new Twig_Source($template)); |
|
147 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
148 | 148 |
|
149 | 149 |
// should not throw an exception |
150 | 150 |
} |
... | ... |
@@ -154,7 +154,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
154 | 154 |
$template = '{{ 922337203685477580700 }}'; |
155 | 155 |
|
156 | 156 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
157 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
157 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
158 | 158 |
$stream->next(); |
159 | 159 |
$node = $stream->next(); |
160 | 160 |
$this->assertEquals('922337203685477580700', $node->getValue()); |
... | ... |
@@ -168,7 +168,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
168 | 168 |
); |
169 | 169 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
170 | 170 |
foreach ($tests as $template => $expected) { |
171 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
171 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
172 | 172 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
173 | 173 |
$stream->expect(Twig_Token::STRING_TYPE, $expected); |
174 | 174 |
} |
... | ... |
@@ -179,7 +179,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
179 | 179 |
$template = 'foo {{ "bar #{ baz + 1 }" }}'; |
180 | 180 |
|
181 | 181 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
182 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
182 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
183 | 183 |
$stream->expect(Twig_Token::TEXT_TYPE, 'foo '); |
184 | 184 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
185 | 185 |
$stream->expect(Twig_Token::STRING_TYPE, 'bar '); |
... | ... |
@@ -196,7 +196,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
196 | 196 |
$template = '{{ "bar \#{baz+1}" }}'; |
197 | 197 |
|
198 | 198 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
199 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
199 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
200 | 200 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
201 | 201 |
$stream->expect(Twig_Token::STRING_TYPE, 'bar #{baz+1}'); |
202 | 202 |
$stream->expect(Twig_Token::VAR_END_TYPE); |
... | ... |
@@ -207,7 +207,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
207 | 207 |
$template = '{{ "bar # baz" }}'; |
208 | 208 |
|
209 | 209 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
210 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
210 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
211 | 211 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
212 | 212 |
$stream->expect(Twig_Token::STRING_TYPE, 'bar # baz'); |
213 | 213 |
$stream->expect(Twig_Token::VAR_END_TYPE); |
... | ... |
@@ -222,7 +222,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
222 | 222 |
$template = '{{ "bar #{x" }}'; |
223 | 223 |
|
224 | 224 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
225 |
- $lexer->tokenize(new Twig_Source($template)); |
|
225 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
226 | 226 |
} |
227 | 227 |
|
228 | 228 |
public function testStringWithNestedInterpolations() |
... | ... |
@@ -230,7 +230,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
230 | 230 |
$template = '{{ "bar #{ "foo#{bar}" }" }}'; |
231 | 231 |
|
232 | 232 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
233 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
233 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
234 | 234 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
235 | 235 |
$stream->expect(Twig_Token::STRING_TYPE, 'bar '); |
236 | 236 |
$stream->expect(Twig_Token::INTERPOLATION_START_TYPE); |
... | ... |
@@ -247,7 +247,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
247 | 247 |
$template = '{% foo "bar #{ "foo#{bar}" }" %}'; |
248 | 248 |
|
249 | 249 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
250 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
250 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
251 | 251 |
$stream->expect(Twig_Token::BLOCK_START_TYPE); |
252 | 252 |
$stream->expect(Twig_Token::NAME_TYPE, 'foo'); |
253 | 253 |
$stream->expect(Twig_Token::STRING_TYPE, 'bar '); |
... | ... |
@@ -265,7 +265,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
265 | 265 |
$template = "{{ 1 and\n0}}"; |
266 | 266 |
|
267 | 267 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
268 |
- $stream = $lexer->tokenize(new Twig_Source($template)); |
|
268 |
+ $stream = $lexer->tokenize(new Twig_Source($template, 'index')); |
|
269 | 269 |
$stream->expect(Twig_Token::VAR_START_TYPE); |
270 | 270 |
$stream->expect(Twig_Token::NUMBER_TYPE, 1); |
271 | 271 |
$stream->expect(Twig_Token::OPERATOR_TYPE, 'and'); |
... | ... |
@@ -273,7 +273,7 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase |
273 | 273 |
|
274 | 274 |
/** |
275 | 275 |
* @expectedException Twig_Error_Syntax |
276 |
- * @expectedExceptionMessage Unclosed "variable" at line 3 |
|
276 |
+ * @expectedExceptionMessage Unclosed "variable" in "index" at line 3 |
|
277 | 277 |
*/ |
278 | 278 |
public function testUnterminatedVariable() |
279 | 279 |
{ |
... | ... |
@@ -287,12 +287,12 @@ bar |
287 | 287 |
'; |
288 | 288 |
|
289 | 289 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
290 |
- $lexer->tokenize(new Twig_Source($template)); |
|
290 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
291 | 291 |
} |
292 | 292 |
|
293 | 293 |
/** |
294 | 294 |
* @expectedException Twig_Error_Syntax |
295 |
- * @expectedExceptionMessage Unclosed "block" at line 3 |
|
295 |
+ * @expectedExceptionMessage Unclosed "block" in "index" at line 3 |
|
296 | 296 |
*/ |
297 | 297 |
public function testUnterminatedBlock() |
298 | 298 |
{ |
... | ... |
@@ -306,6 +306,6 @@ bar |
306 | 306 |
'; |
307 | 307 |
|
308 | 308 |
$lexer = new Twig_Lexer(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
309 |
- $lexer->tokenize(new Twig_Source($template)); |
|
309 |
+ $lexer->tokenize(new Twig_Source($template, 'index')); |
|
310 | 310 |
} |
311 | 311 |
} |
... | ... |
@@ -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( |
... | ... |
@@ -32,10 +35,10 @@ class Twig_Tests_Loader_ChainTest extends PHPUnit_Framework_TestCase |
32 | 35 |
)); |
33 | 36 |
|
34 | 37 |
$this->assertEquals('foo', $loader->getSourceContext('foo')->getName()); |
35 |
- $this->assertNull($loader->getSourceContext('foo')->getPath()); |
|
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 |
} |
... | ... |
@@ -148,7 +148,7 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase |
148 | 148 |
{{ foo }} |
149 | 149 |
{% endmacro %} |
150 | 150 |
EOF |
151 |
- ))); |
|
151 |
+ , 'index'))); |
|
152 | 152 |
} |
153 | 153 |
|
154 | 154 |
protected function getParser() |
... | ... |
@@ -156,7 +156,7 @@ EOF |
156 | 156 |
$parser = new TestParser(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); |
157 | 157 |
$parser->setParent(new Twig_Node()); |
158 | 158 |
$parser->stream = $this->getMockBuilder('Twig_TokenStream')->disableOriginalConstructor()->getMock(); |
159 |
- $parser->stream->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source(''))); |
|
159 |
+ $parser->stream->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Twig_Source('', ''))); |
|
160 | 160 |
|
161 | 161 |
return $parser; |
162 | 162 |
} |