Skip to content

Commit

Permalink
[Config] Extra tests for Config component
Browse files Browse the repository at this point in the history
  • Loading branch information
zomberg authored and nicolas-grekas committed Jul 26, 2016
1 parent 50a0f75 commit 0beaac2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tests/Definition/Builder/ArrayNodeDefinitionTest.php
Expand Up @@ -185,6 +185,48 @@ public function testTrueEnableEnabledNode($expected, $config, $message)
);
}

public function testCanBeDisabled()
{
$node = new ArrayNodeDefinition('root');
$node->canBeDisabled();

$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->assertTrue($this->getField($enabledNode, 'defaultValue'));
}

public function testIgnoreExtraKeys()
{
$node = new ArrayNodeDefinition('root');

$this->assertFalse($this->getField($node, 'ignoreExtraKeys'));

$result = $node->ignoreExtraKeys();

$this->assertEquals($node, $result);
$this->assertTrue($this->getField($node, 'ignoreExtraKeys'));
}

public function testNormalizeKeys()
{
$node = new ArrayNodeDefinition('root');

$this->assertTrue($this->getField($node, 'normalizeKeys'));

$result = $node->normalizeKeys(false);

$this->assertEquals($node, $result);
$this->assertFalse($this->getField($node, 'normalizeKeys'));
}

public function getEnableableNodeFixtures()
{
return array(
Expand Down
20 changes: 20 additions & 0 deletions Tests/Definition/Builder/ExprBuilderTest.php
Expand Up @@ -150,6 +150,26 @@ public function testThenUnsetExpression()
$this->assertEquals(array(), $this->finalizeTestBuilder($test));
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You must specify an if part.
*/
public function testEndIfPartNotSpecified()
{
$this->getTestBuilder()->end();
}

/**
* @expectedException \RuntimeException
* @expectedExceptionMessage You must specify a then part.
*/
public function testEndThenPartNotSpecified()
{
$builder = $this->getTestBuilder();
$builder->ifPart = 'test';
$builder->end();
}

/**
* Create a test treebuilder with a variable node, and init the validation.
*
Expand Down

0 comments on commit 0beaac2

Please sign in to comment.