ReflectionTest.php 5.1 KB

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