Ejemplo n.º 1
0
    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 "Tests ok, submit away :) \n";
}
exit($ret);
//return the combined/single return value of tests
/**
 *  Check if the given options array contains any of the $opts specified
 *
 * @param array $options the array from getopt()
 * @param string $opts,... options to check for
 * @return bool If one of the specified options is set
 */
Ejemplo n.º 2
0
$classLoader = new LibreNMS\ClassLoader();
$classLoader->register();
$short_opts = 'lsupch';
$long_opts = array('lint', 'style', 'unit', 'passthru', 'snmpsim', '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      --snmpsim  Use snmpsim on 127.0.0.1:11161 for unit tests\n  -c, --commands Print commands only, no checks\n  -h, --help     Show this help text.\n";
    exit;
}
// set up some variables
$passthru = check_opt($options, 'p', 'passthru');
$command_only = check_opt($options, 'c', 'commands');
$snmpsim = check_opt($options, 'snmpsim');
$ret = 0;
$completed_tests = array('lint' => false, 'style' => false, 'unit' => false);
$all = !check_opt($options, 'l', 'lint', 's', 'style', 'u', 'unit');
if ($all) {
    // no test specified, run all tests in this order
    $options += array('u' => false, 's' => false, 'l' => false);
}
// run tests in the order they were specified
foreach (array_keys($options) as $opt) {
    if ($opt == 'l' || $opt == 'lint') {
        $ret += run_check('lint', $passthru, $command_only);
    } elseif ($opt == 's' || $opt == 'style') {
        $ret += run_check('style', $passthru, $command_only);
    } elseif ($opt == 'u' || $opt == 'unit') {
        $ret += run_check('unit', $passthru, $command_only, $snmpsim);
    }
}
// output Tests ok, if no arguments passed
Ejemplo n.º 3
0
}
// 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 "Tests ok, submit away :) \n";
}
exit($ret);
//return the combined/single return value of tests
/**
 * Runs php -l and tests for any syntax errors
 *
 * @param bool $passthru display the output as comes in
 * @param bool $command_only only display the intended command, no checks
 * @return int the return value from running php -l (0 = success)
 */