ReflectionTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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.php';
  23. /**
  24. * Test case for Zend_Server_Reflection
  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_ReflectionTest extends PHPUnit_Framework_TestCase
  34. {
  35. /**
  36. * reflectClass() test
  37. */
  38. public function testReflectClass()
  39. {
  40. try {
  41. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass');
  42. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Class);
  43. } catch (Exception $e) {
  44. $this->fail('Failed to perform class reflection: ' . $e->getMessage());
  45. }
  46. try {
  47. $reflection = Zend_Server_Reflection::reflectClass(new Zend_Server_Reflection_testClass());
  48. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Class);
  49. } catch (Exception $e) {
  50. $this->fail('Failed to perform object reflection: ' . $e->getMessage());
  51. }
  52. try {
  53. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass', 'string');
  54. $this->fail('Passing non-array for argv should fail');
  55. } catch (Exception $e) {
  56. // do nothing
  57. }
  58. try {
  59. $reflection = Zend_Server_Reflection::reflectClass(false);
  60. $this->fail('Passing non-object/class should fail');
  61. } catch (Exception $e) {
  62. // do nothing
  63. }
  64. }
  65. /**
  66. * reflectClass() test; test namespaces
  67. */
  68. public function testReflectClass2()
  69. {
  70. $reflection = Zend_Server_Reflection::reflectClass('Zend_Server_Reflection_testClass', false, 'zsr');
  71. $this->assertEquals('zsr', $reflection->getNamespace());
  72. }
  73. /**
  74. * reflectFunction() test
  75. */
  76. public function testReflectFunction()
  77. {
  78. try {
  79. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction');
  80. $this->assertTrue($reflection instanceof Zend_Server_Reflection_Function);
  81. } catch (Exception $e) {
  82. $this->fail('Function reflection failed: ' . $e->getMessage());
  83. }
  84. try {
  85. $reflection = Zend_Server_Reflection::reflectFunction(false);
  86. $this->fail('Function reflection should require valid function');
  87. } catch (Exception $e) {
  88. // do nothing
  89. }
  90. try {
  91. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction', 'string');
  92. $this->fail('Argv array should be an array');
  93. } catch (Exception $e) {
  94. // do nothing
  95. }
  96. }
  97. /**
  98. * reflectFunction() test; test namespaces
  99. */
  100. public function testReflectFunction2()
  101. {
  102. $reflection = Zend_Server_Reflection::reflectFunction('Zend_Server_Reflection_testFunction', false, 'zsr');
  103. $this->assertEquals('zsr', $reflection->getNamespace());
  104. }
  105. }
  106. /**
  107. * Zend_Server_Reflection_testFunction
  108. *
  109. * Used to test reflectFunction generation of signatures
  110. *
  111. * @param boolean $arg1
  112. * @param string|array $arg2
  113. * @param string $arg3 Optional argument
  114. * @param string|struct|false $arg4 Optional argument
  115. * @return boolean|array
  116. */
  117. function Zend_Server_Reflection_testFunction($arg1, $arg2, $arg3 = 'string', $arg4 = 'array')
  118. {
  119. }
  120. /**
  121. * Zend_Server_Reflection_testClass -- test class reflection
  122. */
  123. class Zend_Server_Reflection_testClass
  124. {
  125. /**
  126. * Constructor
  127. *
  128. * This shouldn't be reflected
  129. *
  130. * @param mixed $arg
  131. * @return void
  132. */
  133. public function __construct($arg = null)
  134. {
  135. }
  136. /**
  137. * Public one
  138. *
  139. * @param string $arg1
  140. * @param array $arg2
  141. * @return string
  142. */
  143. public function one($arg1, $arg2 = null)
  144. {
  145. }
  146. /**
  147. * Protected _one
  148. *
  149. * Should not be reflected
  150. *
  151. * @param string $arg1
  152. * @param array $arg2
  153. * @return string
  154. */
  155. protected function _one($arg1, $arg2 = null)
  156. {
  157. }
  158. /**
  159. * Public two
  160. *
  161. * @param string $arg1
  162. * @param string $arg2
  163. * @return boolean|array
  164. */
  165. public static function two($arg1, $arg2)
  166. {
  167. }
  168. }