Skip to content

Commit 94d3805

Browse files
Merge branch '3.1' into 3.2
* 3.1: 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 bd626bc + bedcf6d commit 94d3805

File tree

6 files changed

+26
-24
lines changed

6 files changed

+26
-24
lines changed

ContainerBuilder.php

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

426426
if (!isset($this->definitions[$id]) && isset($this->aliasDefinitions[$id])) {
427-
return $this->get($this->aliasDefinitions[$id], $invalidBehavior);
427+
return $this->get((string) $this->aliasDefinitions[$id], $invalidBehavior);
428428
}
429429

430430
try {
@@ -1140,14 +1140,14 @@ private function callMethod($service, $call)
11401140
/**
11411141
* Shares a given service in the container.
11421142
*
1143-
* @param Definition $definition
1144-
* @param mixed $service
1145-
* @param string $id
1143+
* @param Definition $definition
1144+
* @param mixed $service
1145+
* @param string|null $id
11461146
*/
11471147
private function shareService(Definition $definition, $service, $id)
11481148
{
1149-
if ($definition->isShared()) {
1150-
$this->services[$lowerId = strtolower($id)] = $service;
1149+
if (null !== $id && $definition->isShared()) {
1150+
$this->services[strtolower($id)] = $service;
11511151
}
11521152
}
11531153

Dumper/YamlDumper.php

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

171-
return sprintf(" %s:\n alias: %s\n public: false", $alias, $id);
171+
return sprintf(" %s:\n alias: %s\n public: false\n", $alias, $id);
172172
}
173173

174174
/**

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

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('');

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public function testOverrideServiceWhenUsingADumpedContainer()
252252
$container->set('bar', $bar = new \stdClass());
253253
$container->setParameter('foo_bar', 'foo_bar');
254254

255-
$this->assertEquals($bar, $container->get('bar'), '->set() overrides an already defined service');
255+
$this->assertSame($bar, $container->get('bar'), '->set() overrides an already defined service');
256256
}
257257

258258
public function testOverrideServiceWhenUsingADumpedContainerAndServiceIsUsedFromAnotherOne()

Tests/Fixtures/yaml/services6.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ services:
2525
class: Request
2626
synthetic: true
2727
lazy: true
28+
another_third_alias_for_foo:
29+
alias: foo
2830
decorator_service:
2931
decorates: decorated
3032
decorator_service_with_name:

0 commit comments

Comments
 (0)