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
This commit is contained in:
commit
1d25a25109
@ -37,7 +37,14 @@ class HttpCache extends BaseHttpCache
|
||||
$this->kernel = $kernel;
|
||||
$this->cacheDir = $cacheDir;
|
||||
|
||||
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge(['debug' => $kernel->isDebug()], $this->getOptions()));
|
||||
$isDebug = $kernel->isDebug();
|
||||
$options = ['debug' => $isDebug];
|
||||
|
||||
if ($isDebug) {
|
||||
$options['stale_if_error'] = 0;
|
||||
}
|
||||
|
||||
parent::__construct($kernel, $this->createStore(), $this->createSurrogate(), array_merge($options, $this->getOptions()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,13 +145,13 @@ class SymfonyQuestionHelperTest extends AbstractQuestionHelperTest
|
||||
);
|
||||
|
||||
$this->assertOutputContains(<<<EOT
|
||||
qqq:
|
||||
qqq:
|
||||
[foo ] foo
|
||||
[żółw ] bar
|
||||
[łabądź] baz
|
||||
>
|
||||
EOT
|
||||
, $output);
|
||||
, $output, true);
|
||||
}
|
||||
|
||||
public function testChoiceQuestionCustomPrompt()
|
||||
@ -168,9 +168,9 @@ EOT
|
||||
$this->assertOutputContains(<<<EOT
|
||||
qqq:
|
||||
[0] foo
|
||||
>ccc>
|
||||
>ccc>
|
||||
EOT
|
||||
, $output);
|
||||
, $output, true);
|
||||
}
|
||||
|
||||
protected function getInputStream($input)
|
||||
@ -200,10 +200,15 @@ EOT
|
||||
return $mock;
|
||||
}
|
||||
|
||||
private function assertOutputContains($expected, StreamOutput $output)
|
||||
private function assertOutputContains($expected, StreamOutput $output, $normalize = false)
|
||||
{
|
||||
rewind($output->getStream());
|
||||
$stream = stream_get_contents($output->getStream());
|
||||
|
||||
if ($normalize) {
|
||||
$stream = str_replace(PHP_EOL, "\n", $stream);
|
||||
}
|
||||
|
||||
$this->assertStringContainsString($expected, $stream);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class PassConfig
|
||||
new ValidateEnvPlaceholdersPass(),
|
||||
new ResolveChildDefinitionsPass(),
|
||||
new RegisterServiceSubscribersPass(),
|
||||
new ResolveParameterPlaceHoldersPass(false),
|
||||
new ResolveParameterPlaceHoldersPass(false, false),
|
||||
new ResolveFactoryClassPass(),
|
||||
new ResolveNamedArgumentsPass(),
|
||||
new AutowireRequiredMethodsPass(),
|
||||
|
@ -24,10 +24,12 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
|
||||
{
|
||||
private $bag;
|
||||
private $resolveArrays;
|
||||
private $throwOnResolveException;
|
||||
|
||||
public function __construct(bool $resolveArrays = true)
|
||||
public function __construct($resolveArrays = true, $throwOnResolveException = true)
|
||||
{
|
||||
$this->resolveArrays = $resolveArrays;
|
||||
$this->throwOnResolveException = $throwOnResolveException;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +63,16 @@ class ResolveParameterPlaceHoldersPass extends AbstractRecursivePass
|
||||
protected function processValue($value, $isRoot = false)
|
||||
{
|
||||
if (\is_string($value)) {
|
||||
$v = $this->bag->resolveValue($value);
|
||||
try {
|
||||
$v = $this->bag->resolveValue($value);
|
||||
} catch (ParameterNotFoundException $e) {
|
||||
if ($this->throwOnResolveException) {
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$v = null;
|
||||
$this->container->getDefinition($this->currentId)->addError($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->resolveArrays || !$v || !\is_array($v) ? $v : $value;
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
|
||||
|
||||
class ResolveParameterPlaceHoldersPassTest extends TestCase
|
||||
{
|
||||
@ -71,6 +72,31 @@ class ResolveParameterPlaceHoldersPassTest extends TestCase
|
||||
$this->assertSame($this->container->getParameterBag()->resolveValue('%env(BAZ)%'), $boundValue);
|
||||
}
|
||||
|
||||
public function testParameterNotFoundExceptionsIsThrown()
|
||||
{
|
||||
$this->expectException(ParameterNotFoundException::class);
|
||||
$this->expectExceptionMessage('The service "baz_service_id" has a dependency on a non-existent parameter "non_existent_param".');
|
||||
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$definition = $containerBuilder->register('baz_service_id');
|
||||
$definition->setArgument(0, '%non_existent_param%');
|
||||
|
||||
$pass = new ResolveParameterPlaceHoldersPass();
|
||||
$pass->process($containerBuilder);
|
||||
}
|
||||
|
||||
public function testParameterNotFoundExceptionsIsNotThrown()
|
||||
{
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
$definition = $containerBuilder->register('baz_service_id');
|
||||
$definition->setArgument(0, '%non_existent_param%');
|
||||
|
||||
$pass = new ResolveParameterPlaceHoldersPass(true, false);
|
||||
$pass->process($containerBuilder);
|
||||
|
||||
$this->assertCount(1, $definition->getErrors());
|
||||
}
|
||||
|
||||
private function createContainerBuilder()
|
||||
{
|
||||
$containerBuilder = new ContainerBuilder();
|
||||
|
Reference in New Issue
Block a user