DocblockTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_Reflection
  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. /** requires */
  23. require_once 'Zend/Reflection/File.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Reflection
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Reflection
  31. * @group Zend_Reflection_Docblock
  32. */
  33. class Zend_Reflection_DocblockTest extends PHPUnit_Framework_TestCase
  34. {
  35. static protected $_sampleClassFileRequired = false;
  36. public function setup()
  37. {
  38. if (self::$_sampleClassFileRequired === false) {
  39. $fileToRequire = dirname(__FILE__) . '/_files/TestSampleClass.php';
  40. require_once $fileToRequire;
  41. self::$_sampleClassFileRequired = true;
  42. }
  43. }
  44. public function testDocblockShortDescription()
  45. {
  46. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  47. $this->assertEquals($classReflection->getDocblock()->getShortDescription(), 'TestSampleClass5 Docblock Short Desc');
  48. }
  49. public function testDocblockLongDescription()
  50. {
  51. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  52. $expectedOutput =<<<EOS
  53. This is a long description for
  54. the docblock of this class, it
  55. should be longer than 3 lines.
  56. It indeed is longer than 3 lines
  57. now.
  58. EOS;
  59. $this->assertEquals($classReflection->getDocblock()->getLongDescription(), $expectedOutput);
  60. }
  61. public function testDocblockTags()
  62. {
  63. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  64. $this->assertEquals(count($classReflection->getDocblock()->getTags()), 1);
  65. $this->assertEquals(count($classReflection->getDocblock()->getTags('author')), 1);
  66. $this->assertEquals($classReflection->getDocblock()->getTag('version'), false);
  67. $this->assertEquals($classReflection->getMethod('doSomething')->getDocblock()->hasTag('return'), true);
  68. $returnTag = $classReflection->getMethod('doSomething')->getDocblock()->getTag('return');
  69. $this->assertEquals(get_class($returnTag), 'Zend_Reflection_Docblock_Tag_Return');
  70. $this->assertEquals($returnTag->getType(), 'mixed');
  71. }
  72. public function testDocblockLines()
  73. {
  74. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  75. $classDocblock = $classReflection->getDocblock();
  76. $this->assertEquals($classDocblock->getStartLine(), 76);
  77. $this->assertEquals($classDocblock->getEndLine(), 86);
  78. }
  79. public function testDocblockContents()
  80. {
  81. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  82. $classDocblock = $classReflection->getDocblock();
  83. $expectedContents = <<<EOS
  84. TestSampleClass5 Docblock Short Desc
  85. This is a long description for
  86. the docblock of this class, it
  87. should be longer than 3 lines.
  88. It indeed is longer than 3 lines
  89. now.
  90. @author Ralph Schindler <ralph.schindler@zend.com>
  91. EOS;
  92. $this->assertEquals($classDocblock->getContents(), $expectedContents);
  93. }
  94. public function testToString()
  95. {
  96. $classReflection = new Zend_Reflection_Class('Zend_Reflection_TestSampleClass5');
  97. $classDocblock = $classReflection->getDocblock();
  98. $expectedString = 'Docblock [ /* Docblock */ ] {' . PHP_EOL
  99. . PHP_EOL
  100. . ' - Tags [1] {' . PHP_EOL
  101. . ' Docblock Tag [ * @author ]' . PHP_EOL
  102. . ' }' . PHP_EOL
  103. . '}' . PHP_EOL;
  104. $this->assertEquals($expectedString, (string)$classDocblock);
  105. }
  106. }