コード例 #1
0
 public function testCounterKeySelectorIsAutomaticallySetForChildren()
 {
     $child1 = $this->treeBuilder->leaf();
     $child2 = $this->treeBuilder->tree();
     $child3 = $this->treeBuilder->each();
     $keys = array($child1->buildKey(''), $child2->buildKey(''), $child3->buildKey(''));
     $this->assertInstanceOf('\\TreeBuilder\\NoKey', $keys[0]);
     $this->assertInstanceOf('\\TreeBuilder\\NoKey', $keys[1]);
     $this->assertInstanceOf('\\TreeBuilder\\NoKey', $keys[2]);
 }
コード例 #2
0
 public function testBuildValue()
 {
     $identity = function ($element) {
         return $element;
     };
     $name = function ($element) {
         return $element['name'];
     };
     $child1 = $this->mockedNode($identity, $name);
     $child2 = $this->mockedNode($identity, $name);
     $child1->key(function ($element) {
         return (int) $element['id'];
     });
     $child2->key(function ($element) {
         return (int) $element['id'] + 10;
     });
     $this->treeBuilder->addChild($child1)->addChild($child2);
     $element = array('baseKey' => array(array('id' => '1', 'name' => 'John'), array('id' => '2', 'name' => 'Kate'), array('id' => '3', 'name' => 'William')));
     $expected = array(1 => 'John', 2 => 'Kate', 3 => 'William', 11 => 'John', 12 => 'Kate', 13 => 'William');
     $this->assertEquals($expected, $this->treeBuilder->buildValue($element));
 }