| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_CodeGenerator
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id $
- */
- /** requires */
- require_once 'Zend/Reflection/Method.php';
- require_once 'Zend/CodeGenerator/Php/Method.php';
- require_once 'Zend/Reflection/Docblock.php';
- require_once 'Zend/Reflection/Class.php';
- require_once '_files/TestSampleSingleClass.php';
- /**
- * @category Zend
- * @package Zend_CodeGenerator
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- *
- * @group Zend_CodeGenerator
- * @group Zend_CodeGenerator_Php
- */
- class Zend_CodeGenerator_Php_MethodTest extends PHPUnit_Framework_TestCase
- {
- /**
- * @var Zend_CodeGenerator_Php_Method
- */
- protected $_method = null;
- public function setup()
- {
- $this->_method = new Zend_CodeGenerator_Php_Method();
- }
- public function teardown()
- {
- $this->_method = null;
- }
- public function testMethodConstructor()
- {
- $codeGenMethod = new Zend_CodeGenerator_Php_Method();
- $this->isInstanceOf($codeGenMethod, 'Zend_CodeGenerator_Php_Method');
- }
- public function testMethodParameterAccessors()
- {
- $codeGen = new Zend_CodeGenerator_Php_Method();
- $codeGen->setParameters(array(
- array('name' => 'one')
- ));
- $params = $codeGen->getParameters();
- $param = array_shift($params);
- $this->assertTrue($param instanceof Zend_CodeGenerator_Php_Parameter, 'Failed because $param was not instance of Zend_CodeGenerator_Php_Property');
- }
- public function testMethodBodyGetterAndSetter()
- {
- $this->_method->setBody('Foo');
- $this->assertEquals('Foo', $this->_method->getBody());
- }
- public function testDocblockGetterAndSetter()
- {
- $d = new Zend_CodeGenerator_Php_Docblock();
- $this->_method->setDocblock($d);
- $this->assertTrue($d === $this->_method->getDocblock());
- }
- public function testMethodFromReflection()
- {
- $ref = new Zend_Reflection_Method('Zend_Reflection_TestSampleSingleClass', 'someMethod');
- $codeGenMethod = Zend_CodeGenerator_Php_Method::fromReflection($ref);
- $target = <<<EOS
- /**
- * Enter description here...
- *
- * @return bool
- */
- public function someMethod()
- {
- /* test test */
- }
- EOS;
- $this->assertEquals($target, (string) $codeGenMethod);
- }
- /**
- * @group ZF-6444
- */
- public function testMethodWithStaticModifierIsEmitted()
- {
- $codeGen = new Zend_CodeGenerator_Php_Method();
- $codeGen->setName('foo');
- $codeGen->setParameters(array(
- array('name' => 'one')
- ));
- $codeGen->setStatic(true);
- $expected = <<<EOS
- public static function foo(\$one)
- {
- }
- EOS;
- $this->assertEquals($expected, $codeGen->generate());
- }
- /**
- * @group ZF-6444
- */
- public function testMethodWithFinalModifierIsEmitted()
- {
- $codeGen = new Zend_CodeGenerator_Php_Method();
- $codeGen->setName('foo');
- $codeGen->setParameters(array(
- array('name' => 'one')
- ));
- $codeGen->setFinal(true);
- $expected = <<<EOS
- final public function foo(\$one)
- {
- }
- EOS;
- $this->assertEquals($expected, $codeGen->generate());
- }
- /**
- * @group ZF-6444
- */
- public function testMethodWithFinalModifierIsNotEmittedWhenMethodIsAbstract()
- {
- $codeGen = new Zend_CodeGenerator_Php_Method();
- $codeGen->setName('foo');
- $codeGen->setParameters(array(
- array('name' => 'one')
- ));
- $codeGen->setFinal(true);
- $codeGen->setAbstract(true);
- $expected = <<<EOS
- abstract public function foo(\$one)
- {
- }
- EOS;
- $this->assertEquals($expected, $codeGen->generate());
- }
- /**
- * @group ZF-7205
- */
- public function testMethodCanHaveDocblock()
- {
- $codeGenProperty = new Zend_CodeGenerator_Php_Method(array(
- 'name' => 'someFoo',
- 'static' => true,
- 'visibility' => 'protected',
- 'docblock' => '@var string $someVal This is some val'
- ));
- $expected = <<<EOS
- /**
- * @var string \$someVal This is some val
- */
- protected static function someFoo()
- {
- }
- EOS;
- $this->assertEquals($expected, $codeGenProperty->generate());
- }
- }
|