bug #26895 [Config] Fixes the valid placeholder types for variable node (romain-pierre)

This PR was merged into the 4.1-dev branch.

Discussion
----------

[Config] Fixes the valid placeholder types for variable node

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | we will see...    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #26894
| License       | MIT

This is a proposition, still in discussion.
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

Commits
-------

9fbdcdbeb9 Fixes the valid placeholder types for variable node
This commit is contained in:
Fabien Potencier 2018-04-16 19:38:06 +02:00
commit d2f8df8054
2 changed files with 15 additions and 1 deletions

View File

@ -539,7 +539,7 @@ abstract class BaseNode implements NodeInterface
$knownTypes = array_keys(self::$placeholders[$this->handlingPlaceholder]);
$validTypes = $this->getValidPlaceholderTypes();
if (array_diff($knownTypes, $validTypes)) {
if ($validTypes && array_diff($knownTypes, $validTypes)) {
$e = new InvalidTypeException(sprintf(
'Invalid type for path "%s". Expected %s, but got %s.',
$this->getPath(),

View File

@ -209,6 +209,19 @@ class ValidateEnvPlaceholdersPassTest extends TestCase
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
}
public function testEnvWithVariableNode(): void
{
$container = new ContainerBuilder();
$container->registerExtension($ext = new EnvExtension());
$container->prependExtensionConfig('env_extension', $expected = array(
'variable_node' => '%env(SOME)%',
));
$this->doProcess($container);
$this->assertSame($expected, $container->resolveEnvPlaceholders($ext->getConfig()));
}
private function doProcess(ContainerBuilder $container): void
{
(new MergeExtensionConfigurationPass())->process($container);
@ -247,6 +260,7 @@ class EnvConfiguration implements ConfigurationInterface
->end()
->arrayNode('simple_array_node')->end()
->enumNode('enum_node')->values(array('a', 'b'))->end()
->variableNode('variable_node')->end()
->end();
return $treeBuilder;