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

Skip to content

Commit 317d46f

Browse files
committed
[TwigBundle] fixed usage of getSource in tests
1 parent b9a4586 commit 317d46f

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

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)