public function end() { $jobCount = $this->runner->getJobCount(); $results = $this->runner->getResults(); $count = array_sum($results); echo !$jobCount ? "No tests found\n" : "\n\n" . $this->buffer . "\n" . ($results[Runner::FAILED] ? Dumper::color('white/red') . 'FAILURES!' : Dumper::color('white/green') . 'OK') . " ({$jobCount} test" . ($jobCount > 1 ? 's' : '') . ", " . ($results[Runner::FAILED] ? $results[Runner::FAILED] . ' failure' . ($results[Runner::FAILED] > 1 ? 's' : '') . ', ' : '') . ($results[Runner::SKIPPED] ? $results[Runner::SKIPPED] . ' skipped, ' : '') . ($jobCount !== $count ? $jobCount - $count . ' not run, ' : '') . sprintf('%0.1f', $this->time + microtime(TRUE)) . ' seconds)' . Dumper::color() . "\n"; $this->buffer = NULL; }
public function result($testName, $result, $message) { $message = ' ' . str_replace("\n", "\n ", Tester\Dumper::removeColors(trim($message))); $outputs = array(Runner::PASSED => "-- OK: {$testName}", Runner::SKIPPED => "-- Skipped: {$testName}\n{$message}", Runner::FAILED => "-- FAILED: {$testName}\n{$message}"); fwrite($this->file, $outputs[$result] . "\n\n"); }
private function assessOutputMatch(Job $job, $content) { if (!Tester\Assert::isMatching($content, $job->getOutput())) { Dumper::saveOutput($job->getFile(), $job->getOutput(), '.actual'); Dumper::saveOutput($job->getFile(), $content, '.expected'); return array(Runner::FAILED, 'Failed: output should match ' . Dumper::toLine(rtrim($content))); } }
/** * Format exception for string (CMD) * @param BaseTest $test * @param Exception $e * @return string */ public function format(BaseTest $test, Exception $e) { $content = "TEST: [1;34m" . get_class($test) . "[0m" . PHP_EOL; $content .= \Tester\Dumper::dumpException($e); $content .= "-------------------------------------" . PHP_EOL; return $content; }
public function end() { $results = $this->runner->getResults(); $count = array_sum($results); $s = !$count ? "No tests found\n" : "\n\n" . $this->buffer . "\n" . ($results[Runner::FAILED] ? "[1;41;37mFAILURES!" : "[1;42;37mOK") . " ({$count} tests, " . ($results[Runner::FAILED] ? $results[Runner::FAILED] . ' failures, ' : '') . ($results[Runner::SKIPPED] ? $results[Runner::SKIPPED] . ' skipped, ' : '') . sprintf('%0.1f', $this->time + microtime(TRUE)) . " seconds)[0m\n"; echo Tester\Environment::$useColors ? $s : Tester\Dumper::removeColors($s); $this->buffer = NULL; }
/** @return void */ private function createPhpInterpreter() { $args = ''; if ($this->options['-c']) { $args .= ' -c ' . Helpers::escapeArg($this->options['-c']); } elseif (!$this->options['--info']) { echo "Note: No php.ini is used.\n"; } if (in_array($this->options['-o'], array('tap', 'junit'))) { $args .= ' -d html_errors=off'; } foreach ($this->options['-d'] as $item) { $args .= ' -d ' . Helpers::escapeArg($item); } // Is the executable Zend PHP or HHVM? $proc = @proc_open($this->options['-p'] . ' --version', array(array('pipe', 'r'), array('pipe', 'w'), array('pipe', 'w')), $pipes, NULL, NULL, array('bypass_shell' => TRUE)); if ($proc === FALSE) { throw new \Exception('Cannot run PHP interpreter ' . $this->options['-p'] . '. Use -p option.'); } $output = stream_get_contents($pipes[1]); $error = stream_get_contents($pipes[2]); if (proc_close($proc)) { throw new \Exception("Unable to run '{$this->options['-p']}': " . preg_replace('#[\\r\\n ]+#', ' ', $error)); } if (preg_match('#HipHop VM#', $output)) { $this->interpreter = new HhvmPhpInterpreter($this->options['-p'], $args); } else { $this->interpreter = new ZendPhpInterpreter($this->options['-p'], $args); } if ($this->interpreter->getErrorOutput()) { echo Dumper::color('red', 'PHP startup error: ' . $this->interpreter->getErrorOutput()) . "\n"; if ($this->interpreter->isCgi()) { echo "(note that PHP CLI generates better error messages)\n"; } } }
function d($v) { echo \Tester\Dumper::toPhp($v) . "\n"; }
public function result($testName, $result, $message) { $message = Tester\Dumper::removeColors(trim($message)); $outputs = array(Runner::PASSED => "ok {$testName}", Runner::SKIPPED => "ok {$testName} #skip {$message}", Runner::FAILED => "not ok {$testName}" . str_replace("\n", "\n# ", "\n" . $message)); echo $outputs[$result] . "\n"; }
/** @return void */ private function createPhpInterpreter() { $args = $this->options['-C'] ? [] : ['-n']; if ($this->options['-c']) { array_push($args, '-c', $this->options['-c']); } elseif (!$this->options['--info'] && !$this->options['-C']) { echo "Note: No php.ini is used.\n"; } if (in_array($this->options['-o'], ['tap', 'junit'])) { array_push($args, '-d', 'html_errors=off'); } foreach ($this->options['-d'] as $item) { array_push($args, '-d', $item); } $this->interpreter = new PhpInterpreter($this->options['-p'], $args); if ($error = $this->interpreter->getStartupError()) { echo Dumper::color('red', "PHP startup error: {$error}") . "\n"; } }
/** * @param string $destination fully qualified presenter name (module:module:presenter) * @param string $path * @param array $params provided to the presenter usually via URL * @param array $post provided to the presenter via POST * * @return \Nette\Application\Responses\RedirectResponse * @throws \Exception */ protected function checkRedirect($destination, $path = '/', $params = [], $post = []) { /** @var \Nette\Application\Responses\RedirectResponse $response */ $response = $this->check($destination, $params, $post); if (!$this->__testbench_exception) { Assert::same(200, $this->getReturnCode()); Assert::type('Nette\\Application\\Responses\\RedirectResponse', $response); Assert::same(302, $response->getCode()); if ($path) { if (!\Tester\Assert::isMatching("~^https?://test\\.bench{$path}(?(?=\\?).+)\$~", $response->getUrl())) { $path = Dumper::color('yellow') . Dumper::toLine($path) . Dumper::color('white'); $url = Dumper::color('yellow') . Dumper::toLine($response->getUrl()) . Dumper::color('white'); $originalUrl = new \Nette\Http\Url($response->getUrl()); Assert::fail(str_repeat(' ', strlen($originalUrl->getHostUrl()) - 13) . "path {$path} doesn't match\n{$url}\nafter redirect"); } } } return $response; }
function fileDump($var) { \Tester\Dumper::saveOutput('dump', $var); }