NodeTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. require_once 'Zend/Server/Reflection/Node.php';
  3. require_once 'PHPUnit/Framework/TestCase.php';
  4. require_once 'PHPUnit/Framework/IncompleteTestError.php';
  5. /**
  6. * Test case for Zend_Server_Reflection_Node
  7. *
  8. * @package ortus
  9. * @version $Id$
  10. */
  11. class Zend_Server_Reflection_NodeTest extends PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * __construct() test
  15. */
  16. public function test__construct()
  17. {
  18. $node = new Zend_Server_Reflection_Node('string');
  19. $this->assertTrue($node instanceof Zend_Server_Reflection_Node);
  20. $this->assertEquals('string', $node->getValue());
  21. $this->assertTrue(null === $node->getParent());
  22. $children = $node->getChildren();
  23. $this->assertTrue(empty($children));
  24. $child = new Zend_Server_Reflection_Node('array', $node);
  25. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  26. $this->assertEquals('array', $child->getValue());
  27. $this->assertTrue($node === $child->getParent());
  28. $children = $child->getChildren();
  29. $this->assertTrue(empty($children));
  30. $children = $node->getChildren();
  31. $this->assertTrue($child === $children[0]);
  32. }
  33. /**
  34. * setParent() test
  35. */
  36. public function testSetParent()
  37. {
  38. $parent = new Zend_Server_Reflection_Node('string');
  39. $child = new Zend_Server_Reflection_Node('array');
  40. $child->setParent($parent);
  41. $this->assertTrue($parent === $child->getParent());
  42. }
  43. /**
  44. * createChild() test
  45. */
  46. public function testCreateChild()
  47. {
  48. $parent = new Zend_Server_Reflection_Node('string');
  49. $child = $parent->createChild('array');
  50. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  51. $this->assertTrue($parent === $child->getParent());
  52. $children = $parent->getChildren();
  53. $this->assertTrue($child === $children[0]);
  54. }
  55. /**
  56. * attachChild() test
  57. */
  58. public function testAttachChild()
  59. {
  60. $parent = new Zend_Server_Reflection_Node('string');
  61. $child = new Zend_Server_Reflection_Node('array');
  62. $parent->attachChild($child);
  63. $this->assertTrue($parent === $child->getParent());
  64. $children = $parent->getChildren();
  65. $this->assertTrue($child === $children[0]);
  66. }
  67. /**
  68. * getChildren() test
  69. */
  70. public function testGetChildren()
  71. {
  72. $parent = new Zend_Server_Reflection_Node('string');
  73. $child = $parent->createChild('array');
  74. $children = $parent->getChildren();
  75. $types = array();
  76. foreach ($children as $c) {
  77. $types[] = $c->getValue();
  78. }
  79. $this->assertTrue(is_array($children));
  80. $this->assertEquals(1, count($children), var_export($types, 1));
  81. $this->assertTrue($child === $children[0]);
  82. }
  83. /**
  84. * hasChildren() test
  85. */
  86. public function testHasChildren()
  87. {
  88. $parent = new Zend_Server_Reflection_Node('string');
  89. $this->assertFalse($parent->hasChildren());
  90. $parent->createChild('array');
  91. $this->assertTrue($parent->hasChildren());
  92. }
  93. /**
  94. * getParent() test
  95. */
  96. public function testGetParent()
  97. {
  98. $parent = new Zend_Server_Reflection_Node('string');
  99. $child = $parent->createChild('array');
  100. $this->assertTrue(null === $parent->getParent());
  101. $this->assertTrue($parent === $child->getParent());
  102. }
  103. /**
  104. * getValue() test
  105. */
  106. public function testGetValue()
  107. {
  108. $parent = new Zend_Server_Reflection_Node('string');
  109. $this->assertEquals('string', $parent->getValue());
  110. }
  111. /**
  112. * setValue() test
  113. */
  114. public function testSetValue()
  115. {
  116. $parent = new Zend_Server_Reflection_Node('string');
  117. $this->assertEquals('string', $parent->getValue());
  118. $parent->setValue('array');
  119. $this->assertEquals('array', $parent->getValue());
  120. }
  121. /**
  122. * getEndPoints() test
  123. */
  124. public function testGetEndPoints()
  125. {
  126. $root = new Zend_Server_Reflection_Node('root');
  127. $child1 = $root->createChild('child1');
  128. $child2 = $root->createChild('child2');
  129. $child1grand1 = $child1->createChild(null);
  130. $child1grand2 = $child1->createChild('child1grand2');
  131. $child2grand1 = $child2->createChild('child2grand1');
  132. $child2grand2 = $child2->createChild('child2grand2');
  133. $child2grand2great1 = $child2grand2->createChild(null);
  134. $child2grand2great2 = $child2grand2->createChild('child2grand2great2');
  135. $endPoints = $root->getEndPoints();
  136. $endPointsArray = array();
  137. foreach ($endPoints as $endPoint) {
  138. $endPointsArray[] = $endPoint->getValue();
  139. }
  140. $test = array(
  141. 'child1',
  142. 'child1grand2',
  143. 'child2grand1',
  144. 'child2grand2',
  145. 'child2grand2great2'
  146. );
  147. $this->assertTrue($test === $endPointsArray, 'Test was [' . var_export($test, 1) . ']; endPoints were [' . var_export($endPointsArray, 1) . ']');
  148. }
  149. }