我有在陽明配置陣列值的Symfony2的配置TreeBuilder作爲驗證,看起來像這樣:在陽明
foobar_template:
templates:
homepage:
name: "Homepage template"
regions: ["top", "main", "left", "bottom"]
layout:
- [ { region: "top", colspan: 4 } ]
- [ { region: "left" }, { region: "main", colspan: 3 } ]
- [ { region: "bottom", colspan: 4 } ]
subpage:
name: "Subpage template"
regions: ["top", "main"]
layout:
- [ { region: "top", colspan: 4 } ]
- [ { region: "main", colspan: 4 } ]
我一直在努力,以確保此配置是根據規範中定義的,但似乎無法確保佈局部分包含至少定義一個區域的條目。目前我的configuration.php包含以下內容:
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('foobar_template');
$rootNode
->children()
->arrayNode('templates')
->useAttributeAsKey('template')
->prototype('array')
->children()
->scalarNode('name')->end()
->arrayNode('regions')
->isRequired()
->requiresAtLeastOneElement()
->prototype('scalar')->end()
->end()
->append($this->addLayoutNode())
->end()
->end()
->end()
->end();
return $treeBuilder;
}
public function addLayoutNode()
{
$builder = new TreeBuilder();
$node = $builder->root('layout');
$node
->isRequired()
->requiresAtLeastOneElement()
->prototype('array')
->prototype('variable')->end()
->end();
return $node;
}
}
但我真的想測試指定的佈局塊包含的區域(即至少包含- [{ region: <region_name> }]
一個片段,所以我應該怎麼用,而不是->prototype('variable')->end()
英寸addLayoutNode()來實際執行這個測試嗎?我嘗試過多種方式,但是在嘗試這樣做時總是遇到一個InvalidDefinitionException或InvalidConfigurationException任何人都知道如何在配置中測試上述內容(我目前正在做一些理智檢查在擴展包的負載中,但是如果配置可以檢查這個,它會更乾淨)