Skip to content
Permalink
Browse files

Merge branch '4.3' into 4.4

* 4.3:
  Avoid stale-if-error if kernel.debug = true, because it hides errors
  [Console] Fix SymfonyQuestionHelper tests sometimes failing on AppVeyor
  [Workflow] Fix configuration node reference for "initial_marking"
  expand listener in place
  [DI] deferred exceptions in ResolveParameterPlaceHoldersPass
  • Loading branch information
chalasr committed Jan 10, 2020
2 parents d68a4b0 + 1d25a25 commit 36e6ceaeb7ebfb922ba8950e9a2723fdbb793707
@@ -602,7 +602,7 @@ Workflow
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
* `WorkflowInterface::apply()` has a third argument: `array $context = []`.
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
* Removed support of `initial_place`. Use `initial_places` instead.
* Removed support of `initial_place`. Use `initial_marking` instead.
* `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
* `DefinitionBuilder::setInitialPlace()` has been removed, use `DefinitionBuilder::setInitialPlaces()` instead.

@@ -36,7 +36,14 @@ public function __construct(KernelInterface $kernel, string $cacheDir = null)
$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 @@ public function testChoiceQuestionPadding()
);

$this->assertOutputContains(<<<EOT
qqq:
qqq:
[foo ] foo
[żółw ] bar
[łabądź] baz
>
EOT
, $output);
, $output, true);
}

public function testChoiceQuestionCustomPrompt()
@@ -168,9 +168,9 @@ public function testChoiceQuestionCustomPrompt()
$this->assertOutputContains(<<<EOT
qqq:
[0] foo
>ccc>
>ccc>
EOT
, $output);
, $output, true);
}

protected function getInputStream($input)
@@ -200,10 +200,15 @@ protected function createInputInterfaceMock($interactive = true)
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 @@ public function __construct()
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 @@ public function process(ContainerBuilder $container)
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 @@
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 @@ public function testBindingsShouldBeResolved()
$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
{
$containerBuilder = new ContainerBuilder();
@@ -274,7 +274,7 @@ private function sortListeners(string $eventName)
$this->sorted[$eventName] = [];

foreach ($this->listeners[$eventName] as &$listeners) {
foreach ($listeners as $k => $listener) {
foreach ($listeners as $k => &$listener) {
if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure && 2 >= \count($listener)) {
$listener[0] = $listener[0]();
$listener[1] = $listener[1] ?? '__invoke';

0 comments on commit 36e6cea

Please sign in to comment.
You can’t perform that action at this time.