/** * Calls an assertion function. * * @param string $name Assertion function name * @param array $vars Array of variables to pass the process. * @param object $test \XPSPL\unittest\SIG_Test * * @return boolean|string|int True on success, False on failure| * String indicated failure message| * Integer on unknown assertion. */ public function call_assertion($name, $vars, SIG_Test $signal) { if (!isset($this->_storage[$name])) { return Output::instance()->unknown_assertion($signal, $name, $vars, $this); } if (!is_array($vars)) { $vars = [$vars]; } $func = $this->_storage[$name][0]->bindTo($signal); $test = call_user_func_array($func, $vars); if ($test === true) { return true; } if (null !== $this->_storage[$name][1]) { $output = Output::instance(); $e_vars = []; foreach ($vars as $_var) { $e_vars[] = $output->variable($_var); } $sprintf = array_merge([$this->_storage[$name][1]], $e_vars); return call_user_func_array('sprintf', $sprintf); } return false; }
/** * 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); }); }
/** * Processes the merge operation */ public function run() { Output::instance()->write( "Merge: {$this->commandObject->conversionType} '{$this->commandObject->title}'" ); $result = ''; $return = ''; // mark operation as running $this->status = self::STATUS_RUNNING; $this->startTime = time(); $this->update(); // @todo Use pcntl_exec instead, to avoid errors exec( "{$this->command} 2>&1 >/dev/null", $result, $return ); $status = ( $return !== 0 ) ? -1 : 0; $this->status = ( $status == 0 ) ? self::STATUS_DONE : self::STATUS_ERROR; $this->message = implode( "\n", $result ); $this->endTime = time(); $this->update(); Output::instance()->write( "Done" ); }
{ extract(Options::getOptions()); if ($embedAssets) { wp_enqueue_script('dynamic-images', plugins_url('dynamic-images/assets/dynamic-images.js', DI_ROOT), false, null, true); wp_enqueue_style('dynamic-images', plugins_url('dynamic-images/assets/dynamic-images.css', DI_ROOT), false, null, true); } } public function outputOptions() { printf('<script> this.dynamicImageOptions = %s; </script>', json_encode(Options::getOptions())); } public function filterContent($content) { return preg_replace('!<img(.*?)src=(.*?)>!', '<img$1data-dynamic-image=$2>', $content); } protected function __construct() { extract(Options::getOptions()); add_action('wp_enqueue_scripts', array($this, 'embedAssets')); add_action('wp_footer', array($this, 'outputOptions')); if ($filterContent) { add_filter('the_content', array($this, 'filterContent'), 100); add_filter('acf/load_value/type=wysiwyg', array($this, 'filterContent')); add_filter('acf/load_value/type=textarea', array($this, 'filterContent')); } } } Output::instance();