/** * Handle failinfo message */ function paintSignal($type, $message) { parent::paintSignal($type, $message); if ($type = 'failinfo') { $this->_failinfo = $message; } }
public function run() { $test = new GroupTest("Piwik - running '{$this->testGroupType}' tests..."); $intro = ''; if (!$this->databaseRequired) { $intro .= $this->getTestDatabaseInfoMessage(); } $intro .= self::$testsHelpLinks . "<hr/>"; $intro .= $this->introAppend; $toInclude = array(); foreach ($this->dirsToGlob as $dir) { $toInclude = array_merge($toInclude, Piwik::globr(PIWIK_INCLUDE_PATH . $dir, '*.test.php')); } // if present, make sure Database.test.php is first $idx = array_search(PIWIK_INCLUDE_PATH . '/tests/core/Database.test.php', $toInclude); if ($idx !== FALSE) { unset($toInclude[$idx]); array_unshift($toInclude, PIWIK_INCLUDE_PATH . '/tests/core/Database.test.php'); } foreach ($toInclude as $file) { $test->addFile($file); } $result = $test->run(new HtmlTimerReporter($intro)); if (SimpleReporter::inCli()) { exit($result ? 0 : 1); } }
function paintError($message) { parent::paintError($message); $this->_response->addContent("Error !!\n"); $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $this->_response->addContent("\tin " . implode("\n\tin ", array_reverse($breadcrumb))); $this->_response->addContent("\n\t " . $message . "\n"); }
/** * Exit handler to run all recent test cases and exit system if in CLI */ function simpletest_autorun() { if (tests_have_run()) { return; } $result = run_local_tests(); if (SimpleReporter::inCli()) { exit($result ? 0 : 1); } }
function paintSkip($message) { parent::paintSkip($message); $str = "<span class=\"pass\">Skipped</span>: "; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $str .= implode(" -> ", $breadcrumb); $str .= " -> " . $this->_htmlEntities($message) . "<br />\n"; $this->_response->body->append('MAIN', $str); }
function paintError($message) { parent::paintError($message); $str = "<span class=\"fail\">Exception</span>: "; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $str .= implode(" -> ", $breadcrumb); $str .= " -> <strong>" . $this->_htmlEntities($message) . "</strong><br />\n"; $this->_response->body->append('MAIN', $str); }
/** * Exit handler to run all recent test cases and exit system if in CLI */ function simpletest_autorun() { chdir($GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH']); if (tests_have_run()) { return; } $result = run_local_tests(); if (SimpleReporter::inCli()) { exit($result ? 0 : 1); } }
function paintFail($message) { SimpleReporter::paintFail($message); if ($this->getFailCount() <= 10) { print $this->test_name . ": {$message}\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); print "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); print "\n"; } }
/** * Assembles the appopriate reporter for the environment. */ function DefaultReporter() { if (SimpleReporter::inCli()) { global $argv; $parser = new SimpleCommandLineParser($argv); $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter'); $reporter =& new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest()); } else { $reporter =& new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']); } $this->SimpleReporterDecorator($reporter); }
function paintFail($message) { parent::paintFail($message); $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $test = implode("->", $breadcrumb); $result["time"] = time(); $result["status"] = "Failed"; $result["test"] = $test; $result["message"] = $message; $this->results[] = $result; }
/** * Invokes run() on all of the held test cases, instantiating * them if necessary. * @param SimpleReporter $reporter Current test reporter. * @param int $port Port to report test results on * @access public */ function run(&$reporter, $port) { $count = count($this->_test_cases); for ($i = 0; $i < $count; $i++) { if (is_string($this->_test_cases[$i])) { $class = $this->_test_cases[$i]; $test =& new $class(); ob_start(); $reporter->paintGroupStart($this->getLabel(), $this->getSize()); $reporter->paintCaseStart($test->getLabel()); $start = ob_get_contents(); ob_end_clean(); ob_start(); $reporter->paintCaseEnd($test->getLabel()); $reporter->paintGroupEnd($this->getLabel()); $end = ob_get_contents(); ob_end_clean(); //the guts from SimpleTestCase::run($reporter) where $test->_runner = new EclipseRunner($test, $reporter, $start, $end, $port); $test->_runner->run(); $output = $start; if ($i + 1 == $count) { $output .= "<done/>"; } $output .= $end; $sock = new SimpleSocket("127.0.0.1", $port, 5); $sock->write($output); $sock->close(); echo $sock->getError(); } else { $this->_test_cases[$i]->run($reporter, $port); } } return $reporter->getStatus(); }
/** * Exit handler to run all recent test cases if no test has * so far been run. Uses the DefaultReporter which can have * it's output controlled with SimpleTest::prefer(). */ function simpletest_autorun() { if (tests_have_run()) { return; } $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file()); $loader = new SimpleFileLoader(); $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates)); $result = $suite->run(new DefaultReporter()); if (SimpleReporter::inCli()) { exit($result ? 0 : 1); } }
/** * Exit handler to run all recent test cases if no test has * so far been run. Uses the DefaultReporter which can have * it's output controlled with SimpleTest::prefer(). */ function simpletest_autorun() { try { if (tests_have_run()) { return; } $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file()); $loader = new SimpleFileLoader(); $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates)); $result = $suite->run(new DefaultReporter()); } catch (Exception $e) { // This is here, because under normal circumstances shutdown // functions don't have a stack frame, leading to obscure errors. echo $e->__toString(); $result = false; } if (SimpleReporter::inCli()) { exit($result ? 0 : 1); } }
/** * acceptor for end of test group. * final group pops the collected treemap nodes and assigns it to the internal graph property. */ public function paintGroupEnd($message) { $node = $this->_stack->pop(); $current = $this->_stack->peek(); if ($current) { if ($node->isFailed()) { $current->fail(); } $current->putChild($node); } else { $this->_graph = $node; } parent::paintGroupEnd($message); }
function TestDoxReporter($test_case_pattern = '/^TestOf(.*)$/') { parent::__construct(); $this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern; }
/** * Assembles the appropriate reporter for the environment. */ function __construct() { if (SimpleReporter::inCli()) { $parser = new SimpleCommandLineParser($_SERVER['argv']); $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter'); if ($parser->help()) { // I'm not sure if we should do the echo'ing here -- ezyang echo $parser->getHelpText(); exit(1); } $reporter = new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest()); if ($parser->noSkips()) { $reporter = new NoSkipsReporter($reporter); } } else { $reporter = new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']); if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') { $reporter = new NoSkipsReporter($reporter); } } parent::__construct($reporter); }
/** * Paints the end of a test method being run. This is used * to pause the collection of code coverage if its being used. * * @param string $method The name of the method being run. * @return void */ function paintMethodEnd($method) { parent::paintMethodEnd($method); if (!empty($this->params['codeCoverage'])) { CodeCoverageManager::stop(); } }
/** * @param string $message */ public function paintSkip($message) { parent::paintSkip($message); if (preg_match('!^(.*) at \\[(.+) line (\\d+)]$!', $message, $matches)) { $this->writeError($matches[1], null, $matches[2], $matches[3], $matches[1]); } else { $this->writeError($message); } }
{ function UnitTests() { $this->GroupTest("Unit tests"); $this->addTestFile("errors_test.php"); $this->addTestFile("options_test.php"); $this->addTestFile("dumper_test.php"); $this->addTestFile("expectation_test.php"); $this->addTestFile("simple_mock_test.php"); $this->addTestFile("adapter_test.php"); $this->addTestFile("socket_test.php"); $this->addTestFile("query_string_test.php"); $this->addTestFile("http_test.php"); $this->addTestFile("user_agent_test.php"); $this->addTestFile("browser_test.php"); $this->addTestFile("parser_test.php"); $this->addTestFile("tag_test.php"); $this->addTestFile("page_test.php"); $this->addTestFile("frames_test.php"); $this->addTestFile("shell_tester_test.php"); $this->addTestFile("xml_test.php"); } } if (!defined("TEST_RUNNING")) { define("TEST_RUNNING", true); $test =& new UnitTests(); if (SimpleReporter::inCli()) { exit($test->run(new TextReporter()) ? 0 : 1); } $test->run(new HtmlReporter()); }
function paintFail($message) { parent::paintFail($message); $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $bc = implode(">", $breadcrumb); $this->PrintMessage("Fail: {$bc} -> {$message}", true, 'red'); }
/** * Sends a single error to the reporter. * @param SimpleReporter $reporter Current test reporter. * @access public */ function run(&$reporter) { $reporter->paintGroupStart($this->getLabel(), $this->getSize()); $reporter->paintFail('Bad TestSuite [' . $this->getLabel() . '] with error [' . $this->_error . ']'); $reporter->paintGroupEnd($this->getLabel()); return $reporter->getStatus(); }
function paintFail($message) { // We need to bypass parent::paintFail to increment failures without printing its message. SimpleReporter::paintFail($message); print "<blockquote><strong><span class=\"fail\">Fail</span>: {$message}</strong></blockquote>\n"; }
/** * Signals the appropriate end event on the * listener. * @param SimpleReporter $listener Target for events. * @access public */ function paintEnd(&$listener) { $listener->paintGroupEnd($this->getName()); }
/** * Paints a PHP error or exception. * @param string $message Message is ignored. * @access public **/ function paintError($message) { parent::paintError($message); $this->test_stack[] = array('data' => array($this->_htmlEntities($message), 'EXCEPTION'), 'class' => 'simpletest-fail'); //$this->writeContent($this->_htmlEntities($message). ' EXCEPTION', NULL, 'simpletest-fail'); }
/** * Prints the message for skipping tests. * * @param string $message Text of skip condition. */ public function paintSkip($message) { parent::paintSkip($message); print "Skip: {$message}\n"; }
/** * Prints the message for skipping tests. * @param string $message Text of skip condition. * @access public */ function paintSkip($message) { parent::paintSkip($message); echo "<li class='skipped'>\n"; echo "<span>Skipped</span> "; echo $this->_htmlEntities($message); echo "</li>\n"; }
/** * Paints a PHP error or exception. * @param string $message Message is ignored. * @access public * @abstract */ function paintException($message) { parent::paintException($message); print "Exception " . $this->getExceptionCount() . "!\n$message\n"; }
function paintFail($message) { $this->addTest(false); // echo 'fail: ' . $message . "\n"; parent::paintFail($message); }
public function __construct($test_case_pattern = '/^TestOf(.*)$/') { parent::__construct(); $this->_test_case_pattern = empty($test_case_pattern) ? '/^(.*)$/' : $test_case_pattern; }
/** * Run a single test case with the given name, using the provided output format. * @param string $testName * @param string $format (xml, text or html) * @return int */ public function runTestCase($testName, $format = Sweety_Runner::REPORT_TEXT) { foreach ($this->_testLocators as $locator) { if ($locator->includeTest($testName)) { break; } } $testClass = new ReflectionClass($testName); if ($testClass->getConstructor()) { //We don't want test output to be cached if (!SimpleReporter::inCli()) { header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); } switch ($format) { case Sweety_Runner::REPORT_HTML: $reporter = new HtmlReporter(); break; case Sweety_Runner::REPORT_XML: if (!SimpleReporter::inCli()) { header("Content-Type: text/xml"); //Sigh! SimpleTest (skip() issues). } $reporter = new XmlReporter(); break; case Sweety_Runner::REPORT_TEXT: default: $reporter = new TextReporter(); break; } $test = $testClass->newInstance(); return $test->run($reporter) ? 0 : 1; } return 1; }