Skip to content

Commit ebe5b56

Browse files
committed
Merge branch '2.1' into 2.2
* 2.1: [FrameworkBundle] Fixes invalid serialized objects in cache remove dead code in yaml component fixed typo RedisProfilerStorage wrong db-number/index-number selected [DependencyInjection] added a test for the previous merge (refs #7261) Unset loading[$id] in ContainerBuilder on exception [Console] fixed StringInput binding [Console] added string input test Revert "merged branch jfsimon/issue-6749 (PR #7220)" fixed CS Conflicts: src/Symfony/Component/Console/Tests/Input/StringInputTest.php src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
2 parents b4b6d55 + 8b7cfa0 commit ebe5b56

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ContainerBuilder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,12 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
431431

432432
$this->loading[$id] = true;
433433

434-
$service = $this->createService($definition, $id);
434+
try {
435+
$service = $this->createService($definition, $id);
436+
} catch (\Exception $e) {
437+
unset($this->loading[$id]);
438+
throw $e;
439+
}
435440

436441
unset($this->loading[$id]);
437442

Tests/ContainerBuilderTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\DependencyInjection\ContainerBuilder;
2020
use Symfony\Component\DependencyInjection\ContainerInterface;
2121
use Symfony\Component\DependencyInjection\Definition;
22+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2223
use Symfony\Component\DependencyInjection\Reference;
2324
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2425
use Symfony\Component\Config\Resource\FileResource;
@@ -116,6 +117,26 @@ public function testGet()
116117
$this->assertTrue($builder->get('bar') === $builder->get('bar'), '->get() always returns the same instance if the service is shared');
117118
}
118119

120+
/**
121+
* @covers \Symfony\Component\DependencyInjection\ContainerBuilder::get
122+
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
123+
* @expectedExceptionMessage You have requested a synthetic service ("foo"). The DIC does not know how to construct this service.
124+
*/
125+
public function testGetUnsetLoadingServiceWhenCreateServiceThrowsAnException()
126+
{
127+
$builder = new ContainerBuilder();
128+
$builder->register('foo', 'stdClass')->setSynthetic(true);
129+
130+
// we expect a RuntimeException here as foo is synthetic
131+
try {
132+
$builder->get('foo');
133+
} catch (RuntimeException $e) {
134+
}
135+
136+
// we must also have the same RuntimeException here
137+
$builder->get('foo');
138+
}
139+
119140
/**
120141
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
121142
*/

0 commit comments

Comments
 (0)