Skip to content

Commit 1d25a25

Browse files
committed
Merge branch '3.4' into 4.3
* 3.4: Avoid stale-if-error if kernel.debug = true, because it hides errors [Console] Fix SymfonyQuestionHelper tests sometimes failing on AppVeyor [DI] deferred exceptions in ResolveParameterPlaceHoldersPass
2 parents d079389 + a0b976f commit 1d25a25

File tree

5 files changed

+58
-9
lines changed

5 files changed

+58
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/HttpCache/HttpCache.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ public function __construct(KernelInterface $kernel, string $cacheDir = null)
3737
$this->kernel = $kernel;
3838
$this->cacheDir = $cacheDir;
3939

40-
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge(['debug' => $kernel->isDebug()], $this->getOptions()));
40+
$isDebug = $kernel->isDebug();
41+
$options = ['debug' => $isDebug];
42+
43+
if ($isDebug) {
44+
$options['stale_if_error'] = 0;
45+
}
46+
47+
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($options, $this->getOptions()));
4148
}
4249

4350
/**

src/Symfony/Component/Console/Tests/Helper/SymfonyQuestionHelperTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ public function testChoiceQuestionPadding()
145145
);
146146

147147
$this->assertOutputContains(<<<EOT
148-
qqq:
148+
qqq:
149149
[foo ] foo
150150
[żółw ] bar
151151
[łabądź] baz
152152
>
153153
EOT
154-
, $output);
154+
, $output, true);
155155
}
156156

157157
public function testChoiceQuestionCustomPrompt()
@@ -168,9 +168,9 @@ public function testChoiceQuestionCustomPrompt()
168168
$this->assertOutputContains(<<<EOT
169169
qqq:
170170
[0] foo
171-
>ccc>
171+
>ccc>
172172
EOT
173-
, $output);
173+
, $output, true);
174174
}
175175

176176
protected function getInputStream($input)
@@ -200,10 +200,15 @@ protected function createInputInterfaceMock($interactive = true)
200200
return $mock;
201201
}
202202

203-
private function assertOutputContains($expected, StreamOutput $output)
203+
private function assertOutputContains($expected, StreamOutput $output, $normalize = false)
204204
{
205205
rewind($output->getStream());
206206
$stream = stream_get_contents($output->getStream());
207+
208+
if ($normalize) {
209+
$stream = str_replace(PHP_EOL, "\n", $stream);
210+
}
211+
207212
$this->assertStringContainsString($expected, $stream);
208213
}
209214
}

src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct()
5252
new ValidateEnvPlaceholdersPass(),
5353
new ResolveChildDefinitionsPass(),
5454
new RegisterServiceSubscribersPass(),
55-
new ResolveParameterPlaceHoldersPass(false),
55+
new ResolveParameterPlaceHoldersPass(false, false),
5656
new ResolveFactoryClassPass(),
5757
new ResolveNamedArgumentsPass(),
5858
new AutowireRequiredMethodsPass(),

src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
2424
{
2525
private $bag;
2626
private $resolveArrays;
27+
private $throwOnResolveException;
2728

28-
public function __construct(bool $resolveArrays = true)
29+
public function __construct($resolveArrays = true, $throwOnResolveException = true)
2930
{
3031
$this->resolveArrays = $resolveArrays;
32+
$this->throwOnResolveException = $throwOnResolveException;
3133
}
3234

3335
/**
@@ -61,7 +63,16 @@ public function process(ContainerBuilder $container)
6163
protected function processValue($value, $isRoot = false)
6264
{
6365
if (\is_string($value)) {
64-
$v = $this->bag->resolveValue($value);
66+
try {
67+
$v = $this->bag->resolveValue($value);
68+
} catch (ParameterNotFoundException $e) {
69+
if ($this->throwOnResolveException) {
70+
throw $e;
71+
}
72+
73+
$v = null;
74+
$this->container->getDefinition($this->currentId)->addError($e->getMessage());
75+
}
6576

6677
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
6778
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1718

1819
class ResolveParameterPlaceHoldersPassTest extends TestCase
1920
{
@@ -71,6 +72,31 @@ public function testBindingsShouldBeResolved()
7172
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
7273
}
7374

75+
public function testParameterNotFoundExceptionsIsThrown()
76+
{
77+
$this->expectException(ParameterNotFoundException::class);
78+
$this->expectExceptionMessage('The service "baz_service_id" has a dependency on a non-existent parameter "non_existent_param".');
79+
80+
$containerBuilder = new ContainerBuilder();
81+
$definition = $containerBuilder->register('baz_service_id');
82+
$definition->setArgument(0, '%non_existent_param%');
83+
84+
$pass = new ResolveParameterPlaceHoldersPass();
85+
$pass->process($containerBuilder);
86+
}
87+
88+
public function testParameterNotFoundExceptionsIsNotThrown()
89+
{
90+
$containerBuilder = new ContainerBuilder();
91+
$definition = $containerBuilder->register('baz_service_id');
92+
$definition->setArgument(0, '%non_existent_param%');
93+
94+
$pass = new ResolveParameterPlaceHoldersPass(true, false);
95+
$pass->process($containerBuilder);
96+
97+
$this->assertCount(1, $definition->getErrors());
98+
}
99+
74100
private function createContainerBuilder()
75101
{
76102
$containerBuilder = new ContainerBuilder();

0 commit comments

Comments
 (0)