/** * 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); }); }
<?php ini_set('memory_limit', '10G'); xp_set_signal_history(true); $sig = XP_SIG('foo'); $time = time(); // Emit a few foo objects for ($i = 0; $i < 10000000; $i++) { xp_emit($sig); } $end = time(); $emitted = 0; foreach (xp_signal_history() as $_node) { if ($_node[0]->compare($sig)) { $emitted++; } } echo 'Emitted ' . $emitted . ' signals in ' . ($end - $time) . ' seconds' . PHP_EOL; echo 'Rate of ' . $emitted / ($end - $time);