isInstanceOf($codeGenProperty, 'Zend_CodeGenerator_Php_Property'); } public function testPropertyReturnsSimpleValue() { $codeGenProperty = new Zend_CodeGenerator_Php_Property(array('name' => 'someVal', 'defaultValue' => 'some string value')); $this->assertEquals(' public $someVal = \'some string value\';', $codeGenProperty->generate()); } public function testPropertyMultilineValue() { $targetValue = array( 5, 'one' => 1, 'two' => '2', ); $expectedSource = << 1, 'two' => '2' ); EOS; $property = new Zend_CodeGenerator_Php_Property(array( 'name' => 'myFoo', 'defaultValue' => $targetValue )); $this->assertEquals($expectedSource, $property->generate()); } public function testPropertyCanProduceContstantModifier() { $codeGenProperty = new Zend_CodeGenerator_Php_Property(array('name' => 'someVal', 'defaultValue' => 'some string value', 'const' => true)); $this->assertEquals(' const someVal = \'some string value\';', $codeGenProperty->generate()); } public function testPropertyCanProduceStaticModifier() { $codeGenProperty = new Zend_CodeGenerator_Php_Property(array('name' => 'someVal', 'defaultValue' => 'some string value', 'static' => true)); $this->assertEquals(' public static $someVal = \'some string value\';', $codeGenProperty->generate()); } /** * @group ZF-6444 */ public function testPropertyWillLoadFromReflection() { $reflectionClass = new Zend_Reflection_Class('Zend_CodeGenerator_Php_TestClassWithManyProperties'); // test property 1 $reflProp = $reflectionClass->getProperty('_bazProperty'); $cgProp = Zend_CodeGenerator_Php_Property::fromReflection($reflProp); $this->assertEquals('_bazProperty', $cgProp->getName()); $this->assertEquals(array(true, false, true), $cgProp->getDefaultValue()->getValue()); $this->assertEquals('private', $cgProp->getVisibility()); $reflProp = $reflectionClass->getProperty('_bazStaticProperty'); // test property 2 $cgProp = Zend_CodeGenerator_Php_Property::fromReflection($reflProp); $this->assertEquals('_bazStaticProperty', $cgProp->getName()); $this->assertEquals(Zend_CodeGenerator_Php_TestClassWithManyProperties::FOO, $cgProp->getDefaultValue()->getValue()); $this->assertTrue($cgProp->isStatic()); $this->assertEquals('private', $cgProp->getVisibility()); } /** * @group ZF-6444 */ public function testPropertyWillEmitStaticModifier() { $codeGenProperty = new Zend_CodeGenerator_Php_Property(array( 'name' => 'someVal', 'static' => true, 'visibility' => 'protected', 'defaultValue' => 'some string value' )); $this->assertEquals(' protected static $someVal = \'some string value\';', $codeGenProperty->generate()); } /** * @group ZF-7205 */ public function testPropertyCanHaveDocblock() { $codeGenProperty = new Zend_CodeGenerator_Php_Property(array( 'name' => 'someVal', 'static' => true, 'visibility' => 'protected', 'defaultValue' => 'some string value', 'docblock' => '@var string $someVal This is some val' )); $expected = <<assertEquals($expected, $codeGenProperty->generate()); } }