8000 Merge branch '2.8' into 3.1 · src-run/symfony@d1e0ba9 · GitHub
[go: up one dir, main page]

Skip to content

Commit d1e0ba9

Browse files
committed
Merge branch '2.8' into 3.1
* 2.8: [TwigBundle] fixed usage of getSource in tests Trim constant values in XmlFileLoader move test to the HttpKernel component [TwigBridge] fixed Twig_Source required argument
2 parents aa75adf + 5dfaf58 commit d1e0ba9

File tree

10 files changed

+35
-42
lines changed

10 files changed

+35
-42
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/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConsoleCommandPassTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,6 @@ public function testProcessThrowAnExceptionIfTheServiceIsNotASubclassOfCommand()
9090

9191
$container->compile();
9292
}
93-
94-
public function testHttpKernelRegisterCommandsIngoreCommandAsAService()
95-
{
96-
$container = new ContainerBuilder();
97-
$container->addCompilerPass(new AddConsoleCommandPass());
98-
$definition = new Definition('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\MyCommand');
99-
$definition->addTag('console.command');
100-
$container->setDefinition('my-command', $definition);
101-
$container->compile();
102-
103-
$application = $this->getMock('Symfony\Component\Console\Application');
104-
// Never called, because it's the
105-
// Symfony\Bundle\FrameworkBundle\Console\Application that register
106-
// commands as a service
107-
$application->expects($this->never())->method('add');
108-
109-
$bundle = new ExtensionPresentBundle();
110-
$bundle->setContainer($container);
111-
$bundle->registerCommands($application);
112-
}
11393
}
11494

11595
class MyCommand extends Command

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/WebProfilerBundle/Profiler/TemplateManager.php

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

129129
try {
130-
$loader->getSource($template);
130+
if ($loader instanceof \Twig_SourceContextLoaderInterface) {
131+
$loader->getSourceContext($template);
132+
} else {
133+
$loader->getSource($template);
134+
}
131135

132136
return true;
133137
} 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
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $lowercase = true)
391391
$arguments[$key] = $arg->nodeValue;
392392
break;
393393
case 'constant':
394-
$arguments[$key] = constant($arg->nodeValue);
394+
$arguments[$key] = constant(trim($arg->nodeValue));
395395
break;
396396
default:
397397
$arguments[$key] = XmlUtils::phpize($arg->nodeValue);

src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\Bundle;
1313

14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
1415
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
1516
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
1617
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
@@ -51,4 +52,18 @@ public function testGetContainerExtensionWithInvalidClass()
5152
$bundle = new ExtensionNotValidBundle();
5253
$bundle->getContainerExtension();
5354
}
55+
56+
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
57+
{
58+
$container = new ContainerBuilder();
59+
$container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
60+
61+
$application = $this->getMock('Symfony\Component\Console\Application');
62+
// add() is never called when the found command classes are already registered as services
63+
$application->expects($this->never())->method('add');
64+
65+
$bundle = new ExtensionPresentBundle();
66+
$bundle->setContainer($container);
67+
$bundle->registerCommands($application);
68+
}
5469
}

0 commit comments

Comments
 (0)
0