/** * @return boolean */ public function accept() { $test = $this->getInnerIterator()->current(); if ($test instanceof PHPUnit_Framework_TestSuite) { return TRUE; } $tmp = PHPUnit_Util_Test::describe($test, FALSE); if ($tmp[0] != '') { $name = join('::', $tmp); } else { $name = $tmp[1]; } return preg_match($this->filter, $name); }
public function endTest(\PHPUnit_Framework_Test $test, $time) { parent::endTest($test, $time); if ($this->debug) { foreach ($this->timeColors as $threshold => $color) { if ($time >= $threshold) { $timeColor = $color; break; } } $this->write(' '); $this->writeWithColor($timeColor, '[' . number_format($time, 3) . 's]', false); $this->write(' '); $this->writeWithColor('fg-cyan', \PHPUnit_Util_Test::describe($test), true); } }
/** * @return bool */ public function accept() { $test = $this->getInnerIterator()->current(); if ($test instanceof PHPUnit_Framework_TestSuite) { return TRUE; } $tmp = PHPUnit_Util_Test::describe($test, FALSE); if ($tmp[0] != '') { $name = implode('::', $tmp); } else { $name = $tmp[1]; } $accepted = preg_match($this->filter, $name, $matches); if ($accepted && isset($this->filterMax)) { $set = end($matches); $accepted = $set >= $this->filterMin && $set <= $this->filterMax; } return $accepted; }
/** * {@inheritdoc} */ public function endTest(\PHPUnit_Framework_Test $test, $time) { $test_name = \PHPUnit_Util_Test::describe($test); if (!empty($test_name)) { $this->test_name_status = sprintf("%s (%s)\n", $test_name, sprintf("%s ms", round($time * 1000))); } if (!$this->lastTestFailed) { $this->writeProgress('.'); } if ($test instanceof \PHPUnit_Framework_TestCase) { $this->numAssertions += $test->getNumAssertions(); } elseif ($test instanceof \PHPUnit_Extensions_PhptTestCase) { $this->numAssertions++; } $this->lastTestFailed = false; if ($test instanceof \PHPUnit_Framework_TestCase) { if (method_exists($this, 'hasExpectationOnOutput') && !$test->hasExpectationOnOutput()) { $this->write($test->getActualOutput()); } } }
/** * Runs the tests and collects their result in a TestResult. * * @param PHPUnit_Framework_TestResult $result * @param mixed $filter * @param array $groups * @param array $excludeGroups * @return PHPUnit_Framework_TestResult * @throws InvalidArgumentException */ public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE, array $groups = array(), array $excludeGroups = array()) { if ($result === NULL) { $result = $this->createResult(); } try { $this->setUp(); } catch (PHPUnit_Framework_SkippedTestSuiteError $e) { $numTests = count($this); for ($i = 0; $i < $numTests; $i++) { $result->addFailure($this, $e, 0); } return $result; } $result->startTestSuite($this); if (empty($groups)) { $tests = $this->tests; } else { $tests = array(); foreach ($groups as $group) { if (isset($this->groups[$group])) { $tests = array_merge($tests, $this->groups[$group]); } } } foreach ($tests as $test) { if ($result->shouldStop()) { break; } if ($test instanceof PHPUnit_Framework_TestSuite) { $test->setBackupGlobals($this->backupGlobals); $test->setSharedFixture($this->sharedFixture); $test->run($result, $filter, $groups, $excludeGroups); } else { $runTest = TRUE; if ($filter !== FALSE) { $tmp = PHPUnit_Util_Test::describe($test, FALSE); if ($tmp[0] != '') { $name = join('::', $tmp); } else { $name = $tmp[1]; } if (preg_match($filter, $name) == 0) { $runTest = FALSE; } } if ($runTest && !empty($excludeGroups)) { foreach ($this->groups as $_group => $_tests) { if (@in_array($_group, $excludeGroups)) { foreach ($_tests as $_test) { if ($test === $_test) { $runTest = FALSE; break 2; } } } } } if ($runTest) { if ($test instanceof PHPUnit_Framework_TestCase) { $test->setBackupGlobals($this->backupGlobals); $test->setSharedFixture($this->sharedFixture); } $this->runTest($test, $result); } } } $result->endTestSuite($this); $this->tearDown(); return $result; }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { $this->currentTestName = PHPUnit_Util_Test::describe($test); $this->currentTestPass = TRUE; }
/** * @param PHPUnit_Framework_Test $test * @param string $color * @access private */ private function addTestNode(PHPUnit_Framework_Test $test, $color) { $name = PHPUnit_Util_Test::describe($test, FALSE); $this->graphs[$this->testSuiteLevel]->addNode($name[1], array('color' => $color, 'URL' => sprintf('%s-test.html#%s', PHPUnit_Util_Filesystem::getSafeFilename($name[0]), $name[1])), $this->testSuites[$this->testSuiteLevel]); $this->graphs[$this->testSuiteLevel]->addEdge(array($this->testSuites[$this->testSuiteLevel] => $name[1])); }
public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { $this->level++; $name = PHPUnit_Util_Test::describe($suite); if (empty($name)) { //$name = get_class($suite); $name = '-'; } $this->suiteStack[] = $name; }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { $this->currentTestName = PHPUnit_Util_Test::describe($test); $this->currentTestPass = TRUE; $this->write("\n"); $this->write(sprintf('test started: %s', $this->currentTestName)); }
private static function _getFilteredTests($testSuite, $filter, array $groups, array $excludeGroups) { $ret = array(); if (empty($groups)) { $tests = $testSuite->tests; } else { $tests = array(); foreach ($groups as $group) { if (isset($testSuite->groups[$group])) { $tests = array_merge($tests, $testSuite->groups[$group]); } } } foreach ($tests as $test) { if ($test instanceof PHPUnit_Framework_TestSuite) { $ret = array_merge($ret, self::_getFilteredTests($test, $filter, $groups, $excludeGroups)); } else { $runTest = TRUE; if ($filter !== FALSE) { $tmp = PHPUnit_Util_Test::describe($test, FALSE); if ($tmp[0] != '') { $name = join('::', $tmp); } else { $name = $tmp[1]; } if (preg_match($filter, $name) == 0) { $runTest = FALSE; } } if ($runTest && !empty($excludeGroups)) { foreach ($testSuite->groups as $_group => $_tests) { if (in_array($_group, $excludeGroups)) { foreach ($_tests as $_test) { if ($test === $_test) { $runTest = FALSE; break 2; } } } } } if ($runTest) { $ret[] = $test; } } } return $ret; }
/** * @param PHPUnit_Framework_Test $test * @param string $color * @access private */ private function addTestNode(PHPUnit_Framework_Test $test, $color) { $name = PHPUnit_Util_Test::describe($test, FALSE); $this->graph->addNode($name[1], array('color' => $color), $this->testSuites[$this->testSuiteLevel]); $this->graph->addEdge(array($this->testSuites[$this->testSuiteLevel] => $name[1])); }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { $this->currentTestName = PHPUnit_Util_Test::describe($test); $this->currentTestPass = TRUE; $this->write(array('event' => 'testStart', 'suite' => $this->currentTestSuiteName, 'test' => $this->currentTestName)); }
/** * @param PHPUnit_Framework_TestResult $result * @param PHPUnit_Framework_TestSuite $testSuite * @return array * @access protected * @since Method available since Release 3.0.0 */ protected static function getTests(PHPUnit_Framework_TestResult $result, PHPUnit_Framework_TestSuite $testSuite = NULL) { if ($testSuite === NULL) { $testSuite = $result->topTestSuite(); } $tests = array(); foreach ($testSuite->tests() as $test) { if ($test instanceof PHPUnit_Framework_TestSuite) { $tests = array_merge($tests, self::getTests($result, $test)); } else { $testName = PHPUnit_Util_Test::describe($test, FALSE); $tests[] = array('name' => $testName[1], 'object' => $test, 'result' => PHPUnit_Util_Test::lookupResult($test, $result)); } } return array($testSuite->getName() => $tests); }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { $this->current_suite()->tests[$test->getName()] = (object) array('description' => PHPUnit_Util_Test::describe($test), 'exceptions' => array(), 'assertions' => 0, 'success' => false); $this->test =& $this->current_suite()->tests[$test->getName()]; }
/** * A test ended. * * @param \PHPUnit_Framework_Test $test * @param float $time * * @return void */ public function endTest(\PHPUnit_Framework_Test $test, $time) { if ($test instanceof \PHPUnit_Framework_TestCase) { $assertionCount = $test->getNumAssertions(); $this->numAssertions += $assertionCount; if ($test->getStatus() == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { $status = 'failures'; } elseif ($test->getStatus() == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) { $status = 'errors'; } elseif ($test->getStatus() == \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) { $status = 'incompletes'; } elseif ($test->getStatus() == \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED) { $status = 'skips'; } elseif ($test->getStatus() == \PHPUnit_Runner_BaseTestRunner::STATUS_RISKY) { $status = 'risky'; } else { $status = 'tests'; } if (count($this->suites) - $this->endedSuites > 1) { $suiteName = end($this->suites); $this->stats[$suiteName][$status]++; $this->stats[$suiteName]['assertions'] += $assertionCount; } // updates also top test suite $suiteName = reset($this->suites); $this->stats[$suiteName][$status]++; $this->stats[$suiteName]['assertions'] += $assertionCount; } if (method_exists($test, 'hasOutput') && $test->hasOutput()) { $output = $test->getActualOutput(); } else { $output = ''; } $testName = $test->getName(); $context = array('testName' => $testName, 'testDescriptionArr' => \PHPUnit_Util_Test::describe($test, false), 'testDescriptionStr' => $test->toString(), 'operation' => __FUNCTION__, 'output' => $output); if (isset($assertionCount)) { $context['assertionCount'] = $assertionCount; } $this->logger->info(sprintf("Test '%s' ended.", $testName), $context); }
/** * A test ended. * * @param \PHPUnit_Framework_Test $test * @param float $time */ public function endTest(\PHPUnit_Framework_Test $test, $time) { if (!$this->lastTestFailed) { $this->writeProgress(sprintf("\rOK %d/%d %s", $this->numTestsRun, $this->numTests, \PHPUnit_Util_Test::describe($test))); } if ($test instanceof \PHPUnit_Framework_TestCase) { $this->numAssertions += $test->getNumAssertions(); } elseif ($test instanceof \PHPUnit_Extensions_PhptTestCase) { $this->numAssertions++; } $this->lastTestFailed = false; if ($test instanceof \PHPUnit_Framework_TestCase) { if (!$test->hasExpectationOnOutput()) { $this->write($test->getActualOutput()); } } }
/** * A test started. * * @param PHPUnit_Framework_Test $test * @return void */ public function startTest(PHPUnit_Framework_Test $test) { $this->level++; $this->starttimes[$this->level] = microtime(true); $this->write(sprintf("%s> TEST: %s\n", str_repeat(' ', $this->level), PHPUnit_Util_Test::describe($test))); }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { $this->lastEvent = self::EVENT_TEST_START; if ($this->debug) { $this->write(sprintf("\nStarting test '%s'.\n", PHPUnit_Util_Test::describe($test))); } $this->numTestsRun++; }
/** * A test started. * * @param \PHPUnit_Framework_Test $test */ public function startTest(\PHPUnit_Framework_Test $test) { $this->numTestsRun++; $this->lastEvent = self::EVENT_TEST_START; $len = strLen($this->numTests); $name = str_pad(\PHPUnit_Util_Test::describe($test, true), 100, ' ', STR_PAD_RIGHT); $this->write(sprintf('[%' . $len . 'd / %d ] %s', $this->numTestsRun, $this->numTests, $name)); }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { if ($this->debug) { $this->write(sprintf("\nStarting test '%s'.\n", PHPUnit_Util_Test::describe($test))); } }
/** * A test started. * * @param PHPUnit_Framework_Test $test */ public function startTest(PHPUnit_Framework_Test $test) { if ($this->verbose) { $this->numberOfTests[count($this->numberOfTests) - 1]++; } else { if (isset($this->numberOfTests[0])) { $this->numberOfTests[0]++; } else { $this->numberOfTests = array(1); } } $this->lastEvent = self::EVENT_TEST_START; if ($this->debug) { $this->write(sprintf("\nStarting test '%s'.\n", PHPUnit_Util_Test::describe($test))); } }
/** * @param PHPUnit_Framework_Test $test * @param string $prefix * @param string $directive */ protected function writeNotOk(PHPUnit_Framework_Test $test, $prefix = '', $directive = '') { $this->write(sprintf("not ok %d - %s%s%s\n", $this->testNumber, $prefix != '' ? $prefix . ': ' : '', PHPUnit_Util_Test::describe($test), $directive != '' ? ' # ' . $directive : '')); $this->testSuccessful = FALSE; }
/** * A test ended. * * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(PHPUnit_Framework_Test $test, $time) { if ($this->testSuccessful === TRUE) { $this->write(sprintf("ok %d - %s\n", $this->testNumber, PHPUnit_Util_Test::describe($test))); } $this->writeDiagnostics($test); }
/** * Runs the tests and collects their result in a TestResult. * * @param PHPUnit_Framework_TestResult $result * @param mixed $filter * @param array $groups * @param array $excludeGroups * @param boolean $processIsolation * @return PHPUnit_Framework_TestResult * @throws InvalidArgumentException */ public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE, array $groups = array(), array $excludeGroups = array(), $processIsolation = FALSE) { if ($result === NULL) { $result = $this->createResult(); } $result->startTestSuite($this); try { $this->setUp(); if ($this->testCase && method_exists($this->name, 'setUpBeforeClass')) { call_user_func(array($this->name, 'setUpBeforeClass')); } } catch (PHPUnit_Framework_SkippedTestSuiteError $e) { $numTests = count($this); for ($i = 0; $i < $numTests; $i++) { $result->addFailure($this, $e, 0); } return $result; } if (empty($groups)) { $tests = $this->tests; } else { $tests = new SplObjectStorage(); foreach ($groups as $group) { if (isset($this->groups[$group])) { foreach ($this->groups[$group] as $test) { $tests->attach($test); } } } } foreach ($tests as $test) { if ($result->shouldStop()) { break; } if ($test instanceof PHPUnit_Framework_TestSuite) { $test->setBackupGlobals($this->backupGlobals); $test->setBackupStaticAttributes($this->backupStaticAttributes); $test->run($result, $filter, $groups, $excludeGroups, $processIsolation); } else { $runTest = TRUE; if ($filter !== FALSE) { $tmp = PHPUnit_Util_Test::describe($test, FALSE); if ($tmp[0] != '') { $name = join('::', $tmp); } else { $name = $tmp[1]; } if (preg_match($filter, $name) == 0) { $runTest = FALSE; } } if ($runTest && !empty($excludeGroups)) { foreach ($this->groups as $_group => $_tests) { if (in_array($_group, $excludeGroups)) { foreach ($_tests as $_test) { if ($test === $_test) { $runTest = FALSE; break 2; } } } } } if ($runTest) { if ($test instanceof PHPUnit_Framework_TestCase) { $test->setBackupGlobals($this->backupGlobals); $test->setBackupStaticAttributes($this->backupStaticAttributes); $test->setRunTestInSeparateProcess($processIsolation); } $this->runTest($test, $result); } } } if ($this->testCase && method_exists($this->name, 'tearDownAfterClass')) { call_user_func(array($this->name, 'tearDownAfterClass')); } $this->tearDown(); $result->endTestSuite($this); return $result; }
/** * @param PHPUnit_Framework_TestCase $test * @return string the formatted test name */ protected function get_formatted_test_name(PHPUnit_Framework_TestCase $test) { $test_name = PHPUnit_Util_Test::describe($test); return $this->format_test_name($test_name); }