예제 #1
0
 /**
  * Returns node attributes including (lazily) calculated ones.
  *
  * @return  array
  * @see     Node::getAttributes()
  */
 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $errors = count($this->errors);
     $failures = count($this->failures);
     if (0 < $errors) {
         $attributes['errors'] = $errors;
     }
     if (0 < $failures) {
         $attributes['failures'] = $failures;
     }
     return $attributes;
 }
 /**
  * @dataProvider provideNodes
  */
 public function testConstruct(array $attributes, Node $node)
 {
     $this->assertSame('Dummy', $node->getType());
     $this->assertSame(array('subNode1', 'subNode2'), $node->getSubNodeNames());
     $this->assertSame(10, $node->getLine());
     $this->assertSame('/** doc comment */', $node->getDocComment()->getText());
     $this->assertSame('value1', $node->subNode1);
     $this->assertSame('value2', $node->subNode2);
     $this->assertTrue(isset($node->subNode1));
     $this->assertTrue(isset($node->subNode2));
     $this->assertFalse(isset($node->subNode3));
     $this->assertSame($attributes, $node->getAttributes());
     return $node;
 }
예제 #3
0
 protected function applyArgs(Node $node)
 {
     if ($node instanceof TextNode) {
         $node->setContent($this->interpolate($node->getContent()));
     } else {
         if ($node instanceof Element) {
             foreach ($node->getAttributes() as $attr => $value) {
                 $node->setAttribute($attr, $this->interpolate($value));
             }
         }
     }
     foreach ($node->getChildren() as $child) {
         $this->applyArgs($child);
     }
 }
예제 #4
0
 /**
  * Returns node attributes including (lazily) calculated ones.
  *
  * @return  array
  * @see     Node::getAttributes()
  */
 public function getAttributes()
 {
     $attributes = parent::getAttributes();
     $tests = count($this->cases);
     $errors = 0;
     $failures = 0;
     $time = 0;
     if (count($this->cases)) {
         foreach ($this->cases as $case) {
             $errors += $case->getAttribute('errors');
             $failures += $case->getAttribute('failures');
             $time += (double) $case->getAttribute('time');
         }
     }
     if (count($this->suites)) {
         foreach ($this->suites as $suite) {
             $errors += $suite->getAttribute('errors');
             $failures += $suite->getAttribute('failures');
             $tests += $suite->getAttribute('tests');
             $time += $suite->getAttribute('time');
         }
     }
     if (0 < $errors) {
         $attributes['errors'] = $errors;
     }
     if (0 < $failures) {
         $attributes['failures'] = $failures;
     }
     if (0 < $tests) {
         $attributes['tests'] = $tests;
     }
     if (0 < $time) {
         $attributes['time'] = $time;
     }
     return $attributes;
 }
예제 #5
0
 /**
  * Returns an array representation of the given Node structure.
  *
  * @param Node $node
  *
  * @return array
  */
 public function toArray(Node $node)
 {
     return array('name' => $node->getName(), 'value' => $node->getValue(), 'attributes' => $node->getAttributes(), 'children' => array_map(function (Node $child) {
         return $this->toArray($child);
     }, $node->getChildren()));
 }