/** * Render method * * @param boolean $ret * @return mixed */ public function render($ret = false) { $this->output = '<?php' . PHP_EOL; $this->output .= null !== $this->docblock ? $this->docblock->render(true) . PHP_EOL : null; if (null !== $this->namespace) { $this->output .= $this->namespace->render(true) . PHP_EOL; } if (null !== $this->code) { $this->output .= $this->code->render(true) . PHP_EOL; } if (null !== $this->body) { $this->output .= PHP_EOL . $this->body . PHP_EOL . PHP_EOL; } if ($this->close) { $this->output .= '?>' . PHP_EOL; } if ($ret) { return $this->output; } else { echo $this->output; } }
public function testRender() { $c = ClassGenerator::factory('TestClass'); $c->setAbstract(true)->setParent('TestParent')->setInterface('TestInterface')->addProperty(new PropertyGenerator('testProp', 'string', 'This is a test string'))->addMethod(new MethodGenerator('testMethod')); $code = $c->render(true); ob_start(); $c->render(); $output = ob_get_clean(); $this->assertContains('class TestClass extends TestParent implements TestInterface', $output); $this->assertContains('abstract', $code); $this->assertContains('TestParent', $code); $this->assertContains('TestInterface', $code); $code = (string) $c; $this->assertContains('abstract', $code); $this->assertContains('TestParent', $code); $this->assertContains('TestInterface', $code); }