本文整理汇总了PHP中PHPUnit_Util_Test::getGroups方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::getGroups方法的具体用法?PHP PHPUnit_Util_Test::getGroups怎么用?PHP PHPUnit_Util_Test::getGroups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Test
的用法示例。
在下文中一共展示了PHPUnit_Util_Test::getGroups方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: shouldExclude
/**
* @param ReflectionClass $theClass
* @param Stagehand_TestRunner_Config $config
* @return boolean
*/
protected function shouldExclude(ReflectionClass $class, ReflectionMethod $method)
{
if (is_null($this->config->phpunitConfigFile)) {
return false;
}
$groups = PHPUnit_Util_Test::getGroups($class->getName(), $method->getName());
$shouldExclude = false;
$groupConfiguration = PHPUnit_Util_Configuration::getInstance($this->config->phpunitConfigFile)->getGroupConfiguration();
if (array_key_exists('include', $groupConfiguration) && count($groupConfiguration['include'])) {
$shouldExclude = true;
foreach ($groups as $group) {
if (in_array($group, $groupConfiguration['include'])) {
$shouldExclude = false;
break;
}
}
}
if (array_key_exists('exclude', $groupConfiguration) && count($groupConfiguration['exclude'])) {
foreach ($groups as $group) {
if (in_array($group, $groupConfiguration['exclude'])) {
$shouldExclude = true;
break;
}
}
}
return $shouldExclude;
}
示例2: endTest
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
if ($test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName());
if (in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
}
}
}
示例3: makeSuite
protected static function makeSuite($className, $group = null)
{
$suite = new PHPUnit_Framework_TestSuite();
$suite->setName($className);
$class = new ReflectionClass($className);
foreach (self::$engineConfigurations as $engineName => $opts) {
if ($group !== null && $group !== $engineName) {
continue;
}
try {
$parser = new Parser();
$parser->startExternalParse(Title::newMainPage(), new ParserOptions(), Parser::OT_HTML, true);
$engineClass = "Scribunto_{$engineName}Engine";
$engine = new $engineClass(self::$engineConfigurations[$engineName] + array('parser' => $parser));
$parser->scribunto_engine = $engine;
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$suite->addTest(new Scribunto_LuaEngineTestSkip($className, "interpreter for {$engineName} is not available"), array('Lua', $engineName));
continue;
}
// Work around PHPUnit breakage: the only straightforward way to
// get the data provider is to call
// PHPUnit_Util_Test::getProvidedData, but that instantiates the
// class without passing any parameters to the constructor. But we
// *need* that engine name.
self::$staticEngineName = $engineName;
$engineSuite = new PHPUnit_Framework_TestSuite();
$engineSuite->setName("{$engineName}: {$className}");
foreach ($class->getMethods() as $method) {
if (PHPUnit_Framework_TestSuite::isTestMethod($method) && $method->isPublic()) {
$name = $method->getName();
$groups = PHPUnit_Util_Test::getGroups($className, $name);
$groups[] = 'Lua';
$groups[] = $engineName;
$groups = array_unique($groups);
$data = PHPUnit_Util_Test::getProvidedData($className, $name);
if (is_array($data) || $data instanceof Iterator) {
// with @dataProvider
$dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name);
foreach ($data as $k => $v) {
$dataSuite->addTest(new $className($name, $v, $k, $engineName), $groups);
}
$engineSuite->addTest($dataSuite);
} elseif ($data === false) {
// invalid @dataProvider
$engineSuite->addTest(new PHPUnit_Framework_Warning("The data provider specified for {$className}::{$name} is invalid."));
} else {
// no @dataProvider
$engineSuite->addTest(new $className($name, array(), '', $engineName), $groups);
}
}
}
$suite->addTest($engineSuite);
}
return $suite;
}
示例4: fromTestCaseClass
/**
* @param string $className extending PHPUnit_Extensions_SeleniumTestCase
* @return PHPUnit_Extensions_SeleniumTestSuite
*/
public static function fromTestCaseClass($className)
{
$suite = new self();
$suite->setName($className);
$class = new ReflectionClass($className);
$classGroups = PHPUnit_Util_Test::getGroups($className);
$staticProperties = $class->getStaticProperties();
//BC: renamed seleneseDirectory -> selenesePath
if (!isset($staticProperties['selenesePath']) && isset($staticProperties['seleneseDirectory'])) {
$staticProperties['selenesePath'] = $staticProperties['seleneseDirectory'];
}
// Create tests from Selenese/HTML files.
if (isset($staticProperties['selenesePath']) && (is_dir($staticProperties['selenesePath']) || is_file($staticProperties['selenesePath']))) {
if (is_dir($staticProperties['selenesePath'])) {
$files = array_merge(self::getSeleneseFiles($staticProperties['selenesePath'], '.htm'), self::getSeleneseFiles($staticProperties['selenesePath'], '.html'));
} else {
$files[] = realpath($staticProperties['selenesePath']);
}
// Create tests from Selenese/HTML files for multiple browsers.
if (!empty($staticProperties['browsers'])) {
foreach ($staticProperties['browsers'] as $browser) {
$browserSuite = PHPUnit_Extensions_SeleniumBrowserSuite::fromClassAndBrowser($className, $browser);
foreach ($files as $file) {
self::addGeneratedTestTo($browserSuite, new $className($file, array(), '', $browser), $classGroups);
}
$suite->addTest($browserSuite);
}
} else {
// Create tests from Selenese/HTML files for single browser.
foreach ($files as $file) {
self::addGeneratedTestTo($suite, new $className($file), $classGroups);
}
}
}
// Create tests from test methods for multiple browsers.
if (!empty($staticProperties['browsers'])) {
foreach ($staticProperties['browsers'] as $browser) {
$browserSuite = PHPUnit_Extensions_SeleniumBrowserSuite::fromClassAndBrowser($className, $browser);
foreach ($class->getMethods() as $method) {
$browserSuite->addTestMethod($class, $method);
}
$browserSuite->setupSpecificBrowser($browser);
$suite->addTest($browserSuite);
}
} else {
// Create tests from test methods for single browser.
foreach ($class->getMethods() as $method) {
$suite->addTestMethod($class, $method);
}
}
return $suite;
}
示例5: __construct
/**
* @constructor
* @param string $theClass
* @param string $name
*/
public function __construct($theClass = '', $name = '')
{
$this->initObjectManager();
$this->appStateFactory = $this->objectManager->get('Mtf\\App\\State\\StateFactory');
/** @var $applicationStateIterator \Mtf\Util\Iterator\ApplicationState */
$applicationStateIterator = $this->objectManager->create('Mtf\\Util\\Iterator\\ApplicationState');
while ($applicationStateIterator->valid()) {
$appState = $applicationStateIterator->current();
$callback = [$this, 'appStateCallback'];
/** @var $suite \Mtf\TestSuite\TestCase */
$suite = $this->objectManager->create('Mtf\\TestSuite\\TestCase', ['name' => $appState['name']]);
$suite->setCallback($callback, $appState);
$this->addTest($suite, \PHPUnit_Util_Test::getGroups(get_class($suite), $suite->getName()));
$applicationStateIterator->next();
}
parent::__construct('Application State Runner');
}
示例6: addTestsFromTestCaseClass
/**
* Composes a TestSuite from a TestCaseClass or uses $staticProperties['phantomPath']
* for creation of a TestSuite from a folder.
*
* @param string $className extending PHPUnit_Extensions_PhantomTestCase
* @return PHPUnit_Extensions_PhantomTestSuite
*/
public static function addTestsFromTestCaseClass($className)
{
$suite = new self();
$suite->setName($className);
// use Ref to allow access to class properties
$class = new ReflectionClass($className);
$classGroups = PHPUnit_Util_Test::getGroups($className);
$staticProperties = $class->getStaticProperties();
// Tests come from Folder.
// create tests from a folder with phantom .js or .coffee files
if (isset($staticProperties['phantomPath']) === true) {
$files = array();
if (is_dir($staticProperties['phantomPath']) === true) {
$files = array_merge(self::getTestFilesFromFolder($staticProperties['phantomPath'], '.js'), self::getTestFilesFromFolder($staticProperties['phantomPath'], '.coffee'));
} else {
$files[] = realpath($staticProperties['phantomPath']);
}
// create tests from PhantomJS javascript or coffee script files
foreach ($files as $file) {
$basename = basename($file);
$filename = str_replace(array('.js', '.coffee'), array('', ''), $basename);
// exclude some javascript tests from execution, because:
$excludedFiles = array('modernizr', 'jquery', 'movies', 'seasonfood', 'outputEncoding', 'sleepsort', 'stdin-stdout-stderr', 'universe', 'colorwheel', 'technews');
if (in_array($filename, $excludedFiles) === true) {
continue;
}
// filename to testname
$testname = 'test_' . str_replace('.', '_', $basename);
// every Phantom test file gets its own test case (one executePhantomJS call each)
$test = new PHPUnit_Extensions_Phantom_FileExecute($testname, array($file));
$suite->addTest($test, $classGroups);
}
} else {
// Test come from a TestCaseClass.
// create tests for all methods of the test case class
foreach ($class->getMethods() as $method) {
$suite->addTestMethod($class, $method);
}
}
return $suite;
}
示例7: __construct
/**
* @constructor
* @param string $theClass
* @param string $name
*/
public function __construct($theClass = '', $name = '')
{
$this->initObjectManager();
$this->testSuiteFactory = $this->objectManager->get('Mtf\\TestSuite\\TestSuiteFactory');
/** @var $testIterator \Mtf\Util\Iterator\TestCase */
$testIterator = $this->objectManager->create('Mtf\\Util\\Iterator\\TestCase');
while ($testIterator->valid()) {
$arguments = $testIterator->current();
$class = $arguments['class'];
$factory = $this->testSuiteFactory;
$testCallback = $this->objectManager->create('Mtf\\TestSuite\\Callback', ['factory' => $factory, 'arguments' => $arguments, 'theClass' => $class]);
$rule = $this->objectManager->get('Mtf\\TestRunner\\Rule\\SuiteComposite');
$testCaseSuite = $this->testSuiteFactory->get($class);
$allow = $rule->filterSuite($testCaseSuite);
if ($allow) {
$this->addTest($testCallback, \PHPUnit_Util_Test::getGroups($class));
}
$testIterator->next();
}
parent::__construct($name);
}
示例8: __construct
/**
* @constructor
* @param string $class
* @param string $name
* @param string $path
*/
public function __construct($class = '', $name = '', $path = '')
{
// we don't need parent class to collect tests, so don't call parent constructor
$this->initObjectManager();
$name = $name ? $name : $class;
$this->setName($name);
if (is_string($class) && class_exists($class, false)) {
$arguments = ['class' => $class, 'path' => $path];
$theClass = new \ReflectionClass($class);
foreach ($theClass->getMethods() as $method) {
if (!$this->isPublicTestMethod($method)) {
continue;
}
$_arguments = $arguments;
$methodName = $method->getName();
$_arguments['name'] = $methodName;
$test = $this->objectManager->create('Mtf\\TestSuite\\InjectableMethod', $_arguments);
$this->addTest($test, \PHPUnit_Util_Test::getGroups($class, $methodName));
}
}
$this->testCase = true;
}
示例9: __construct
public function __construct(PHPUnit_Framework_TestSuite $suite, array $groups)
{
$groupSuites = array();
$name = $suite->getName();
foreach ($groups as $group) {
$groupSuites[$group] = new PHPUnit_Framework_TestSuite($name . ' - ' . $group);
$this->addTest($groupSuites[$group]);
}
$tests = new RecursiveIteratorIterator(new PHPUnit_Util_TestSuiteIterator($suite), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($tests as $test) {
if ($test instanceof PHPUnit_Framework_TestCase) {
$testGroups = PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
foreach ($groups as $group) {
foreach ($testGroups as $testGroup) {
if ($group == $testGroup) {
$groupSuites[$group]->addTest($test);
}
}
}
}
}
}
示例10: __construct
public function __construct(PHPUnit_Framework_TestSuite $suite, array $groups)
{
$groupSuites = array();
$name = $suite->getName();
foreach ($groups as $group) {
$groupSuites[$group] = new PHPUnit_Framework_TestSuite($name . ' - ' . $group);
$this->addTest($groupSuites[$group]);
}
$tests = new RecursiveIteratorIterator(new PHPUnit_Util_TestSuiteIterator($suite), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($tests as $test) {
if ($test instanceof PHPUnit_Framework_TestCase) {
$class = new ReflectionClass($test);
$method = $class->getMethod($test->getName(FALSE));
$testGroups = PHPUnit_Util_Test::getGroups($method->getDocComment(), PHPUnit_Util_Test::getGroups($class));
foreach ($groups as $group) {
foreach ($testGroups as $testGroup) {
if ($group == $testGroup) {
$groupSuites[$group]->addTest($test);
}
}
}
}
}
}
示例11: __construct
/**
* Constructs a new TestSuite:
*
* - PHPUnit_Framework_TestSuite() constructs an empty TestSuite.
*
* - PHPUnit_Framework_TestSuite(ReflectionClass) constructs a
* TestSuite from the given class.
*
* - PHPUnit_Framework_TestSuite(ReflectionClass, String)
* constructs a TestSuite from the given class with the given
* name.
*
* - PHPUnit_Framework_TestSuite(String) either constructs a
* TestSuite from the given class (if the passed string is the
* name of an existing class) or constructs an empty TestSuite
* with the given name.
*
* @param mixed $theClass
* @param string $name
* @throws InvalidArgumentException
* @access public
*/
public function __construct($theClass = '', $name = '')
{
$argumentsValid = FALSE;
if (is_object($theClass) && $theClass instanceof ReflectionClass) {
$argumentsValid = TRUE;
} else {
if (is_string($theClass) && $theClass !== '' && class_exists($theClass, FALSE)) {
$argumentsValid = TRUE;
if ($name == '') {
$name = $theClass;
}
$theClass = new ReflectionClass($theClass);
} else {
if (is_string($theClass)) {
$this->setName($theClass);
return;
}
}
}
if (!$argumentsValid) {
throw new InvalidArgumentException();
}
PHPUnit_Util_Filter::addFileToFilter(realpath($theClass->getFilename()), 'TESTS');
if ($name != '') {
$this->setName($name);
} else {
$this->setName($theClass->getName());
}
$constructor = $theClass->getConstructor();
if ($constructor !== NULL && !$constructor->isPublic()) {
$this->addTest(self::warning(sprintf('Class "%s" has no public constructor.', $theClass->getName())));
return;
}
$className = $theClass->getName();
$names = array();
$classGroups = PHPUnit_Util_Test::getGroups($theClass);
foreach ($theClass->getMethods() as $method) {
if (strpos($method->getDeclaringClass()->getName(), 'PHPUnit_') !== 0) {
$this->addTestMethod($method, PHPUnit_Util_Test::getGroups($method, $classGroups), $names, $theClass);
}
}
if (empty($this->tests)) {
$this->addTest(self::warning(sprintf('No tests found in class "%s".', $theClass->getName())));
}
}
示例12: testApiTestGroup
public function testApiTestGroup()
{
$groups = PHPUnit_Util_Test::getGroups(get_class($this));
$constraint = PHPUnit_Framework_Assert::logicalOr($this->contains('medium'), $this->contains('large'));
$this->assertThat($groups, $constraint, 'ApiTestCase::setUp can be slow, tests must be "medium" or "large"');
}
示例13: createTest
/**
* @param ReflectionClass $theClass
* @param string $name
* @param array $classGroups
* @return PHPUnit_Framework_Test
*/
public static function createTest(ReflectionClass $theClass, $name, array $classGroups = array())
{
$className = $theClass->getName();
$method = new ReflectionMethod($className, $name);
$methodDocComment = $method->getDocComment();
if (!$theClass->isInstantiable()) {
return self::warning(sprintf('Cannot instantiate class "%s".', $className));
}
$constructor = $theClass->getConstructor();
$expectedException = PHPUnit_Util_Test::getExpectedException($methodDocComment);
if ($constructor !== NULL) {
$parameters = $constructor->getParameters();
// TestCase() or TestCase($name)
if (count($parameters) < 2) {
$test = new $className();
} else {
$data = PHPUnit_Util_Test::getProvidedData($className, $name, $methodDocComment);
$groups = PHPUnit_Util_Test::getGroups($methodDocComment, $classGroups);
if (is_array($data) || $data instanceof Iterator) {
$test = new PHPUnit_Framework_TestSuite($className . '::' . $name);
foreach ($data as $_dataName => $_data) {
$_test = new $className($name, $_data, $_dataName);
if ($_test instanceof PHPUnit_Framework_TestCase && isset($expectedException)) {
$_test->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
}
$test->addTest($_test, $groups);
}
} else {
$test = new $className();
}
}
}
if ($test instanceof PHPUnit_Framework_TestCase) {
$test->setName($name);
if (isset($expectedException)) {
$test->setExpectedException($expectedException['class'], $expectedException['message'], $expectedException['code']);
}
}
return $test;
}
示例14: endTest
public function endTest(\PHPUnit_Framework_Test $test, $time)
{
if ($this->expectedDeprecations) {
restore_error_handler();
try {
$prefix = "@expectedDeprecation:\n ";
$test->assertStringMatchesFormat($prefix . implode("\n ", $this->expectedDeprecations), $prefix . implode("\n ", $this->gatheredDeprecations));
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$test->getTestResultObject()->addFailure($test, $e, $time);
}
$this->expectedDeprecations = $this->gatheredDeprecations = $this->previousErrorHandler = null;
}
if (-2 < $this->state && $test instanceof \PHPUnit_Framework_TestCase) {
$groups = \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false));
if (in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
}
if (in_array('dns-sensitive', $groups, true)) {
DnsMock::withMockedHosts(array());
}
}
}
示例15: register
public static function register($mode = false)
{
if (self::$isRegistered) {
return;
}
$deprecations = array('unsilencedCount' => 0, 'remainingCount' => 0, 'legacyCount' => 0, 'otherCount' => 0, 'unsilenced' => array(), 'remaining' => array(), 'legacy' => array(), 'other' => array());
$deprecationHandler = function ($type, $msg, $file, $line, $context) use(&$deprecations, $mode) {
if (E_USER_DEPRECATED !== $type) {
return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
}
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
$i = count($trace);
while (isset($trace[--$i]['class']) && ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_'))) {
// No-op
}
if (0 !== error_reporting()) {
$group = 'unsilenced';
$ref =& $deprecations[$group][$msg]['count'];
++$ref;
} elseif (isset($trace[$i]['object']) || isset($trace[$i]['class'])) {
$class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class'];
$method = $trace[$i]['function'];
$group = 0 === strpos($method, 'testLegacy') || 0 === strpos($method, 'provideLegacy') || 0 === strpos($method, 'getLegacy') || strpos($class, '\\Legacy') || in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true) ? 'legacy' : 'remaining';
if ('legacy' !== $group && 'weak' !== $mode) {
$ref =& $deprecations[$group][$msg]['count'];
++$ref;
$ref =& $deprecations[$group][$msg][$class . '::' . $method];
++$ref;
}
} else {
$group = 'other';
$ref =& $deprecations[$group][$msg]['count'];
++$ref;
}
++$deprecations[$group . 'Count'];
};
$oldErrorHandler = set_error_handler($deprecationHandler);
if (null !== $oldErrorHandler) {
restore_error_handler();
if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {
restore_error_handler();
self::register($mode);
}
} else {
self::$isRegistered = true;
if (self::hasColorSupport()) {
$colorize = function ($str, $red) {
$color = $red ? '41;37' : '43;30';
return "[{$color}m{$str}[0m";
};
} else {
$colorize = function ($str) {
return $str;
};
}
register_shutdown_function(function () use($mode, &$deprecations, $deprecationHandler, $colorize) {
$currErrorHandler = set_error_handler('var_dump');
restore_error_handler();
if ($currErrorHandler !== $deprecationHandler) {
echo "\n", $colorize('THE ERROR HANDLER HAS CHANGED!', true), "\n";
}
$cmp = function ($a, $b) {
return $b['count'] - $a['count'];
};
foreach (array('unsilenced', 'remaining', 'legacy', 'other') as $group) {
if ($deprecations[$group . 'Count']) {
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group . 'Count']), 'legacy' !== $group), "\n";
uasort($deprecations[$group], $cmp);
foreach ($deprecations[$group] as $msg => $notices) {
echo "\n", rtrim($msg, '.'), ': ', $notices['count'], "x\n";
arsort($notices);
foreach ($notices as $method => $count) {
if ('count' !== $method) {
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
}
}
}
}
}
if (!empty($notices)) {
echo "\n";
}
if ('weak' !== $mode && ($deprecations['unsilenced'] || $deprecations['remaining'] || $deprecations['other'])) {
exit(1);
}
});
}
}