Unset fields if no nested fields are defined

This commit is contained in:
Joris van de Sande 2014-03-24 13:13:57 +01:00
parent 514e63f26f
commit 455ff9e0f7
2 changed files with 34 additions and 0 deletions

View file

@ -334,6 +334,10 @@ class Configuration implements ConfigurationInterface
$childrenNode = $node
->useAttributeAsKey('name')
->prototype('array')
->validate()
->ifTrue(function($v) { return isset($v['fields']) && empty($v['fields']); })
->then(function($v) { unset($v['fields']); return $v; })
->end()
->treatNullLike(array())
->addDefaultsIfNotSet()
->children();

View file

@ -103,4 +103,34 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('http://www.github.com/', $configuration['clients']['default']['servers'][0]['url']);
}
public function testEmptyFieldsIndexIsUnset()
{
$config = array(
'indexes' => array(
'test' => array(
'types' => array(
'test' => array(
'mappings' => array(
'title' => array(
'type' => 'string',
'fields' => array(
'autocomplete' => null
)
),
'content' => null
)
)
)
)
)
);
$processor = new Processor();
$configuration = $processor->processConfiguration(new Configuration(array($config)), array($config));
$this->assertArrayNotHasKey('fields', $configuration['indexes']['test']['types']['test']['mappings']['content']);
$this->assertArrayHasKey('fields', $configuration['indexes']['test']['types']['test']['mappings']['title']);
}
}