Ejemplo n.º 1
0
Archivo: api.php Proyecto: prggmr/xpspl
/**
 * Registers a standard output mechanism for test results.
 *
 * @return  void
 */
function generate_output()
{
    // enable the event history
    xp_set_signal_history(true);
    // Startup
    xp_on_start(function () {
        if (XPSPL_DEBUG) {
            logger(XPSPL_LOG)->info('Unittest begin');
        }
        define('UNITTEST_START_TIME', milliseconds());
    });
    // Shutdown
    xp_on_shutdown(function () {
        if (XPSPL_DEBUG) {
            logger(XPSPL_LOG)->info('Unittest end');
        }
        define('UNITTEST_END_TIME', milliseconds());
        $tests = 0;
        $pass = 0;
        $fail = 0;
        $skip = 0;
        $output = Output::instance();
        $tests_run = [];
        foreach (xp_signal_history() as $_node) {
            if ($_node[0] instanceof SIG_Test) {
                // suites
                $tests++;
                $tests_run[] = $_node[0];
                $failures = [];
                // Get passedXPSPL
                foreach ($_node[0]->get_assertion_results() as $_assertion) {
                    if ($_assertion[0] === true) {
                        $pass++;
                    } elseif ($_assertion[0] === null) {
                        $skip++;
                    } else {
                        $fail++;
                        $failures[] = $_assertion;
                    }
                }
                if (count($failures) != 0) {
                    $output->send_linebreak(Output::ERROR);
                    foreach ($failures as $_failure) {
                        $output->send("FAILURE", Output::ERROR);
                        $output->send("ASSERTION : " . $_failure[1], Output::ERROR, true);
                        $output->send("MESSAGE : " . $_failure[0], Output::ERROR, true);
                        $output->send(sprintf('ARGUMENTS : %s', $output->variable($_failure[2])), Output::ERROR, true);
                        $trace = $_failure[3][1];
                        $output->send("FILE : " . $trace["file"], Output::ERROR, true);
                        $output->send("LINE : " . $trace["line"], Output::ERROR);
                        $output->send_linebreak(Output::ERROR);
                    }
                }
            }
        }
        $size = function ($size) {
            /**
             * This was authored by another individual by whom i don't know
             */
            $filesizename = array(" Bytes", "KB", "MB", "GB", "TB", "PB", " EB", "ZB", "YB");
            return $size ? round($size / pow(1024, $i = floor(log($size, 1024))), 2) . $filesizename[$i] : '0 Bytes';
        };
        $output->send_linebreak();
        $output->send(sprintf("Ran %s tests in %sms and used %s memory", $tests, UNITTEST_END_TIME - UNITTEST_START_TIME, $size(memory_get_peak_usage())), Output::SYSTEM, true);
        $output->send(sprintf("%s Assertions: %s Passed, %s Failed, %s Skipped", $pass + $fail + $skip, $pass, $fail, $skip), Output::SYSTEM, true);
    });
}
Ejemplo n.º 2
0
    $log->add_handler(new \logger\Handler($formatter, STDOUT));
}
/**
 * XPSPL
 *
 * XPSPL is a globally available singleton used for communication access via the
 * API.
 */
final class XPSPL extends \XPSPL\Processor
{
    use XPSPL\Singleton;
}
/**
 * Start the processor VROOOOOOM!
 */
xp_set_signal_history(XPSPL_SIGNAL_HISTORY);
if (!function_exists('rfind')) {
    function rfind($src = '', $file_type = '')
    {
        // If source is not a directory stop processing
        if (!is_dir($src)) {
            return false;
        }
        $matches = [];
        $i = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($template_directory_path)), '/^.+\\.' . $file_type . '$/i', RecursiveRegexIterator::GET_MATCH);
        foreach ($i as $f) {
            array_map($f, function ($file) use($matches) {
                $matches[] = $file;
            });
        }
        return $matches;
Ejemplo n.º 3
0
                        }
                        if ($_v >= 1) {
                            $total++;
                        }
                    }
                    $avg[$file] = round($total / $lines * 100, 2);
                } else {
                    $avg[$file] = 0;
                }
            }, $_file);
        }
        $total = 0.0;
        foreach ($avg as $_c) {
            $total += $_c;
        }
        \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true);
        \unittest\Output::send(sprintf('Total Test Coverage : %s%%', round($total / (count($avg) * 100) * 100, 2)), \unittest\Output::DEBUG, true);
        \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true);
        foreach ($avg as $_k => $_c) {
            \unittest\Output::send(sprintf('File : %s', $_k), \unittest\Output::DEBUG, true);
            \unittest\Output::send(sprintf('Coverage : %s%%', $_c), \unittest\Output::DEBUG, true);
            \unittest\Output::send('--------------------', \unittest\Output::DEBUG, true);
        }
    });
}
xp_import("unittest");
// load the standard unittest output
unittest\generate_output();
// make sure we save the event history
xp_set_signal_history(true);