Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Enableable ArrayNodeDefinition is disabled for empty configuration #25789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ public function canBeEnabled()
->beforeNormalization()
->ifArray()
->then(function ($v) {
$v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true;
if (!isset($v['enabled'])) {
$v['enabled'] = !empty($v);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be is_array($v) && !empty($v) to cover the foo: ~ case, which should work as enable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What tests should we add to make sure it won't happen in the future? Component tests cover null case already. ~ is just a null, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forget my comment. This callback is only triggered for arrays ;)

Copy link
Contributor Author

@mateuszsip mateuszsip Jan 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like ~ in yaml is represented by empty array (?), simple reproducer is available here

}

return $v;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,20 @@ public function testCanBeDisabled()
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
}

public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized()
{
$config = array();

$node = new ArrayNodeDefinition('root');
$node->canBeEnabled();

$this->assertEquals(
array('enabled' => false),
$node->getNode()->normalize($config),
'An enableable node is disabled by default'
);
}

public function testIgnoreExtraKeys()
{
$node = new ArrayNodeDefinition('root');
Expand Down Expand Up @@ -240,6 +254,7 @@ public function getEnableableNodeFixtures()
array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'),
array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'),
array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'),
array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Config\Tests\Definition\Builder;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

Expand Down Expand Up @@ -131,4 +132,22 @@ public function testDefinitionExampleGetsTransferredToNode()
$this->assertInternalType('array', $tree->getExample());
$this->assertEquals('example', $children['child']->getExample());
}

public function testRootNodeThatCanBeEnabledIsDisabledByDefault()
{
$builder = new TreeBuilder();

$builder->root('test')
->canBeEnabled();

$tree = $builder->buildTree();
$children = $tree->getChildren();

$this->assertFalse($children['enabled']->getDefaultValue());

$processor = new Processor();
$result = $processor->process($tree, array());

$this->assertEquals(array('enabled' => false), $result);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.