2
0

FunctionTest.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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-2009 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/Function.php';
  23. require_once 'PHPUnit/Framework/TestCase.php';
  24. require_once 'PHPUnit/Framework/IncompleteTestError.php';
  25. /**
  26. * Test case for Zend_Server_Reflection_Function
  27. *
  28. * @category Zend
  29. * @package Zend_Server
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2009 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_Reflection_FunctionTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function test__construct()
  38. {
  39. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  40. $r = new Zend_Server_Reflection_Function($function);
  41. $this->assertTrue($r instanceof Zend_Server_Reflection_Function);
  42. $this->assertTrue($r instanceof Zend_Server_Reflection_Function_Abstract);
  43. $params = $r->getParameters();
  44. try {
  45. $r = new Zend_Server_Reflection_Function($params[0]);
  46. $this->fail('Should not be able to construct with non-function');
  47. } catch (Exception $e) {
  48. // do nothing
  49. }
  50. $r = new Zend_Server_Reflection_Function($function, 'namespace');
  51. $this->assertEquals('namespace', $r->getNamespace());
  52. $argv = array('string1', 'string2');
  53. $r = new Zend_Server_Reflection_Function($function, 'namespace', $argv);
  54. $this->assertTrue(is_array($r->getInvokeArguments()));
  55. $this->assertTrue($argv === $r->getInvokeArguments());
  56. $prototypes = $r->getPrototypes();
  57. $this->assertTrue(is_array($prototypes));
  58. $this->assertTrue(0 < count($prototypes));
  59. }
  60. public function test__getSet()
  61. {
  62. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  63. $r = new Zend_Server_Reflection_Function($function);
  64. $r->system = true;
  65. $this->assertTrue($r->system);
  66. }
  67. public function testNamespace()
  68. {
  69. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  70. $r = new Zend_Server_Reflection_Function($function, 'namespace');
  71. $this->assertEquals('namespace', $r->getNamespace());
  72. $r->setNamespace('framework');
  73. $this->assertEquals('framework', $r->getNamespace());
  74. }
  75. public function testDescription()
  76. {
  77. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  78. $r = new Zend_Server_Reflection_Function($function);
  79. $this->assertContains('function for reflection', $r->getDescription());
  80. $r->setDescription('Testing setting descriptions');
  81. $this->assertEquals('Testing setting descriptions', $r->getDescription());
  82. }
  83. public function testGetPrototypes()
  84. {
  85. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  86. $r = new Zend_Server_Reflection_Function($function);
  87. $prototypes = $r->getPrototypes();
  88. $this->assertTrue(is_array($prototypes));
  89. $this->assertTrue(0 < count($prototypes));
  90. $this->assertEquals(8, count($prototypes));
  91. foreach ($prototypes as $p) {
  92. $this->assertTrue($p instanceof Zend_Server_Reflection_Prototype);
  93. }
  94. }
  95. public function testGetPrototypes2()
  96. {
  97. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function2');
  98. $r = new Zend_Server_Reflection_Function($function);
  99. $prototypes = $r->getPrototypes();
  100. $this->assertTrue(is_array($prototypes));
  101. $this->assertTrue(0 < count($prototypes));
  102. $this->assertEquals(1, count($prototypes));
  103. foreach ($prototypes as $p) {
  104. $this->assertTrue($p instanceof Zend_Server_Reflection_Prototype);
  105. }
  106. }
  107. public function testGetInvokeArguments()
  108. {
  109. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  110. $r = new Zend_Server_Reflection_Function($function);
  111. $args = $r->getInvokeArguments();
  112. $this->assertTrue(is_array($args));
  113. $this->assertEquals(0, count($args));
  114. $argv = array('string1', 'string2');
  115. $r = new Zend_Server_Reflection_Function($function, null, $argv);
  116. $args = $r->getInvokeArguments();
  117. $this->assertTrue(is_array($args));
  118. $this->assertEquals(2, count($args));
  119. $this->assertTrue($argv === $args);
  120. }
  121. public function test__wakeup()
  122. {
  123. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function');
  124. $r = new Zend_Server_Reflection_Function($function);
  125. $s = serialize($r);
  126. $u = unserialize($s);
  127. $this->assertTrue($u instanceof Zend_Server_Reflection_Function);
  128. $this->assertEquals('', $u->getNamespace());
  129. }
  130. public function testMultipleWhitespaceBetweenDoctagsAndTypes()
  131. {
  132. $function = new ReflectionFunction('Zend_Server_Reflection_FunctionTest_function3');
  133. $r = new Zend_Server_Reflection_Function($function);
  134. $prototypes = $r->getPrototypes();
  135. $this->assertTrue(is_array($prototypes));
  136. $this->assertTrue(0 < count($prototypes));
  137. $this->assertEquals(1, count($prototypes));
  138. $proto = $prototypes[0];
  139. $params = $proto->getParameters();
  140. $this->assertTrue(is_array($params));
  141. $this->assertEquals(1, count($params));
  142. $this->assertEquals('string', $params[0]->getType());
  143. }
  144. }
  145. /**
  146. * Zend_Server_Reflection_FunctionTest_function
  147. *
  148. * Test function for reflection unit tests
  149. *
  150. * @param string $var1
  151. * @param string|array $var2
  152. * @param array $var3
  153. * @return null|array
  154. */
  155. function Zend_Server_Reflection_FunctionTest_function($var1, $var2, $var3 = null)
  156. {
  157. }
  158. /**
  159. * Zend_Server_Reflection_FunctionTest_function2
  160. *
  161. * Test function for reflection unit tests; test what happens when no return
  162. * value or params specified in docblock.
  163. */
  164. function Zend_Server_Reflection_FunctionTest_function2()
  165. {
  166. }
  167. /**
  168. * Zend_Server_Reflection_FunctionTest_function3
  169. *
  170. * @param string $var1
  171. * @return void
  172. */
  173. function Zend_Server_Reflection_FunctionTest_function3($var1)
  174. {
  175. }