本文整理汇总了PHP中PHPUnit_Framework_TestSuite::tests方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestSuite::tests方法的具体用法?PHP PHPUnit_Framework_TestSuite::tests怎么用?PHP PHPUnit_Framework_TestSuite::tests使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestSuite
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestSuite::tests方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startTestSuite
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$suiteName = $suite->getName();
if (-1 === $this->state) {
echo "Testing {$suiteName}\n";
$this->state = 0;
if (!class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry', false) && class_exists('Doctrine\\Common\\Annotations\\AnnotationRegistry')) {
AnnotationRegistry::registerLoader('class_exists');
}
if ($this->skippedFile = getenv('SYMFONY_PHPUNIT_SKIPPED_TESTS')) {
$this->state = 1;
if (file_exists($this->skippedFile)) {
$this->state = 2;
if (!($this->wasSkipped = (require $this->skippedFile))) {
echo "All tests already ran successfully.\n";
$suite->setTests(array());
}
}
}
foreach ($suite->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite && in_array('time-sensitive', \PHPUnit_Util_Test::getGroups($test->getName()), true)) {
ClockMock::register($test->getName());
}
}
} elseif (2 === $this->state) {
$skipped = array();
foreach ($suite->tests() as $test) {
if (!$test instanceof \PHPUnit_Framework_TestCase || isset($this->wasSkipped[$suiteName]['*']) || isset($this->wasSkipped[$suiteName][$test->getName()])) {
$skipped[] = $test;
}
}
$suite->setTests($skipped);
}
}
示例2: markTestsSkipped
/**
* Mark tests skipped
*
* @param TestCase $test
* @param array $errors
* @todo Mark tests skipped, unfortunately tests are skipped by invoking exceptions from the tests.
*/
private function markTestsSkipped(TestCase $test, array $errors)
{
list($identifier, $className, $testName) = $this->storage->getTestIdentifiers($test);
if ($this->mergeMode === self::MERGE_MODE_ERROR_AND_SKIP && count($errors) > 0 && count($this->suite->tests()) > count($errors) && $this->storage->getRecording(array(StorageInterface::STATUS_PASSED), $identifier)) {
// mark test skipped. quite hard, cause skipped tests are handled through exceptions
}
}
示例3: browserOnAllTests
private function browserOnAllTests(PHPUnit_Framework_TestSuite $suite, array $browser)
{
foreach ($suite->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
$this->browserOnAllTests($test, $browser);
} else {
$test->setupSpecificBrowser($browser);
}
}
}
示例4: startTestSuite
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$this->suiteLevel++;
$this->currentSuiteName = $suite->getName();
if ($this->suiteLevel == 1 + $this->rootSuiteNestingLevel) {
$this->rootSuiteName = $suite->getName();
$suites = $suite->tests();
$filtered = $this->filterSuites($suites);
$suite->setTests($filtered);
}
}
示例5: _getTests
protected function _getTests(PHPUnit_Framework_TestSuite $suite)
{
$tests = array();
foreach ($suite->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
$tests = array_merge($tests, $this->_getTests($test));
} else {
$tests[] = $test;
}
}
return $tests;
}
示例6: extractSuite
protected function extractSuite(\PHPUnit_Framework_TestSuite $suite)
{
$testList = $suite->tests();
foreach ($testList as $test) {
if ($test instanceof \PHPUnit_Framework_TestSuite) {
$this->extractSuite($test);
} else {
$ref = new \ReflectionClass($test);
self::addFile($ref);
}
}
}
示例7: endTestSuite
/**
* Clear test method properties after each test suite
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
$tests = $suite->tests();
foreach ($tests as $test) {
$reflectionClass = new ReflectionClass($test);
$properties = $reflectionClass->getProperties();
foreach ($properties as $property) {
$property->setAccessible(true);
$value = $property->getValue($test);
if (is_object($value) && method_exists($value, '__destruct')) {
$value->__destruct();
}
$property->setValue($test, null);
}
}
}
示例8: sortTestSuite
private function sortTestSuite(TestSuite $suite)
{
$tests = $suite->tests();
$testsOrderResult = array(static::SORT_NONE, null);
foreach ($tests as $test) {
if ($test instanceof TestCase && Util::getInvisibleProperty($test, 'dependencies', 'hasDependencies')) {
return $testsOrderResult;
}
}
$orderedTests = new SegmentedQueue($tests);
$orderedTests->setMergeMode($this->mergeMode);
foreach ($tests as $position => $test) {
list($testOrderResult, $time) = $this->sortTest($test, $position, $orderedTests);
if ($testsOrderResult[0] < $testOrderResult) {
$testsOrderResult = array($testOrderResult, $time);
}
}
$groups = Util::getInvisibleProperty($suite, 'groups', 'getGroupDetails');
$groupsOrderResult = array(static::SORT_NONE, null);
foreach ($groups as $groupName => $group) {
$groupOrderResult = array(static::SORT_NONE, null);
$orderedGroup = new SegmentedQueue($group);
$orderedGroup->setMergeMode($this->mergeMode);
foreach ($group as $position => $test) {
list($testOrderResult, $time) = $this->sortTest($test, $position, $orderedGroup);
if ($groupOrderResult[0] < $testOrderResult) {
$groupOrderResult = array($testOrderResult, $time);
}
}
if ($groupOrderResult[0] > static::SORT_NONE) {
$groups[$groupName] = iterator_to_array($orderedGroup);
if ($groupsOrderResult[0] < $groupOrderResult[0]) {
$groupsOrderResult = $groupOrderResult;
}
}
}
if ($testsOrderResult[0] > static::SORT_NONE) {
Util::setInvisibleProperty($suite, 'tests', iterator_to_array($orderedTests), 'setTests');
}
if ($groupsOrderResult) {
Util::setInvisibleProperty($suite, 'groups', $groups, 'setGroupDetails');
}
return $testsOrderResult[0] > $groupsOrderResult[0] ? $testsOrderResult : $groupsOrderResult;
}
示例9: endTestSuite
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
foreach ($suite->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
return false;
}
}
$sb = "Testsuite: " . $suite->getName() . "\n";
$sb .= "Tests run: " . $this->getRunCount();
$sb .= ", Failures: " . $this->getFailureCount();
$sb .= ", Errors: " . $this->getErrorCount();
$sb .= ", Incomplete: " . $this->getIncompleteCount();
$sb .= ", Skipped: " . $this->getSkippedCount();
$sb .= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n";
if ($this->out != NULL) {
$this->out->write($sb);
$this->out->write($this->inner);
}
parent::endTestSuite($suite);
}
示例10: startTestSuite
public function startTestSuite(\PHPUnit_Framework_TestSuite $mainSuite)
{
if (null !== self::$enabledPolyfills) {
return;
}
self::$enabledPolyfills = false;
foreach ($mainSuite->tests() as $suite) {
$testClass = $suite->getName();
if (!($tests = $suite->tests())) {
continue;
}
if (!preg_match('/^(.+)\\\\Tests(\\\\.*)Test$/', $testClass, $m)) {
$mainSuite->addTest(self::warning('Unknown naming convention for ' . $testClass));
continue;
}
$testedClass = new \ReflectionClass($m[1] . $m[2]);
$bootstrap = new \SplFileObject(dirname($testedClass->getFileName()) . '/bootstrap.php');
$warnings = array();
$defLine = null;
foreach (new \RegexIterator($bootstrap, '/return p\\\\' . $testedClass->getShortName() . '::/') as $defLine) {
if (!preg_match('/^\\s*function (?P<name>[^\\(]++)(?P<signature>\\([^\\)]*+\\)) \\{ (?<return>return p\\\\' . $testedClass->getShortName() . '::[^\\(]++)(?P<args>\\([^\\)]*+\\)); \\}$/', $defLine, $f)) {
$warnings[] = self::warning('Invalid line in bootstrap.php: ' . trim($defLine));
continue;
}
$testNamespace = substr($testClass, 0, strrpos($testClass, '\\'));
if (function_exists($testNamespace . '\\' . $f['name'])) {
continue;
}
try {
$r = new \ReflectionFunction($f['name']);
if ($r->isUserDefined()) {
throw new \ReflectionException();
}
if (false !== strpos($f['signature'], '&')) {
$defLine = sprintf('return \\%s%s', $f['name'], $f['args']);
} else {
$defLine = sprintf("return \\call_user_func_array('%s', func_get_args())", $f['name']);
}
} catch (\ReflectionException $e) {
$defLine = sprintf("throw new \\PHPUnit_Framework_SkippedTestError('Internal function not found: %s')", $f['name']);
}
eval(<<<EOPHP
namespace {$testNamespace};
use Symfony\\Polyfill\\Util\\TestListener;
use {$testedClass->getNamespaceName()} as p;
function {$f['name']}{$f['signature']}
{
if ('{$testClass}' === TestListener::\$enabledPolyfills) {
{$f['return']}{$f['args']};
}
{$defLine};
}
EOPHP
);
}
if (!$warnings && null === $defLine) {
$warnings[] = new \PHPUnit_Framework_SkippedTestCase('No Polyfills found in bootstrap.php for ' . $testClass);
} else {
$mainSuite->addTest(new static($suite));
}
}
foreach ($warnings as $w) {
$mainSuite->addTest($w);
}
}
示例11: __construct
/**
* Constructor.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function __construct(PHPUnit_Framework_TestSuite $testSuite)
{
$this->tests = $testSuite->tests();
}
示例12: endTestSuite
/**
* Handler for 'endTestSuite' event
*
* @param \PHPUnit_Framework_TestSuite $suite
*/
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
{
$clearStatics = false;
foreach ($suite->tests() as $test) {
if ($test instanceof \Magento\TestFramework\TestCase\AbstractController) {
$clearStatics = true;
break;
}
}
if ($clearStatics) {
self::restoreStaticVariables();
}
}
示例13: filterTests
/**
* @param \PHPUnit_Framework_TestSuite $testSuite
* @param integer $filter
* @since Method available since Release 3.0.3
*/
protected function filterTests(\PHPUnit_Framework_TestSuite $testSuite, $filter)
{
$filteredTests = array();
foreach ($testSuite->tests() as $test) {
if ($test instanceof \PHPUnit_Framework_TestCase) {
$testClassName = get_class($test);
$testMethodName = $test->getName(false);
if ($this->testTargetRepository->shouldTreatElementAsTest($testClassName, $filter == self::$FILTER_METHOD ? $testMethodName : null)) {
$filteredTests[] = $test;
}
} else {
$this->filterTests($test, $filter);
if (count($test) > 0) {
$filteredTests[] = $test;
}
}
}
$testSuiteClass = new \ReflectionClass($testSuite);
$testsProperty = $testSuiteClass->getProperty('tests');
$testsProperty->setAccessible(true);
$testsProperty->setValue($testSuite, $filteredTests);
$testsProperty->setAccessible(false);
$numTestsProperty = $testSuiteClass->getProperty('numTests');
$numTestsProperty->setAccessible(true);
$numTestsProperty->setValue($testSuite, -1);
$numTestsProperty->setAccessible(false);
$groupsProperty = $testSuiteClass->getProperty('groups');
$groupsProperty->setAccessible(true);
$groups = $groupsProperty->getValue($testSuite);
$groups = array_map(function ($tests) use($filteredTests) {
return array_filter($tests, function ($test) use($filteredTests) {
return in_array($test, $filteredTests, true);
});
}, $groups);
$groupsProperty->setValue($testSuite, $groups);
$groupsProperty->setAccessible(false);
}
示例14: runTestCase
/**
* Runs a testcase as given in the GET/POST variable "testCaseFile".
*
* @param PHPUnit_Framework_TestSuite $testSuiteWithAllTestCases suite with all test cases
* @param PHPUnit_Framework_TestResult $testResult the test result (will be modified)
*
* @return void
*/
protected function runTestCase(PHPUnit_Framework_TestSuite $testSuiteWithAllTestCases, PHPUnit_Framework_TestResult $testResult)
{
$testCaseFileName = $this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TESTCASE);
$this->testListener->setTestSuiteName($testCaseFileName);
$suiteNameHasBeenDisplayed = FALSE;
$totalNumberOfTestCases = 0;
foreach ($testSuiteWithAllTestCases->tests() as $testCases) {
foreach ($testCases->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
list($testIdentifier, $unused) = explode('::', $test->getName());
} else {
$testIdentifier = get_class($test);
}
if ($testIdentifier === $testCaseFileName) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
$totalNumberOfTestCases += $test->count();
} else {
$totalNumberOfTestCases++;
}
}
}
}
$this->testListener->setTotalNumberOfTests($totalNumberOfTestCases);
$this->renderProgressbar();
foreach ($testSuiteWithAllTestCases->tests() as $testCases) {
foreach ($testCases->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
list($testIdentifier, $unused) = explode('::', $test->getName());
} else {
$testIdentifier = get_class($test);
}
if ($testIdentifier === $testCaseFileName) {
if (!$suiteNameHasBeenDisplayed) {
$this->outputService->output('<h2 class="testSuiteName">Testsuite: ' . $testCaseFileName . '</h2>');
$suiteNameHasBeenDisplayed = TRUE;
}
$test->run($testResult);
}
}
}
if (!is_object($testResult)) {
$this->outputService->output('<h2 class="hadError">Error</h2><p>The test <strong> ' . htmlspecialchars($this->request->getAsString(Tx_Phpunit_Interface_Request::PARAMETER_KEY_TEST)) . '</strong> could not be found.</p>');
return;
}
}
示例15: testMessageNameForTestWithDataProvider
public function testMessageNameForTestWithDataProvider()
{
$theClass = new \ReflectionClass('\\PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest');
$testSuite = new \PHPUnit_Framework_TestSuite($theClass);
$tests = $testSuite->tests();
$this->assertArrayHasKey(0, $tests);
$this->assertInstanceOf('PHPUnit_Framework_TestSuite_DataProvider', $tests[0]);
/* @var \PHPUnit_Framework_TestSuite_DataProvider $dataProviderTestSuite */
$dataProviderTestSuite = $tests[0];
$this->assertArrayHasKey(1, $tests);
$this->assertInstanceOf('\\PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest', $tests[1]);
/* @var DataProviderTest $simpleMethodTest*/
$simpleMethodTest = $tests[1];
$this->listener->startTestSuite($testSuite);
$this->listener->startTestSuite($dataProviderTestSuite);
foreach ($dataProviderTestSuite as $test) {
$this->listener->startTest($test);
$this->listener->endTest($test, 5);
}
$this->listener->endTestSuite($dataProviderTestSuite);
$this->listener->startTest($simpleMethodTest);
$this->listener->endTest($simpleMethodTest, 6);
$this->listener->endTestSuite($testSuite);
$expectedOutput = <<<EOS
##teamcity[testSuiteStarted name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteStarted name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest::testMethodWithDataProvider' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "two"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "two"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "three"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "three"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "four"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "four"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testMethodWithDataProvider with data set "five.one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='5000' name='testMethodWithDataProvider with data set "five.one"' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteFinished name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest::testMethodWithDataProvider' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testStarted captureStandardOutput='true' name='testSimpleMethod' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testFinished duration='6000' name='testSimpleMethod' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
##teamcity[testSuiteFinished name='PHPUnit\\TeamCity\\Tests\\Fixtures\\DataProviderTest' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']
EOS;
$this->assertOutputSame($expectedOutput);
}