/** * Class Method Constructor * * @param string $name the function name. * @param array $arguments the argument of the function prototype. * @param string $body the code of the function. * @param array $bodyArguments the template arguments of the code of the function. */ public function __construct($name, array $arguments = array(), $body = '', array $bodyArguments = array()) { $this->name = $name; $this->arguments = $arguments; $this->block = new BracketedBlock(); if ($body) { $this->block->setBody($body); } if ($bodyArguments) { $this->block->setDefaultArguments($bodyArguments); } }
public function testBlockWithSetBody() { $block = new Block(); $block->setBody('${{name}} = 1;'); $block->appendLine('${{name}} = ${{name}} + 1;'); $block->appendLine('return ${{name}};'); $code = $block->render(array('name' => 'a')); $this->assertNotEmpty($code); $ret = eval($code); $this->assertEquals(2, $ret); }