8000 Enableable ArrayNodeDefinition is disabled for empty configuration by mateuszsip · Pull Request #25789 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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 1 commit
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
Next Next commit
Tests
  • Loading branch information
mateuszsip committed Jan 13, 2018
commit 1b43fbf16aec9ded9867ced2fa177fe35e9b8f46
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,37 @@ public function testCanBeDisabled()
$this->assertTrue($this->getField($enabledNode, 'defaultValue'));
}

public function testNodeThatCanBeEnabledIsDisabledByDefault()
{
$node = new ArrayNodeDefinition('root');
$node->canBeEnabled();

$this->assertTrue($this->getField($node, 'addDefaults'));
$this->assertEquals(array('enabled' => false), $this->getField($node, 'falseEquivalent'));
$this->assertEquals(array('enabled' => true), $this->getField($node, 'trueEquivalent'));
$this->assertEquals(array('enabled' => true), $this->getField($node, 'nullEquivalent'));

$nodeChildren = $this->getField($node, 'children');
$this->assertArrayHasKey('enabled', $nodeChildren);

$enabledNode = $nodeChildren['enabled'];
$this->assertTrue($this->getField($enabledNode, 'default'));
$this->assertFalse($this->getField($enabledNode, 'defaultValue'));
}

public function testEnableableNodeIsDisabledForEmptyConfiguration()
{
$processor = new Processor();
$node = new ArrayNodeDefinition('root');
$node->canBeEnabled();

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

public function testIgnoreExtraKeys()
{
$node = new ArrayNodeDefinition('root');
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\Definitio 7B73 n\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, []);

$this->assertEquals(array('enabled' => false), $result);
}
}
0