function createFile($filePath, $className) { $content = file_get_contents($filePath); $pattern = '/(\\{[\\s\\S]*\\/\\*\\*[\\s\\S]*?public function action.*\\(\\))/'; preg_match($pattern, $content, $matches); if (empty($matches)) { return array(); } $pattern2 = '/(\\/\\*\\*[\\s\\S]*?public function action.*\\(\\))/'; preg_match_all($pattern2, $matches[0], $matches2); $ret = array(); if (count($matches2[0])) { foreach ($matches2[0] as $val) { preg_match('/.*public function action(.*)/', $val, $matches3); $ret[parseFunction($matches3[1])] = trim(parseDescription($val, $matches3[1])); } } $ret = array('class' => parseClass($className), 'func' => $ret); return $ret; }
function parseExpression($ast) { $type = ast_node_type($ast); switch ($type) { case NodeType::LITERAL: $ret = parseLiteral($ast); break; case NodeType::ATTRIBUTE: $ret = parseAttributeExpr($ast); break; case NodeType::FUNC: $ret = parseFunction($ast); break; case Nodetype::METHOD: $ret = parseMethod($ast); break; case NodeType::OPERATOR: $ret = parseOperator($ast); break; case NodeType::CASE_NODE: $ret = parseCase($ast); break; case NodeType::MATCH: $ret = parseMatch($ast); break; case NodeType::NUL: $ret = parseNull($ast); break; default: $source = ast_node_source($ast); grokit_logic_error('Attempted to evaluate node of type ' . $type . ' as an expression ' . $source); } return $ret; }
function parsingFile($folder, $entry) { global $tokens; global $fp; global $outputDir; $baseDir = ROOT_PATH; $file = $baseDir . $folder . '/' . $entry; $content = file_get_contents($file); //get all tokens $tokens = token_get_all($content); //remove spaces $temp = array(); foreach ($tokens as $k => $token) { if (is_array($token) && $token[0] != T_WHITESPACE) { $temp[] = $tokens[$k]; } if (!is_array($token)) { $temp[] = $token; } } $tokens = $temp; $className = ''; $comments = ''; $path = '/' . str_replace(ROOT_PATH, '', $file); $atLeastOneClass = false; foreach ($tokens as $k => $token) { if (is_array($token)) { //looking for classes if ($token[0] == T_CLASS) { if ($atLeastOneClass) { fprintf($fp, " } \n"); } $atLeastOneClass = true; $className = nextToken(T_STRING, $k); if (strpos(strtolower($entry), strtolower($className))) { print "--> {$className}\n"; } else { print "--> {$className} ({$entry})\n"; } $classFile = $folder . '/' . $entry; if (!is_dir($outputDir . $folder)) { mkdir($outputDir . $folder, 0777, true); } $fp = fopen($outputDir . $folder . '/class' . $className . 'Test.php', 'w'); fprintf($fp, "<?php\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/thirdparty/smarty/libs/Smarty.class.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/system/class.xmlform.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/system/class.xmlDocument.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/system/class.form.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/system/class.dbconnection.php';\n"); // setup propel definitions and logging fprintf($fp, "require_once PATH_TRUNK . 'gulliver/thirdparty/propel/Propel.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/thirdparty/creole/Creole.php';\n"); fprintf($fp, "require_once PATH_TRUNK . 'gulliver/thirdparty/pear/PEAR.php';\n"); fprintf($fp, "require_once PATH_TRUNK . '%s/%s';\n\n", $folder, $entry); require_once ROOT_PATH . "{$folder}/{$entry}"; fprintf($fp, "/**\n"); fprintf($fp, " * Generated by ProcessMaker Test Unit Generator on %s at %s.\n", date('Y-m-d'), date('H:i:s')); fprintf($fp, "*/\n\n"); fprintf($fp, "class class%sTest extends PHPUnit_Framework_TestCase\n", $className); fprintf($fp, "{\n"); fprintf($fp, " /**\n"); fprintf($fp, " * @var %s\n", $className); fprintf($fp, " */\n"); fprintf($fp, " protected \$object;\n\n"); fprintf($fp, " /**\n"); fprintf($fp, " * Sets up the fixture, for example, opens a network connection.\n"); fprintf($fp, " * This method is called before a test is executed.\n"); fprintf($fp, " */\n"); fprintf($fp, " protected function setUp()\n"); fprintf($fp, " {\n"); fprintf($fp, " \$this->object = new %s();\n", $className); fprintf($fp, " }\n\n"); fprintf($fp, " /**\n"); fprintf($fp, " * Tears down the fixture, for example, closes a network connection.\n"); fprintf($fp, " * This method is called after a test is executed.\n"); fprintf($fp, " */\n"); fprintf($fp, " protected function tearDown()\n"); fprintf($fp, " {\n"); fprintf($fp, " }\n"); fprintf($fp, "\n"); $methods = get_class_methods($className); fprintf($fp, " /**\n"); fprintf($fp, " * This is the default method to test, if the class still having \n"); fprintf($fp, " * the same number of methods.\n"); fprintf($fp, " */\n"); fprintf($fp, " public function testNumberOfMethodsInThisClass()\n"); fprintf($fp, " {\n"); fprintf($fp, " \$methods = get_class_methods('%s');", $className); fprintf($fp, " \$this->assertTrue( count(\$methods) == %s);\n", count($methods)); fprintf($fp, " }\n"); fprintf($fp, "\n"); } if ($token[0] == T_FUNCTION) { $functionName = nextToken(T_STRING, $k); $public = previousToken(T_PUBLIC, $k); $comments = previousToken(T_DOC_COMMENT, $k); parseFunction($k, $path, $className, $functionName, $comments); //if ( strtolower($public) == 'public' ) parsePublic ( $path, $className, $functionName, $comments ); } } } if ($atLeastOneClass) { fprintf($fp, " } \n"); } }