2
0

ReflectionTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. require_once 'Zend/Server/Reflection.php';
  3. require_once 'PHPUnit/Framework/TestCase.php';
  4. require_once 'PHPUnit/Framework/IncompleteTestError.php';
  5. /**
  6. * Test case for Zend_Server_Reflection
  7. *
  8. * @package Zend_Server
  9. * @subpackage UnitTests
  10. * @version $Id$
  11. */
  12. class Zend_Server_ReflectionTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * reflectClass() test
  16. */
  17. public function testReflectClass()
  18. {
  19. try {
  20. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass');
  21. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Class);
  22. } catch (Exception $e) {
  23. $this->fail('Failed to perform class reflection: ' . $e->getMessage());
  24. }
  25. try {
  26. $reflection = Zend_Server_Reflection::reflectClass(new Zend_Server_Reflection_testClass());
  27. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Class);
  28. } catch (Exception $e) {
  29. $this->fail('Failed to perform object reflection: ' . $e->getMessage());
  30. }
  31. try {
  32. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass', 'string');
  33. $this->fail('Passing non-array for argv should fail');
  34. } catch (Exception $e) {
  35. // do nothing
  36. }
  37. try {
  38. $reflection = Zend_Server_Reflection::reflectClass(false);
  39. $this->fail('Passing non-object/class should fail');
  40. } catch (Exception $e) {
  41. // do nothing
  42. }
  43. }
  44. /**
  45. * reflectClass() test; test namespaces
  46. */
  47. public function testReflectClass2()
  48. {
  49. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass', false, 'zsr');
  50. $this->assertEquals('zsr', $reflection->getNamespace());
  51. }
  52. /**
  53. * reflectFunction() test
  54. */
  55. public function testReflectFunction()
  56. {
  57. try {
  58. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction');
  59. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Function);
  60. } catch (Exception $e) {
  61. $this->fail('Function reflection failed: ' . $e->getMessage());
  62. }
  63. try {
  64. $reflection = Zend_Server_Reflection::reflectFunction(false);
  65. $this->fail('Function reflection should require valid function');
  66. } catch (Exception $e) {
  67. // do nothing
  68. }
  69. try {
  70. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction', 'string');
  71. $this->fail('Argv array should be an array');
  72. } catch (Exception $e) {
  73. // do nothing
  74. }
  75. }
  76. /**
  77. * reflectFunction() test; test namespaces
  78. */
  79. public function testReflectFunction2()
  80. {
  81. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction', false, 'zsr');
  82. $this->assertEquals('zsr', $reflection->getNamespace());
  83. }
  84. }
  85. /**
  86. * Zend_Server_Reflection_testFunction
  87. *
  88. * Used to test reflectFunction generation of signatures
  89. *
  90. * @param boolean $arg1
  91. * @param string|array $arg2
  92. * @param string $arg3 Optional argument
  93. * @param string|struct|false $arg4 Optional argument
  94. * @return boolean|array
  95. */
  96. function Zend_Server_Reflection_testFunction($arg1, $arg2, $arg3 = 'string', $arg4 = 'array')
  97. {
  98. }
  99. /**
  100. * Zend_Server_Reflection_testClass -- test class reflection
  101. */
  102. class Zend_Server_Reflection_testClass
  103. {
  104. /**
  105. * Constructor
  106. *
  107. * This shouldn't be reflected
  108. *
  109. * @param mixed $arg
  110. * @return void
  111. */
  112. public function __construct($arg = null)
  113. {
  114. }
  115. /**
  116. * Public one
  117. *
  118. * @param string $arg1
  119. * @param array $arg2
  120. * @return string
  121. */
  122. public function one($arg1, $arg2 = null)
  123. {
  124. }
  125. /**
  126. * Protected _one
  127. *
  128. * Should not be reflected
  129. *
  130. * @param string $arg1
  131. * @param array $arg2
  132. * @return string
  133. */
  134. protected function _one($arg1, $arg2 = null)
  135. {
  136. }
  137. /**
  138. * Public two
  139. *
  140. * @param string $arg1
  141. * @param string $arg2
  142. * @return boolean|array
  143. */
  144. public static function two($arg1, $arg2)
  145. {
  146. }
  147. }