Example #1
0
 /**
  * @param TypeFinder $finder
  * @throws \RuntimeException
  * @throws \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
  */
 protected function build(TypeFinder $finder)
 {
     $prototype = $this->getPrototype();
     try {
         $prototype->children()->enumNode(Configuration::TYPE_ATTR)->values($finder->getValidTypes())->end()->end();
     } catch (\InvalidArgumentException $exception) {
         throw new \RuntimeException('No valid types found', $exception->getCode(), $exception);
     }
     foreach ($finder->getValidFields() as $field) {
         $prototype->append(new \Symfony\Component\Config\Definition\Builder\VariableNodeDefinition($field));
     }
     $self = $this;
     $prototype->validate()->ifTrue(function ($v) {
         return is_array($v);
     })->then(function ($v) use($self, $finder) {
         $builder = $self->getNewBuilder();
         $root = $builder->root($v[Configuration::TYPE_ATTR]);
         $root->children()->scalarNode(Configuration::TYPE_ATTR)->isRequired()->end();
         $validator = $finder->getClassFromType($v[Configuration::TYPE_ATTR]);
         if (null === $validator) {
             throw new InvalidConfigurationException(sprintf('No validator defined for type "%s"', $v[Configuration::TYPE_ATTR]));
         }
         $validator::build($root);
         $self->process(array($v[Configuration::TYPE_ATTR] => $v), $builder);
     })->end();
 }
Example #2
0
 public function testGetValidFields()
 {
     $this->if($object = new TestedClass())->then->array($object->getValidFields())->isEqualTo(array('foo', 'bar'))->if($object = new TestedClass())->and($adapter = new \mageekguy\atoum\test\adapter())->and($object->setAdapter($adapter))->and($adapter->get_declared_classes = array())->then->array($object->getValidFields())->isEqualTo(array());
 }