ClassTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/Class.php';
  23. require_once 'Zend/Server/Reflection.php';
  24. /**
  25. * Test case for Zend_Server_Reflection_Class
  26. *
  27. * @category Zend
  28. * @package Zend_Server
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Server
  33. */
  34. class Zend_Server_Reflection_ClassTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * __construct() test
  38. *
  39. * Call as method call
  40. *
  41. * Expects:
  42. * - reflection:
  43. * - namespace: Optional;
  44. * - argv: Optional; has default;
  45. *
  46. * Returns: void
  47. */
  48. public function test__construct()
  49. {
  50. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  51. $this->assertTrue($r instanceof Zend_Server_Reflection_Class);
  52. $this->assertEquals('', $r->getNamespace());
  53. $methods = $r->getMethods();
  54. $this->assertTrue(is_array($methods));
  55. foreach ($methods as $m) {
  56. $this->assertTrue($m instanceof Zend_Server_Reflection_Method);
  57. }
  58. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'), 'namespace');
  59. $this->assertEquals('namespace', $r->getNamespace());
  60. }
  61. /**
  62. * __call() test
  63. *
  64. * Call as method call
  65. *
  66. * Expects:
  67. * - method:
  68. * - args:
  69. *
  70. * Returns: mixed
  71. */
  72. public function test__call()
  73. {
  74. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  75. $this->assertTrue(is_string($r->getName()));
  76. $this->assertEquals('Zend_Server_Reflection', $r->getName());
  77. }
  78. /**
  79. * test __get/set
  80. */
  81. public function testGetSet()
  82. {
  83. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  84. $r->system = true;
  85. $this->assertTrue($r->system);
  86. }
  87. /**
  88. * getMethods() test
  89. *
  90. * Call as method call
  91. *
  92. * Returns: array
  93. */
  94. public function testGetMethods()
  95. {
  96. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  97. $methods = $r->getMethods();
  98. $this->assertTrue(is_array($methods));
  99. foreach ($methods as $m) {
  100. $this->assertTrue($m instanceof Zend_Server_Reflection_Method);
  101. }
  102. }
  103. /**
  104. * namespace test
  105. */
  106. public function testGetNamespace()
  107. {
  108. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  109. $this->assertEquals('', $r->getNamespace());
  110. $r->setNamespace('namespace');
  111. $this->assertEquals('namespace', $r->getNamespace());
  112. }
  113. /**
  114. * __wakeup() test
  115. *
  116. * Call as method call
  117. *
  118. * Returns: void
  119. */
  120. public function test__wakeup()
  121. {
  122. $r = new Zend_Server_Reflection_Class(new ReflectionClass('Zend_Server_Reflection'));
  123. $s = serialize($r);
  124. $u = unserialize($s);
  125. $this->assertTrue($u instanceof Zend_Server_Reflection_Class);
  126. $this->assertEquals('', $u->getNamespace());
  127. $this->assertEquals($r->getName(), $u->getName());
  128. $rMethods = $r->getMethods();
  129. $uMethods = $r->getMethods();
  130. $this->assertEquals(count($rMethods), count($uMethods));
  131. }
  132. }