/** * @test */ public function createAbstractClassGenerator() { $class = new Stagehand_PHP_Class('Example'); $class->defineAbstract(); $generator = Stagehand_PHP_Class_CodeGenerator::create($class); $this->assertType('Stagehand_PHP_Class_CodeGenerator_AbstractClass', $generator); }
/** * unticked_class_declaration_statement_1 * class_entry_type T_STRING extends_from implements_list '{' class_statement_list '}' */ protected function unticked_class_declaration_statement_1($params) { $className = $params[1]->getValue(); $class = new Stagehand_PHP_Class($className); if ($params[0] === 'abstract') { $class->defineAbstract(); } elseif ($params[0] === 'final') { $class->defineFinal(); } if ($params[2]) { $class->setParentClass($params[2]); } if ($params[3] && is_array($params[3])) { foreach ($params[3] as $interface) { $class->addInterface($interface); } } $this->_declarClass($class); return parent::execute(__FUNCTION__, $params); }
/** * @test */ public function defineAbstractAndUse() { $className = 'ExampleForAbsctuction'; $class = new Stagehand_PHP_Class($className); $class->defineAbstract(); $propertyA = new Stagehand_PHP_Class_Property('a', 10); $methodB = new Stagehand_PHP_Class_Method('b'); $methodB->setCode("return 'foo';"); $methodC = new Stagehand_PHP_Class_Method('c'); $methodC->defineAbstract(); $class->addProperty($propertyA); $class->addMethod($methodB); $class->addMethod($methodC); $class->load(); $refClass = new ReflectionClass($className); $refMethodB = $refClass->getMethod('b'); $refMethodC = $refClass->getMethod('c'); $this->assertTrue($class->isAbstract()); $this->assertTrue($refClass->isAbstract()); $this->assertFalse($refMethodB->isAbstract()); $this->assertTrue($refMethodC->isAbstract()); require_once dirname(__FILE__) . "/ClassTest/ConcreteClass.php"; $instance = new ConcreteClass(); $this->assertEquals($instance->a, 10); $this->assertEquals($instance->b(), 'foo'); $this->assertEquals($instance->c(), 'bar'); }