Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 122ac67

Browse files
committed
bug #20271 Changes related to Twig 1.27 (fabpot)
This PR was merged into the 2.7 branch. Discussion ---------- Changes related to Twig 1.27 | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 317d46f [TwigBundle] fixed usage of getSource in tests b9a4586 [TwigBridge] fixed Twig_Source required argument
2 parents 0c551b5 + 317d46f commit 122ac67

File tree

8 files changed

+20
-22
lines changed

8 files changed

+20
-22
lines changed

src/Symfony/Bridge/Twig/Tests/Extension/RoutingExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testEscaping($template, $mustBeEscaped)
2323
$twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('debug' => true, 'cache' => false, 'autoescape' => 'html', 'optimizations' => 0));
2424
$twig->addExtension(new RoutingExtension($this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface')));
2525

26-
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template)));
26+
$nodes = $twig->parse($twig->tokenize(new \Twig_Source($template, '')));
2727

2828
$this->assertSame($mustBeEscaped, $nodes->getNode('body')->getNode(0)->getNode('expr') instanceof \Twig_Node_Expression_Filter);
2929
}

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function getModule($content)
2525
new \Twig_Node_Expression_Array(array(), 0),
2626
new \Twig_Node_Expression_Array(array(), 0),
2727
null,
28-
new \Twig_Source('')
28+
new \Twig_Source('', '')
2929
);
3030
}
3131

src/Symfony/Bridge/Twig/Tests/TokenParser/FormThemeTokenParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testCompile($source, $expected)
2323
{
2424
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
2525
$env->addTokenParser(new FormThemeTokenParser());
26-
$stream = $env->tokenize(new \Twig_Source($source));
26+
$stream = $env->tokenize(new \Twig_Source($source, ''));
2727
$parser = new \Twig_Parser($env);
2828

2929
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));

src/Symfony/Bridge/Twig/Translation/TwigExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function extractTemplate($template, MessageCatalogue $catalogue)
8585
$visitor = $this->twig->getExtension('Symfony\Bridge\Twig\Extension\TranslationExtension')->getTranslationNodeVisitor();
8686
$visitor->enable();
8787

88-
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template)));
88+
$this->twig->parse($this->twig->tokenize(new \Twig_Source($template, '')));
8989

9090
foreach ($visitor->getMessages() as $message) {
9191
$catalogue->set(trim($message[0]), $this->prefix.trim($message[0]), $message[1] ?: $this->defaultDomain);

src/Symfony/Bundle/TwigBundle/Tests/Loader/FilesystemLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class FilesystemLoaderTest extends TestCase
1919
{
20-
public function testGetSource()
20+
public function testGetSourceContext()
2121
{
2222
$parser = $this->getMock('Symfony\Component\Templating\TemplateNameParserInterface');
2323
$locator = $this->getMock('Symfony\Component\Config\FileLocatorInterface');
@@ -30,10 +30,10 @@ public function testGetSource()
3030
$loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views', 'namespace');
3131

3232
// Twig-style
33-
$this->assertEquals("This is a layout\n", $loader->getSource('@namespace/layout.html.twig'));
33+
$this->assertEquals("This is a layout\n", $loader->getSourceContext('@namespace/layout.html.twig')->getCode());
3434

3535
// Symfony-style
36-
$this->assertEquals("This is a layout\n", $loader->getSource('TwigBundle::layout.html.twig'));
36+
$this->assertEquals("This is a layout\n", $loader->getSourceContext('TwigBundle::layout.html.twig')->getCode());
3737
}
3838

3939
public function testExists()

src/Symfony/Bundle/TwigBundle/Tests/TokenParser/LegacyRenderTokenParserTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCompile($source, $expected)
2727
{
2828
$env = new \Twig_Environment($this->getMock('Twig_LoaderInterface'), array('cache' => false, 'autoescape' => false, 'optimizations' => 0));
2929
$env->addTokenParser(new RenderTokenParser());
30-
$stream = $env->tokenize(new \Twig_Source($source));
30+
$stream = $env->tokenize(new \Twig_Source($source, ''));
3131
$parser = new \Twig_Parser($env);
3232

3333
$this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0));

src/Symfony/Bundle/WebProfilerBundle/Profiler/TemplateManager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ protected function templateExists($template)
126126
}
127127

128128
try {
129-
$loader->getSource($template);
129+
if ($loader instanceof \Twig_SourceContextLoaderInterface) {
130+
$loader->getSourceContext($template);
131+
} else {
132+
$loader->getSource($template);
133+
}
130134

131135
return true;
132136
} catch (\Twig_Error_Loader $e) {

src/Symfony/Bundle/WebProfilerBundle/Tests/Profiler/TemplateManagerTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ class TemplateManagerTest extends TestCase
3131
*/
3232
protected $profiler;
3333

34-
/**
35-
* @var \PHPUnit_Framework_MockObject_MockObject
36-
*/
37-
protected $profile;
38-
3934
/**
4035
* @var \Symfony\Bundle\WebProfilerBundle\Profiler\TemplateManager
4136
*/
@@ -129,11 +124,7 @@ public function profileHasCollectorCallback($panel)
129124

130125
protected function mockProfile()
131126
{
132-
$this->profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
133-
->disableOriginalConstructor()
134-
->getMock();
135-
136-
return $this->profile;
127+
return $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')->disableOriginalConstructor()->getMock();
137128
}
138129

139130
protected function mockTwigEnvironment()
@@ -144,9 +135,12 @@ protected function mockTwigEnvironment()
144135
->method('loadTemplate')
145136
->will($this->returnValue('loadedTemplate'));
146137

147-
$this->twigEnvironment->expects($this->any())
148-
->method('getLoader')
149-
->will($this->returnValue($this->getMock('\Twig_LoaderInterface')));
138+
if (interface_exists('\Twig_SourceContextLoaderInterface')) {
139+
$loader = $this->getMock('\Twig_SourceContextLoaderInterface');
140+
} else {
141+
$loader = $this->getMock('\Twig_LoaderInterface');
142+
}
143+
$this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader));
150144

151145
return $this->twigEnvironment;
152146
}

0 commit comments

Comments
 (0)