From 30675ca20f56b69d43ddc658e2032fddd9673a9e Mon Sep 17 00:00:00 2001 From: Jared Hancock <gravydish@gmail.com> Date: Mon, 9 Apr 2012 09:11:34 -0500 Subject: [PATCH] Add PHP syntax tests And make globbing platform independent, which also fixes an issue where not all PHP files were scanned by the phplint tool for uninitialized variables --- setup/test/lint.php | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/setup/test/lint.php b/setup/test/lint.php index 01c97df9f..c25f7acec 100644 --- a/setup/test/lint.php +++ b/setup/test/lint.php @@ -14,16 +14,53 @@ function get_osticket_root_path() { $root = get_osticket_root_path(); +# Check PHP syntax across all php files +function glob_recursive($pattern, $flags = 0) { + $files = glob($pattern, $flags); + foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) + as $dir) { + $files = array_merge($files, + glob_recursive($dir.'/'.basename($pattern), $flags)); + } + return $files; +} +echo "PHP Syntax Errors: "; +ob_start(); +$scripts=glob_recursive("$root/*/*.php"); +$exit=0; +$syntax_errors=""; +foreach ($scripts as $s) { + system("php -l $s", $exit); + $line = ob_get_contents(); + ob_clean(); + if ($exit !== 0) + $syntax_errors .= $line; +} +ob_end_clean(); + +if (strlen($syntax_errors)) { + $syntax_errors=str_replace("$root/", '', $syntax_errors); + echo "FAIL\n"; + echo "-------------------------------------------------------\n"; + echo "$syntax_errors"; + exit(); +} else { + echo "\n"; +} + # Run phplint across all php files +echo "Access to unitialized variables: "; ob_start(); # XXX: This won't run well on Windoze -system("$root/setup/test/lib/phplint.tcl $root/**/*.php 2>&1"); +system("$root/setup/test/lib/phplint.tcl ".implode(" ", $scripts)); $lint_errors = ob_get_clean(); -$lint_errors=str_replace("$root/", '', $lint_errors); if (strlen($lint_errors)) { - echo "FAIL: Access to unitialized variables\n"; + $lint_errors=str_replace("$root/", '', $lint_errors); + echo "FAIL\n"; echo "-------------------------------------------------------\n"; echo "$lint_errors"; +} else { + echo "\n"; } ?> -- GitLab