8000 Merge branch '3.2' · symfony/symfony@16d33e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16d33e1

Browse files
Merge branch '3.2'
* 3.2: [DI] Add missing legacy group on testLegacy Minor tweaks Fix merge [DI] Dont share service when no id provided Fix Container and PhpDumper test inaccuracies [DI] Fix missing new line after private alias [ClassLoader] Throw an exception if the cache is not writeable Fixing regression in TwigEngine exception handling.
2 parents 9e6d6ba + 1fcb66d commit 16d33e1

File tree

13 files changed

+53
-54
lines changed

13 files changed

+53
-54
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/CachePoolPass.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public function process(ContainerBuilder $container)
3636
}
3737
$seed .= '.'.$container->getParameter('kernel.name').'.'.$container->getParameter('kernel.environment');
3838

39-
$aliases = $container->getAliases();
4039
$attributes = array(
4140
'provider',
4241
'namespace',
@@ -59,9 +58,9 @@ public function process(ContainerBuilder $container)
5958
$tags[0]['namespace'] = $this->getNamespace($seed, $id);
6059
}
6160
if (isset($tags[0]['clearer'])) {
62-
$clearer = strtolower($tags[0]['clearer']);
63-
while (isset($aliases[$clearer])) {
64-
$clearer = (string) $aliases[$clearer];
61+
$clearer = $tags[0]['clearer'];
62+
while ($container->hasAlias($clearer)) {
63+
$clearer = (string) $container->getAlias($clearer);
6564
}
6665
} else {
6766
$clearer = null;

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -320,26 +320,26 @@ public function testAssets()
320320
$packages = $container->getDefinition('assets.packages');
321321

322322
// default package
323-
$defaultPackage = $container->getDefinition($packages->getArgument(0));
323+
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
324324
$this->assertUrlPackage($container, $defaultPackage, array('http://cdn.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
325325

326326
// packages
327327
$packages = $packages->getArgument(1);
328328
$this->assertCount(5, $packages);
329329

330-
$package = $container->getDefinition($packages['images_path']);
330+
$package = $container->getDefinition((string) $packages['images_path']);
331331
$this->assertPathPackage($container, $package, '/foo', 'SomeVersionScheme', '%%s?version=%%s');
332332

333-
$package = $container->getDefinition($packages['images']);
333+
$package = $container->getDefinition((string) $packages['images']);
334334
$this->assertUrlPackage($container, $package, array('http://images1.example.com', 'http://images2.example.com'), '1.0.0', '%%s?version=%%s');
335335

336-
$package = $container->getDefinition($packages['foo']);
336+
$package = $container->getDefinition((string) $packages['foo']);
337337
$this->assertPathPackage($container, $package, '', '1.0.0', '%%s-%%s');
338338

339-
$package = $container->getDefinition($packages['bar']);
339+
$package = $container->getDefinition((string) $packages['bar']);
340340
$this->assertUrlPackage($container, $package, array('https://bar2.example.com'), 'SomeVersionScheme', '%%s?version=%%s');
341341

342-
$package = $container->getDefinition($packages['bar_version_strategy']);
342+
$package = $container->getDefinition((string) $packages['bar_version_strategy']);
343343
$this->assertEquals('assets.custom_version_strategy', (string) $package->getArgument(1));
344344
}
345345

@@ -349,7 +349,7 @@ public function testAssetsDefaultVersionStrategyAsService()
349349
$packages = $container->getDefinition('assets.packages');
350350

351351
// default package
352-
$defaultPackage = $container->getDefinition($packages->getArgument(0));
352+
$defaultPackage = $container->getDefinition((string) $packages->getArgument(0));
353353
$this->assertEquals('assets.custom_version_strategy', (string) $defaultPackage->getArgument(1));
354354
}
355355

@@ -865,7 +865,7 @@ private function assertUrlPackage(ContainerBuilder $container, ChildDefinition $
865865

866866
private function assertVersionStrategy(ContainerBuilder $container, Reference $reference, $version, $format)
867867
{
868-
$versionStrategy = $container->getDefinition($reference);
868+
$versionStrategy = $container->getDefinition((string) $reference);
869869
if (null === $version) {
870870
$this->assertEquals('assets.empty_version_strategy', (string) $reference);
871871
} else {

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ private function createFirewall(ContainerBuilder $container, $id, $firewall, &$a
407407
$config->replaceArgument(8, isset($firewall['access_denied_handler']) ? $firewall['access_denied_handler'] : null);
408408
$config->replaceArgument(9, isset($firewall['access_denied_url']) ? $firewall['access_denied_url'] : null);
409409

410-
$container->setAlias(new Alias('security.user_checker.'.$id, false), $firewall['user_checker']);
410+
$container->setAlias('security.user_checker.'.$id, new Alias($firewall['user_checker'], false));
411411

412412
foreach ($this->factories as $position) {
413413
foreach ($position as $factory) {

src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testFirewalls()
7373
$arguments = $contextDef->getArguments();
7474
$listeners[] = array_map(function ($ref) { return (string) $ref; }, $arguments['index_0']);
7575

76-
$configDef = $container->getDefinition($arguments['index_2']);
76+
$configDef = $container->getDefinition((string) $arguments['index_2']);
7777
$configs[] = array_values($configDef->getArguments());
7878
}
7979

@@ -234,7 +234,7 @@ public function testAccess()
234234
);
235235
} elseif (3 === $i) {
236236
$this->assertEquals('IS_AUTHENTICATED_ANONYMOUSLY', $attributes[0]);
237-
$expression = $container->getDefinition($attributes[1])->getArgument(0);
237+
$expression = $container->getDefinition((string) $attributes[1])->getArgument(0);
238238
$this->assertEquals("token.getUsername() matches '/^admin/'", $expression);
239239
}
240240
}

src/Symfony/Bundle/TwigBundle/TwigEngine.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,12 @@ public function render($name, array $parameters = array())
4949
try {
5050
return parent::render($name, $parameters);
5151
} catch (\Twig_Error $e) {
52-
if ($name instanceof TemplateReference) {
52+
if ($name instanceof TemplateReference && !method_exists($e, 'setSourceContext')) {
5353
try {
5454
// try to get the real name of the template where the error occurred
5555
$name = $e->getTemplateName();
5656
$path = (string) $this->locator->locate($this->parser->parse($name));
57-
if (method_exists($e, 'setSourceContext')) {
58-
$e->setSourceContext(new \Twig_Source('', $name, $path));
59-
} else {
60-
$e->setTemplateName($path);
61-
}
57+
$e->setTemplateName($path);
6258
} catch (\Exception $e2) {
6359
}
6460
}

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@ private static function compressCode($code)
305305
*/
306306
private static function writeCacheFile($file, $content)
307307
{
308-
$tmpFile = tempnam(dirname($file), basename($file));
308+
$dir = dirname($file);
309+
if (!is_writable($dir)) {
310+
throw new \RuntimeException(sprintf('Cache directory "%s" is not writable.', $dir));
311+
}
312+
313+
$tmpFile = tempnam($dir, basename($file));
314+
309315
if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
310316
@chmod($file, 0666 & ~umask());
311317

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
436436
}
437437

438438
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
439-
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
439+
return $this->get((string) $this->aliasDefinitions[$id], $invalidBehavior);
440440
}
441441

442442
try {
@@ -1240,14 +1240,14 @@ private function callMethod($service, $call)
12401240
/**
12411241
* Shares a given service in the container.
12421242
*
1243-
* @param Definition $definition
1244-
* @param mixed $service
1245-
* @param string $id
1243+
* @param Definition $definition
1244+
* @param mixed $service
1245+
* @param string|null $id
12461246
*/
12471247
private function shareService(Definition $definition, $service, $id)
12481248
{
1249-
if ($definition->isShared()) {
1250-
$this->services[$lowerId = strtolower($id)] = $service;
1249+
if (null !== $id && $definition->isShared()) {
1250+
$this->services[strtolower($id)] = $service;
12511251
}
12521252
}
12531253

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private function addServiceAlias($alias, $id)
170170
return sprintf(" %s: '@%s'\n", $alias, $id);
171171
}
172172

173-
return sprintf(" %s:\n alias: %s\n public: false", $alias, $id);
173+
return sprintf(" %s:\n alias: %s\n public: false\n", $alias, $id);
174174
}
175175

176176
/**

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ public function testCreateDefinition()
213213
$this->assertCount(1, $container->getDefinition('coop_tilleuls')->getArguments());
214214
$this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas', $container->getDefinition('coop_tilleuls')->getArgument(0));
215215

216-
$dunglasDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\dunglas');
216+
$dunglasDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Dunglas');
217217
$this->assertEquals(__NAMESPACE__.'\Dunglas', $dunglasDefinition->getClass());
218218
$this->assertFalse($dunglasDefinition->isPublic());
219219
$this->assertCount(1, $dunglasDefinition->getArguments());
220220
$this->assertEquals('autowired.symfony\component\dependencyinjection\tests\compiler\lille', $dunglasDefinition->getArgument(0));
221221

222-
$lilleDefinition = $container->getDefinition('autowired.symfony\component\dependencyinjection\tests\compiler\lille');
222+
$lilleDefinition = $container->getDefinition('autowired.Symfony\Component\DependencyInjection\Tests\Compiler\Lille');
223223
$this->assertEquals(__NAMESPACE__.'\Lille', $lilleDefinition->getClass());
224224
}
225225

src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public function testSet()
144144
{
145145
$sc = new Container();
146146
$sc->set('foo', $foo = new \stdClass());
147-
$this->assertEquals($foo, $sc->get('foo'), '->set() sets a service');
147+
$this->assertSame($foo, $sc->get('foo'), '->set() sets a service');
148148
}
149149

150150
public function testSetWithNullResetTheService()
@@ -166,14 +166,14 @@ public function testGet()
166166
{
167167
$sc = new ProjectServiceContainer();
168168
$sc->set('foo', $foo = new \stdClass());
169-
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
170-
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
171-
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
172-
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
173-
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
169+
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
170+
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
171+
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
172+
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
173+
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
174174

175175
$sc->set('bar', $bar = new \stdClass());
176-
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
176+
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
177177

178178
try {
179179
$sc->get('');
@@ -196,15 +196,15 @@ public function testLegacyGet()
196196
$sc = new LegacyProjectServiceContainer();
197197
$sc->set('foo', $foo = new \stdClass());
198198

199-
$this->assertEquals($foo, $sc->get('foo'), '->get() returns the service for the given id');
200-
$this->assertEquals($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
201-
$this->assertEquals($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
202-
$this->assertEquals($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
203-
$this->assertEquals($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
204-
$this->assertEquals($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
199+
$this->assertSame($foo, $sc->get('foo'), '->get() returns the service for the given id');
200+
$this->assertSame($foo, $sc->get('Foo'), '->get() returns the service for the given id, and converts id to lowercase');
201+
$this->assertSame($sc->__bar, $sc->get('bar'), '->get() returns the service for the given id');
202+
$this->assertSame($sc->__foo_bar, $sc->get('foo_bar'), '->get() returns the service if a get*Method() is defined');
203+
$this->assertSame($sc->__foo_baz, $sc->get('foo.baz'), '->get() returns the service if a get*Method() is defined');
204+
$this->assertSame($sc->__foo_baz, $sc->get('foo\\baz'), '->get() returns the service if a get*Method() is defined');
205205

206206
$sc->set('bar', $bar = new \stdClass());
207-
$this->assertEquals($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
207+
$this->assertSame($bar, $sc->get('bar'), '->get() prefers to return a service defined with set() than one defined with a getXXXMethod()');
208208

209209
try {
210210
$sc->get('');

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function testOverrideServiceWhenUsingADumpedContainer()
272272
$container->set('bar', $bar = new \stdClass());
273273
$container->setParameter('foo_bar', 'foo_bar');
274274

275-
$this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service');
275+
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
276276
}
277277

278278
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()
@@ -308,7 +308,7 @@ public function testDumpAutowireData()
308308
$container->compile();
309309
$dumper = new PhpDumper($container);
310310

311-
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services24.php'), $dumper->dump());
311+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services24.php', $dumper->dump());
312312
}
313313

314314
public function testEnvParameter()
@@ -466,8 +466,7 @@ public function testClosureProxy()
466466
$container->compile();
467467
$dumper = new PhpDumper($container);
468468

469-
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy'));
470-
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services31.php'), $dumper->dump());
469+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services31.php', $dumper->dump());
471470
$res = $container->getResources();
472471
$this->assertSame(realpath(self::$fixturesPath.'/containers/container31.php'), array_pop($res)->getResource());
473472
}
@@ -481,8 +480,7 @@ public function testClosureProxyPhp71()
481480
$container->compile();
482481
$dumper = new PhpDumper($container);
483482

484-
$dump = $dumper->dump(array('class' => 'Symfony_DI_PhpDumper_Test_Closure_Proxy_Php71'));
485-
$this->assertEquals(file_get_contents(self::$fixturesPath.'/php/services32.php'), $dumper->dump());
483+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services32.php', $dumper->dump());
486484
$res = $container->getResources();
487485
$this->assertSame(realpath(self::$fixturesPath.'/containers/container32.php'), array_pop($res)->getResource());
488486
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services6.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ services:
1818
calls:
1919
- [ setBar, [ foo, '@foo', [true, false] ] ]
2020
alias_for_foo: '@foo'
21-
another_third_alias_for_foo:
22-
alias: foo
2321
another_alias_for_foo:
2422
alias: foo
2523
public: false
2624
request:
2725
class: Request
2826
synthetic: true
2927
lazy: true
28+
another_third_alias_for_foo:
29+
alias: foo
3030
decorator_service:
3131
decorates: decorated
3232
decorator_service_with_name:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function testGetContainerExtensionWithInvalidClass()
5757
public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAsServices()
5858
{
5959
$container = new ContainerBuilder();
60-
$container->register('console.command.Symfony_Component_HttpKernel_Tests_Fixtures_ExtensionPresentBundle_Command_FooCommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
60+
$container->register('console.command.symfony_component_httpkernel_tests_fixtures_extensionpresentbundle_command_foocommand', 'Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\Command\FooCommand');
6161

6262
$application = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock();
6363
// add() is never called when the found command classes are already registered as services

0 commit comments

Comments
 (0)
0