Exemplo n.º 1
0
 /**
  * Tests that no exception is thrown for an unrecognized child if the
  * ignoreExtraKeys option is set to true.
  *
  * Related to testExceptionThrownOnUnrecognizedChild
  */
 public function testIgnoreExtraKeysNoException()
 {
     $node = new ArrayNode('roo');
     $node->setIgnoreExtraKeys(true);
     $node->normalize(array('foo' => 'bar'));
     $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
 }
Exemplo n.º 2
0
 /**
  * Tests that extra keys are not removed when
  * ignoreExtraKeys second option is set to false.
  *
  * Related to testExceptionThrownOnUnrecognizedChild
  */
 public function testIgnoreExtraKeysNotRemoved()
 {
     $node = new ArrayNode('roo');
     $node->setIgnoreExtraKeys(true, false);
     $data = array('foo' => 'bar');
     $this->assertSame($data, $node->normalize($data));
 }
Exemplo n.º 3
0
 /**
  * @dataProvider ignoreAndRemoveMatrixProvider
  */
 public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
 {
     if ($expected instanceof \Exception) {
         $this->setExpectedException(get_class($expected), $expected->getMessage());
     }
     $node = new ArrayNode('root');
     $node->setIgnoreExtraKeys($ignore, $remove);
     $result = $node->normalize(array('foo' => 'bar'));
     $this->assertSame($expected, $result, $message);
 }
 public function testRemappedKeysAreUnset()
 {
     $node = new ArrayNode('root');
     $mappingsNode = new PrototypedArrayNode('mappings');
     $node->addChild($mappingsNode);
     // each item under mappings is just a scalar
     $prototype = new ScalarNode(null, $mappingsNode);
     $mappingsNode->setPrototype($prototype);
     $remappings = array();
     $remappings[] = array('mapping', 'mappings');
     $node->setXmlRemappings($remappings);
     $normalized = $node->normalize(array('mapping' => array('foo', 'bar')));
     $this->assertEquals(array('mappings' => array('foo', 'bar')), $normalized);
 }
Exemplo n.º 5
0
 /**
  * Processes an array of configurations.
  *
  * @param array     $validated  merged and validated array
  * @param array     $validating merging and validating array
  * @param ArrayNode $node       merging node
  * @param ArrayNode $masterNode merged node (master node)
  *
  * @return array list of (validated array, merged node)
  */
 public function process(array $validated, array $validating, ArrayNode $node, ArrayNode $masterNode = null)
 {
     // no setting master node
     if (is_null($masterNode)) {
         // set a node to master node
         $masterNode = $node;
         // has setting
     } else {
         // merge a node to master node
         // enabled master node setting when exists the same key validation
         // check existence for avoid exception trying to set a key that already set
         $childrenAll = $masterNode->getChildren();
         foreach ($node->getChildren() as $name => $child) {
             if (!isset($childrenAll[$name])) {
                 $masterNode->addChild($child);
             }
         }
     }
     // validate root node name, target is merging/validating array
     foreach ($validating as $name => $config) {
         if ($masterNode->getName() !== $name || $node->getName() !== $name) {
             throw new \Exception(sprintf('Settings root[%s] is different from Configuration root[%s] or part[%s].', $name, $masterNode->getName(), $node->getName()));
         }
     }
     // directly set validated array without normalize/merge/finalize
     $currentConfig = $validated;
     // loop a validating array
     foreach ($validating as $config) {
         // execute a node's normalize to validate key
         $config = $node->normalize($config);
         // execute a master node's merge to reflect cannotBeOverwritten key setting and so on
         $currentConfig = $masterNode->merge($currentConfig, $config);
     }
     // execute a master node's finalize
     $finalized = $masterNode->finalize($currentConfig);
     return array($finalized, $masterNode);
 }
Exemplo n.º 6
0
 /**
  * Tests the opposite of the testMappedAttributeKeyIsRemoved because
  * the removal can be toggled with an option.
  */
 public function testMappedAttributeKeyNotRemoved()
 {
     $node = new ArrayNode('root');
     $node->setKeyAttribute('id', false);
     // each item under the root is an array, with two scalar items
     $prototype = new ArrayNode(null, $node);
     $prototype->addChild(new ScalarNode('foo'));
     $prototype->addChild(new ScalarNode('id'));
     // the key attribute will remain
     $node->setPrototype($prototype);
     $children = array();
     $children[] = array('id' => 'item_name', 'foo' => 'bar');
     $normalized = $node->normalize($children);
     $expected = array();
     $expected['item_name'] = array('id' => 'item_name', 'foo' => 'bar');
     $this->assertEquals($expected, $normalized);
 }