$short_opts = 'lsuph'; $long_opts = array('lint', 'style', 'unit', 'passthru', 'help'); $parameters = array('p', 'passthru'); $options = getopt($short_opts, $long_opts); if (check_opt($options, 'h', 'help')) { echo "LibreNMS Code Tests Script\nRunning {$filename} without options runs all checks.\n -l, --lint Run php lint checks to test for valid syntax.\n -s, --style Run phpcs check to check for PSR-2 compliance.\n -u, --unit Run phpunit tests.\n -h, --help Show this help text.\n"; exit; } // set up some variables $passthru = check_opt($options, 'p', 'passthru'); $commands = array_diff($options, $parameters); $all = empty($commands); $ret = 0; // run tests if ($all || check_opt($commands, 'l', 'lint')) { $ret += check_lint(); } if ($all || check_opt($commands, 's', 'style')) { $ret += check_style($passthru); } if ($all || check_opt($commands, 'u', 'unit')) { $ret += check_unit($passthru); } // output Tests ok, if no arguments passed if ($all && $ret === 0) { echo "[32mTests ok, submit away :)[0m \n"; } exit($ret); //return the combined/single return value of tests /** * Check if the given options array contains any of the $opts specified
$long_opts = array('lint', 'style', 'unit', 'passthru', 'commands', 'help'); $options = getopt($short_opts, $long_opts); if (check_opt($options, 'h', 'help')) { echo "LibreNMS Code Tests Script\nRunning {$filename} without options runs all checks.\n -l, --lint Run php lint checks to test for valid syntax.\n -s, --style Run phpcs check to check for PSR-2 compliance.\n -u, --unit Run phpunit tests.\n -p, --passthru Display output from checks as it comes\n -c, --commands Print commands only, no checks\n -h, --help Show this help text.\n"; exit; } // set up some variables $parameters = array('p' => false, 'c' => false, 'passthru' => false, 'commands' => false); $passthru = check_opt($options, 'p', 'passthru'); $command_only = check_opt($options, 'c', 'commands'); $commands = array_diff_assoc($options, $parameters); $all = empty($commands); $ret = 0; // run tests if (($all || check_opt($commands, 'l', 'lint')) && !getenv('SKIP_LINT_CHECK')) { $ret += check_lint($passthru, $command_only); } if (($all || check_opt($commands, 's', 'style')) && !getenv('SKIP_STYLE_CHECK')) { $ret += check_style($passthru, $command_only); } if (($all || check_opt($commands, 'u', 'unit')) && !getenv('SKIP_UNIT_CHECK')) { $ret += check_unit($passthru, $command_only); } // output Tests ok, if no arguments passed if ($all && $ret === 0) { echo "[32mTests ok, submit away :)[0m \n"; } exit($ret); //return the combined/single return value of tests /** * Runs php -l and tests for any syntax errors