FunctionTest.php 5.9 KB

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