示例#1
0
/**
 * Runs phpunit
 *
 * @param bool $passthru display the output as comes in
 * @param bool $command_only only display the intended command, no checks
 * @param bool $snmpsim send snmp requests to snmpsim listening on 127.0.0.1:11161
 * @return int the return value from phpunit (0 = success)
 */
function check_unit($passthru = false, $command_only = false, $snmpsim = false)
{
    $phpunit_bin = check_exec('phpunit');
    if ($snmpsim) {
        $phpunit_cmd = "SNMPSIM=1 {$phpunit_bin} --colors=always";
        $snmpsim_cmd = "snmpsimd.py --data-dir=./tests/snmpsim --agent-udpv4-endpoint=127.0.0.1:11161 --logging-method=file:/tmp/snmpsimd.log";
    } else {
        $phpunit_cmd = "{$phpunit_bin} --colors=always";
        $snmpsim_cmd = '';
    }
    if ($command_only) {
        echo $phpunit_cmd . PHP_EOL;
        if ($snmpsim) {
            echo $snmpsim_cmd . PHP_EOL;
        }
        return 250;
    }
    $proc_snmpsimd = null;
    if ($snmpsim) {
        echo 'Starting snmpsimd...' . PHP_EOL;
        $proc_snmpsimd = new Proc($snmpsim_cmd);
    }
    echo 'Running unit tests... ';
    if ($passthru) {
        echo PHP_EOL;
        passthru($phpunit_cmd, $phpunit_ret);
    } else {
        exec($phpunit_cmd, $phpunit_output, $phpunit_ret);
        if ($phpunit_ret > 0) {
            echo "failed\n";
            echo implode(PHP_EOL, $phpunit_output) . PHP_EOL;
            echo 'snmpsimd: output at /tmp/snmpsimd.log';
        } else {
            echo "success\n";
        }
    }
    return $phpunit_ret;
}
示例#2
0
/**
 * Runs phpunit
 *
 * @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 phpunit (0 = success)
 */
function check_unit($passthru = false, $command_only = false)
{
    $phpunit_bin = check_exec('phpunit');
    $phpunit_cmd = "{$phpunit_bin} --colors=always";
    if ($command_only) {
        echo $phpunit_cmd . PHP_EOL;
        return 250;
    }
    echo 'Running unit tests... ';
    if ($passthru) {
        echo PHP_EOL;
        passthru($phpunit_cmd, $phpunit_ret);
    } else {
        exec($phpunit_cmd, $phpunit_output, $phpunit_ret);
        if ($phpunit_ret > 0) {
            echo "failed\n";
            print implode(PHP_EOL, $phpunit_output) . PHP_EOL;
        } else {
            echo "success\n";
        }
    }
    return $phpunit_ret;
}