2
0

ClassTest.php 4.2 KB

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