private function doCompile(string $clsName = '', string $indent = ' ') : UserClass { if ($clsName == '') { $clsName = 'Fruit\\RouteKit\\GeneratedMux'; } $gen = new UserClass($clsName); $gen->implementInterface('Fruit\\RouteKit\\Router'); $in1 = $indent; $in2 = $in1 . $in1; $stateMap = array(); $varMap = array(); $funcMap = array(); $funcCnt = 0; foreach ($this->roots as $m => $root) { $root->fillID(0); $stateMap[$m] = $root->stateTable(array()); $varMap[$m] = $root->varTable(array()); $funcMap[$m] = $root->funcTable(array(), 0, $this->interceptor); // make handlers foreach ($funcMap[$m] as $id => $body) { $fn = sprintf('f%d', $funcCnt++); $gen->addMethod('private static', $fn, array('$method', '$url', '$params', '$int'), $body); $funcMap[$m][$id] = $fn; } } $gen->addStaticVar('stateMap', $stateMap, 'private'); $gen->addStaticVar('varMap', $varMap, 'private'); $gen->addStaticVar('funcMap', $funcMap, 'private'); $gen->addPrivateProperty('interceptor', null); // make dispatcher $func = array(); $func[] = 'list($f, $params) = \\Fruit\\RouteKit\\Mux::findRoute('; $func[] = ' $method, $uri,'; $func[] = ' self::$stateMap,'; $func[] = ' self::$varMap,'; $func[] = ' self::$funcMap'; $func[] = ');'; $func[] = ''; $func[] = 'if ($f === null) {'; $func[] = ' throw new \\Exception(\'No route for \' . $uri);'; $func[] = '}'; $func[] = ''; $func[] = 'return self::$f($method, $uri, $params, $this->interceptor);'; $gen->addMethod('public', 'dispatch', array('string $method', 'string $uri'), $func); if ($this->interceptor !== null) { $func = array('$this->interceptor = ' . var_export($this->interceptor, true) . ';'); $gen->addMethod('public', '__construct', array(), $func); } $gen->addMethod('public', 'getInterceptor', array(), array('return $this->interceptor;')); return $gen; }
private static function generateActionTest($config, $pathAction) { $module = ucfirst($config->module); if (self::isReserved($module, $config)) { $module .= '_'; } $controller = ucfirst($config->controller); if (self::isReserved($controller, $config)) { $controller .= '_'; } $action = ucfirst($config->action); $className = $module . '\\' . $controller . '\\' . $action . 'Test'; $class = new UserClass($className); $class->extendClass('AbstractModuleTest'); $class->useClass('integration\\modules\\AbstractModuleTest'); $class->useClass('TestLib\\Mink'); $class->addStaticVar('canBeOverWritten', true); $doc1 = new CommentBlock(); $doc1->appendLine('Sets up the fixture, for example, opens a network connection.'); $doc1->appendLine('This method is called before a test is executed.'); //$setup = $class->addMethod('protected', 'setUp'); $setup = new ClassMethod('setUp'); $setup->setScope('protected'); //$setup->setCommentBlock($doc1); $block = $setup->getBlock(); $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'module'), $config->module)); $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'controller'), $config->controller)); $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'action'), $config->action)); $block->appendRenderable(new Statement(new StaticMethodCall('parent', 'setUp'))); $class->addMethodObject($setup); $doc2 = new CommentBlock(); $doc2->appendLine('Tears down the fixture, for example, closes a network connection.'); $doc2->appendLine('This method is called after a test is executed.'); $teardown = new ClassMethod('tearDown'); $teardown->setScope('protected'); //$teardown->setCommentBlock($doc2); $block = $teardown->getBlock(); $block->appendLine(new Statement(new StaticMethodCall('parent', 'tearDown'))); $class->addMethodObject($teardown); ////////// $doc3 = new CommentBlock(); $doc3->appendLine('@covers ' . $config->module . '/' . $config->controller . '/' . $config->action); $mainTest = new ClassMethod('test' . $action); $mainTest->setScope('public'); //$mainTest->setCommentBlock($doc3); $class->addMethodObject($mainTest); $block = $mainTest->getBlock(); if ($config->inMenu === true && !self::isDanger($config)) { $res = self::openInMenuBlock($block, $class, $config); if (!$res) { fwrite(STDOUT, "\t" . 'cant open: ' . $config->module . ':' . $config->controller . ':' . $config->action . "\n"); return; } } else { //return; self::simpleBlock($block); } $res = file_put_contents($pathAction, $code = "<?php\n" . $class->render()); if (!$res) { throw new ErrorException('cant write'); } }