8000 Merge branch '3.1' · symfony/symfony@728034c · GitHub
[go: up one dir, main page]

Skip to content

Commit 728034c

Browse files
committed
Merge branch '3.1'
* 3.1: [TwigBundle] fixed usage of getSource in tests Trim constant values in XmlFileLoader move test to the HttpKernel component [TwigBridge] fixed Twig_Source required argument [HttpKernel] Fix a regression in the RequestDataCollector [HttpKernel] Refactor a RequestDataCollector test case to use a data provider
2 parents 923aaad + d1e0ba9 commit 728034c

File tree

12 files changed

+71
-53
lines changed

12 files changed

+71
-53
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 fu 1241 nction 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/DataCollector/RequestDataCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ protected function parseController($controller)
379379
);
380380
}
381381

382-
return (string) $controller ?: 'n/a';
382+
return is_string($controller) ? $controller : 'n/a';
383383
}
384384

385385
private function getCookieHeader($name, $value, $expires, $path, $domain, $secure, $httponly)

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
}

src/Symfony/Component/HttpKernel/Tests/DataCollector/RequestDataCollectorTest.php

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

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

14+
use Symfony\Component\HttpFoundation\RedirectResponse;
1415
use Symfony\Component\HttpFoundation\Session\Session;
1516
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
1617
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
@@ -73,16 +74,28 @@ public function testKernelResponseDoesNotStartSession()
7374
}
7475

7576
/**
76-
* Test various types of controller callables.
77+
* @dataProvider provideControllerCallables
7778
*/
78-
public function testControllerInspection()
79+
public function testControllerInspection($name, $callable, $expected)
80+
{
81+
$c = new RequestDataCollector();
82+
$request = $this->createRequest();
83+
$response = $this->createResponse();
84+
$this->injectController($c, $callable, $request);
85+
$c->collect($request, $response);
86+
87+
$this->assertSame($expected, $c->getController(), sprintf('Testing: %s', $name));
88+
}
89+
90+
public function provideControllerCallables()
7991
{
8092
// make sure we always match the line number
8193
$r1 = new \ReflectionMethod($this, 'testControllerInspection');
8294
$r2 = new \ReflectionMethod($this, 'staticControllerMethod');
8395
$r3 = new \ReflectionClass($this);
96+
8497
// test name, callable, expected
85-
$controllerTests = array(
98+
return array(
8699
array(
87100
'"Regular" callable',
88101
array($this, 'testControllerInspection'),
@@ -171,15 +184,17 @@ function () { return 'foo'; },
171184
),
172185
),
173186
);
187+
}
188+
189+
public function testItIgnoresInvalidCallables()
190+
{
191+
$request = $this->createRequestWithSession();
192+
$response = new RedirectResponse('/');
174193

175194
$c = new RequestDataCollector();
176-
$request = $this->createRequest();
177-
$response = $this->createResponse();
178-
foreach ($controllerTests as $controllerTest) {
179-
$this->injectController($c, $controllerTest[1], $request);
180-
$c->collect($request, $response);
181-
$this->assertSame($controllerTest[2], $c->getController(), sprintf('Testing: %s', $controllerTest[0]));
182-
}
195+
$c->collect($request, $response);
196+
197+
$this->assertSame('n/a', $c->getController());
183198
}
184199

185200
protected function createRequest()
@@ -194,6 +209,16 @@ protected function createRequest()
194209
return $request;
195210
}
196211

212+
private function createRequestWithSession()
213+
{
214+
$request = $this->createRequest();
215+
$request->attributes->set('_controller', 'Foo::bar');
216+
$request->setSession(new Session(new MockArraySessionStorage()));
217+
$request->getSession()->start();
218+
219+
return $request;
220+
}
221+
197222
protected function createResponse()
198223
{
199224
$response = new Response();

0 commit comments

Comments
 (0)
0