2
0

MethodTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_CodeGenerator
  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. */
  21. /**
  22. * @see TestHelper
  23. */
  24. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  25. /** requires */
  26. require_once 'Zend/Reflection/Method.php';
  27. require_once 'Zend/CodeGenerator/Php/Method.php';
  28. require_once 'Zend/Reflection/Docblock.php';
  29. require_once 'Zend/Reflection/Class.php';
  30. require_once '_files/TestSampleSingleClass.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_CodeGenerator
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. *
  38. * @group Zend_CodeGenerator_Php
  39. */
  40. class Zend_CodeGenerator_Php_MethodTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * @var Zend_CodeGenerator_Php_Method
  44. */
  45. protected $_method = null;
  46. public function setup()
  47. {
  48. $this->_method = new Zend_CodeGenerator_Php_Method();
  49. }
  50. public function teardown()
  51. {
  52. $this->_method = null;
  53. }
  54. public function testConstructor()
  55. {
  56. $codeGenMethod = new Zend_CodeGenerator_Php_Method();
  57. $this->isInstanceOf($codeGenMethod, 'Zend_CodeGenerator_Php_Method');
  58. }
  59. public function testParameterAccessors()
  60. {
  61. $codeGen = new Zend_CodeGenerator_Php_Method();
  62. $codeGen->setParameters(array(
  63. array('name' => 'one')
  64. ));
  65. }
  66. public function testBodyGetterAndSetter()
  67. {
  68. $this->_method->setBody('Foo');
  69. $this->assertEquals('Foo', $this->_method->getBody());
  70. }
  71. public function testDocblockGetterAndSetter()
  72. {
  73. $d = new Zend_CodeGenerator_Php_Docblock();
  74. $this->_method->setDocblock($d);
  75. $this->assertTrue($d === $this->_method->getDocblock());
  76. }
  77. public function testFromReflection()
  78. {
  79. $ref = new Zend_Reflection_Method('Zend_Reflection_TestSampleSingleClass', 'someMethod');
  80. $codeGenMethod = Zend_CodeGenerator_Php_Method::fromReflection($ref);
  81. $target = <<<EOS
  82. /**
  83. * Enter description here...
  84. *
  85. * @return bool
  86. *
  87. */
  88. public function someMethod()
  89. {
  90. /* test test */
  91. }
  92. EOS;
  93. $this->assertEquals($target, (string) $codeGenMethod);
  94. }
  95. }