diff --git a/gulliver/system/class.error.php b/gulliver/system/class.error.php index 819be53d1..b2301dbf8 100755 --- a/gulliver/system/class.error.php +++ b/gulliver/system/class.error.php @@ -101,10 +101,11 @@ class G_Error extends PEAR_Error G_ERROR_WARNING_MESSAGE => 'Warning message', ); } - +/* if (DB::isError($code)) { $code = $code->getCode(); } + */ return isset($gErrorMessages[$code]) ? $gErrorMessages[$code] : (isset($errorMessages) ? $errorMessages['G_ERROR'] : ''); } } diff --git a/gulliver/system/class.helper.php b/gulliver/system/class.helper.php index 71e00da48..8bf2fca9f 100755 --- a/gulliver/system/class.helper.php +++ b/gulliver/system/class.helper.php @@ -92,7 +92,8 @@ class Helper{ $this->flush(); } } - +/* function minify($buffer) { return G::removeComments($buffer); -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/tests/generateTestUnit.php b/tests/generateTestUnit.php new file mode 100644 index 000000000..c0f54e3fb --- /dev/null +++ b/tests/generateTestUnit.php @@ -0,0 +1,223 @@ +#!/usr/bin/php + $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 ); + print "--> $className\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, " $functionName ( "; + + //search for first ( open parenthesis + $openParenthesis = false; + $closeParenthesis = false; + while ( ! $openParenthesis ) { + if (! is_array($tokens[$k]) && $tokens[$k] == '(' ) + $openParenthesis = true; + $k++; + } + while ( ! $closeParenthesis ) { + if (is_array($tokens[$k]) && $tokens[$k][0] == T_VARIABLE ) { + //print " " . $tokens[$k][1]; + } + if (! is_array($tokens[$k]) && $tokens[$k] == ')' ) { + $closeParenthesis = true; + //print " \n"; + } + $k++; + } + + + fprintf ( $fp, " /**\n" ); + fprintf ( $fp, " * @covers %s::%s\n", $className, $functionName ); + fprintf ( $fp, " * @todo Implement test%s().\n", $functionName ); + fprintf ( $fp, " */\n" ); + fprintf ( $fp, " public function test%s() \n", $functionName ); + fprintf ( $fp, " { \n" ); + fprintf ( $fp, " if (class_exists('%s')) {\n ", $className ); + fprintf ( $fp, " \$methods = get_class_methods( '%s');\n", $className ); + fprintf ( $fp, " \$this->assertTrue( in_array( '%s', \$methods ), 'seems like this function is outside this class' ); \n", $functionName ); +// fprintf ( $fp, " \$x = new %s(); \n", $className ); +// fprintf ( $fp, " \$this->assertTrue( is_a(\$x, '%s') ); \n", $className ); + fprintf ( $fp, " } \n" ); + + + fprintf ( $fp, " } \n\n" ); + //fprintf ( $fp, "[$functionName]\n class = $className\n path = $path\n" ); + //fprintf ( $fp, "\n" ); + } + + function parsePublic ( $path, $className, $functionName, $comments ) { + global $fp; + $comm = explode ("\n", $comments); + $gearman = false; + $rest = false; + $background = false; + foreach ( $comm as $k => $line ) { + $line = trim(str_replace('*','',$line)); + if (substr($line,0, 13) == '@background =') $background = strtolower(trim(substr( $line,14 ))); + if (substr($line,0, 10) == '@gearman =') $gearman = strtolower(trim(substr( $line,11 ))); + if (substr($line,0, 7) == '@rest =') $rest = strtolower(trim(substr( $line,7 ))); + } + fprintf ( $fp, "[$functionName]\n class = $className\n path = $path\n" ); + fprintf ( $fp, " gearman = " . ($gearman == 'true' ? 'true' : 'false') . "\n" ); + fprintf ( $fp, " background = " . ($background== 'true' ? 'true' : 'false') . "\n" ); + fprintf ( $fp, " rest = " . ($rest == 'true' ? 'true' : 'false') . "\n" ); + fprintf ( $fp, "\n" ); + } + + + + function nextToken( $type, $k ) { + global $tokens; + do { + $k++; + if ($tokens[$k][0] == T_FUNCTION || $tokens[$k][0] == T_CLASS ) { + return ''; + } + } while ( $k < count($tokens) && $tokens[$k][0] != $type ); + if ( isset($tokens[$k]) ) { + return $tokens[$k][1]; + } + else { + return ''; + } + } + + function previousToken( $type, $k ) { + global $tokens; + do { + $k--; + if ($tokens[$k][0] == T_FUNCTION || $tokens[$k][0] == T_CLASS ) { + return ''; + } + } while ( $k > 0 && $tokens[$k][0] != $type ); + + if ( isset($tokens[$k]) ) { + return $tokens[$k][1]; + } + else { + return ''; + } + } + +