Skip to content

Instantly share code, notes, and snippets.

@xphere
Created November 26, 2013 09:13
Show Gist options
  • Save xphere/7655486 to your computer and use it in GitHub Desktop.
Save xphere/7655486 to your computer and use it in GitHub Desktop.
Why is the "empty set of test" test not passing?
<?php
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideDefaultValues
*/
public function testDefaultValues($settings)
{
$expected = array(
'tests' => array(
'default' => array(
'path' => 'Tests',
),
),
);
$config = $this->processConfig($settings);
$this->assertEquals($expected, $config);
}
public function provideDefaultValues()
{
return array(
'empty configuration' => array(
array(),
),
'empty set of test' => array(
array(
'tests' => array(),
),
),
'empty test' => array(
array(
'tests' => array(
'default' => array(),
),
),
),
);
}
protected function getConfiguration()
{
return new Configuration();
}
protected function processConfig(array $config)
{
$configuration = $this->getConfiguration();
$processor = new Processor();
return $processor->processConfiguration($configuration, func_get_args());
}
}
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('test_configuration');
$rootNode
->children()
->arrayNode('tests')
->fixXmlConfig('test')
->addDefaultChildrenIfNoneSet('default')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('path')
->defaultValue('Tests')
->end()
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment