public function addMethod($scope, $methodName, array $arguments = array(), $body = array(), array $bodyArguments = array()) { $method = new ClassMethod($methodName, $arguments, $body, $bodyArguments); $method->setScope($scope); $this->methods[] = $method; return $method; }
public function addTest($testName) { $methodName = 'test' . Inflector::classify($testName); $testMethod = new ClassMethod($methodName, array(), array()); $testMethod->setScope('public'); $this->methods[] = $testMethod; return $testMethod; }
protected function appendQueryStatement(ClassMethod $method, BaseDriver $driver, ToSqlInterface $query, ArgumentArray $args) { // build query $sql = $query->toSql($driver, $args); $call = new MethodCallExpr('$this', 'query', [$sql]); $method->getBlock()->appendLine(new Statement($call)); }
/** * @param Block $block * @param ClassFile $class * @param $config * @return bool */ private static function openInMenuBlock(Block $block, UserClass $class, $config) { fwrite(STDOUT, 'processing: ' . $config->module . ':' . $config->controller . ':' . $config->action . "\n"); $elements = Reverse::getElements($config); if ($elements === false) { return false; } $tryStmt = new TryCatchStatement(); $block->appendRenderable($tryStmt); $tryBlock = $tryStmt->tryBlock; $tryBlock->appendRenderable(new Statement(new AssignExpr('$session', new MethodCall('$this', 'getLoggedSession')))); $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'openInMenu', [new ObjectProperty('$this', 'mapModule'), '$session']))); $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkWait', ['$session']))); $tryBlock->appendRenderable(new Statement(new AssignExpr('$page', new MethodCall('$session', 'getPage')))); /** @var FormElement $input */ foreach ($elements->getInputs() as $input) { $tryBlock->appendLine(''); $tryBlock->appendRenderable(new Comment('input type: ' . $input->getType() . ' label: ' . $input->getLabel())); $tryBlock->appendRenderable(new AssignStatement(new Raw($input->getPhpName() . 'Input'), new MethodCall('$page', $input->getFindMethod(), $input->getFindArgs()))); } /** @var Button $button */ foreach ($elements->getButtons() as $button) { $tryBlock->appendLine(''); //$tryBlock->appendRenderable( // new CommentBlock(explode("\n", var_export($button, true))) //); $tryBlock->appendRenderable(new Comment('button label: ' . $button->getLabel())); $tryBlock->appendRenderable(new AssignStatement(new Raw($button->getPhpName() . 'Button'), new MethodCall('$page', $button->getFindMethod(), $button->getFindArgs()))); } $tryBlock->appendLine(''); $tryBlock->appendLine(''); $tryBlock->appendRenderable(new Comment('Implement test here.')); $tryBlock->appendLine(''); $tryBlock->appendLine(''); $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkErrors', ['$session']))); $tryBlock->appendLine(''); $tryBlock->appendLine(''); $tryBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.')); /* $tryBlock->appendRenderable( new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/ $tryBlock->appendLine(''); $tryBlock->appendLine(''); $throwBlock = $tryStmt->catchBlock; $throwBlock->appendRenderable(new Statement(new MethodCall(new StaticMethodCall('Mink', 'getInstance'), 'ss'))); $throwBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.')); /* $throwBlock->appendRenderable( new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/ if ($elements->getDataTables()) { foreach ($elements->getDataTables() as $key => $dataTable) { $doc = new CommentBlock(); $doc->appendLine('Datatable tests'); $dtTest = new ClassMethod('testDataTable' . ($key + 1)); $dtTest->setScope('public'); //$dtTest->setCommentBlock($doc); $block = $dtTest->getBlock(); self::createDataTableTest($dataTable, $block); $class->addMethodObject($dtTest); } } return true; }