NodeTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Server
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'Zend/Server/Reflection/Node.php';
  23. /**
  24. * Test case for Zend_Server_Reflection_Node
  25. *
  26. * @category Zend
  27. * @package Zend_Server
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Server
  32. */
  33. class Zend_Server_Reflection_NodeTest extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * __construct() test
  37. */
  38. public function test__construct()
  39. {
  40. $node = new Zend_Server_Reflection_Node('string');
  41. $this->assertTrue($node instanceof Zend_Server_Reflection_Node);
  42. $this->assertEquals('string', $node->getValue());
  43. $this->assertTrue(null === $node->getParent());
  44. $children = $node->getChildren();
  45. $this->assertTrue(empty($children));
  46. $child = new Zend_Server_Reflection_Node('array', $node);
  47. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  48. $this->assertEquals('array', $child->getValue());
  49. $this->assertTrue($node === $child->getParent());
  50. $children = $child->getChildren();
  51. $this->assertTrue(empty($children));
  52. $children = $node->getChildren();
  53. $this->assertTrue($child === $children[0]);
  54. }
  55. /**
  56. * setParent() test
  57. */
  58. public function testSetParent()
  59. {
  60. $parent = new Zend_Server_Reflection_Node('string');
  61. $child = new Zend_Server_Reflection_Node('array');
  62. $child->setParent($parent);
  63. $this->assertTrue($parent === $child->getParent());
  64. }
  65. /**
  66. * createChild() test
  67. */
  68. public function testCreateChild()
  69. {
  70. $parent = new Zend_Server_Reflection_Node('string');
  71. $child = $parent->createChild('array');
  72. $this->assertTrue($child instanceof Zend_Server_Reflection_Node);
  73. $this->assertTrue($parent === $child->getParent());
  74. $children = $parent->getChildren();
  75. $this->assertTrue($child === $children[0]);
  76. }
  77. /**
  78. * attachChild() test
  79. */
  80. public function testAttachChild()
  81. {
  82. $parent = new Zend_Server_Reflection_Node('string');
  83. $child = new Zend_Server_Reflection_Node('array');
  84. $parent->attachChild($child);
  85. $this->assertTrue($parent === $child->getParent());
  86. $children = $parent->getChildren();
  87. $this->assertTrue($child === $children[0]);
  88. }
  89. /**
  90. * getChildren() test
  91. */
  92. public function testGetChildren()
  93. {
  94. $parent = new Zend_Server_Reflection_Node('string');
  95. $child = $parent->createChild('array');
  96. $children = $parent->getChildren();
  97. $types = array();
  98. foreach ($children as $c) {
  99. $types[] = $c->getValue();
  100. }
  101. $this->assertTrue(is_array($children));
  102. $this->assertEquals(1, count($children), var_export($types, 1));
  103. $this->assertTrue($child === $children[0]);
  104. }
  105. /**
  106. * hasChildren() test
  107. */
  108. public function testHasChildren()
  109. {
  110. $parent = new Zend_Server_Reflection_Node('string');
  111. $this->assertFalse($parent->hasChildren());
  112. $parent->createChild('array');
  113. $this->assertTrue($parent->hasChildren());
  114. }
  115. /**
  116. * getParent() test
  117. */
  118. public function testGetParent()
  119. {
  120. $parent = new Zend_Server_Reflection_Node('string');
  121. $child = $parent->createChild('array');
  122. $this->assertTrue(null === $parent->getParent());
  123. $this->assertTrue($parent === $child->getParent());
  124. }
  125. /**
  126. * getValue() test
  127. */
  128. public function testGetValue()
  129. {
  130. $parent = new Zend_Server_Reflection_Node('string');
  131. $this->assertEquals('string', $parent->getValue());
  132. }
  133. /**
  134. * setValue() test
  135. */
  136. public function testSetValue()
  137. {
  138. $parent = new Zend_Server_Reflection_Node('string');
  139. $this->assertEquals('string', $parent->getValue());
  140. $parent->setValue('array');
  141. $this->assertEquals('array', $parent->getValue());
  142. }
  143. /**
  144. * getEndPoints() test
  145. */
  146. public function testGetEndPoints()
  147. {
  148. $root = new Zend_Server_Reflection_Node('root');
  149. $child1 = $root->createChild('child1');
  150. $child2 = $root->createChild('child2');
  151. $child1grand1 = $child1->createChild(null);
  152. $child1grand2 = $child1->createChild('child1grand2');
  153. $child2grand1 = $child2->createChild('child2grand1');
  154. $child2grand2 = $child2->createChild('child2grand2');
  155. $child2grand2great1 = $child2grand2->createChild(null);
  156. $child2grand2great2 = $child2grand2->createChild('child2grand2great2');
  157. $endPoints = $root->getEndPoints();
  158. $endPointsArray = array();
  159. foreach ($endPoints as $endPoint) {
  160. $endPointsArray[] = $endPoint->getValue();
  161. }
  162. $test = array(
  163. 'child1',
  164. 'child1grand2',
  165. 'child2grand1',
  166. 'child2grand2',
  167. 'child2grand2great2'
  168. );
  169. $this->assertTrue($test === $endPointsArray, 'Test was [' . var_export($test, 1) . ']; endPoints were [' . var_export($endPointsArray, 1) . ']');
  170. }
  171. }