/** * @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; }
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); } } }
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; }
/** * @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; }
/** * @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'); }
/** * 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; }
/** * @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); }
/** * @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; }
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); } } } } } }
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); } } } } } }
/** * 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()))); } }
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"'); }
/** * @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; }
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()); } } }
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); } }); } }
/** * Check if method where deprecation happened is marked as legacy * * @param \ReflectionMethod $method * * @return bool */ private function isLegacyTestMethod(\ReflectionMethod $method) { return 0 === strpos($method->name, 'testLegacy') || 0 === strpos($method->name, 'provideLegacy') || 0 === strpos($method->name, 'getLegacy') || strpos($method->class, '\\Legacy') || in_array('legacy', \PHPUnit_Util_Test::getGroups($method->class, $method->name), true); }
protected function createTestFromCestMethod($cestInstance, $methodName, $file, $guy) { $testClass = get_class($cestInstance); if (strpos($methodName, '_') === 0) { return; } $overriddenGuy = Annotation::forMethod($testClass, $methodName)->fetch('guy'); if (!$overriddenGuy) { $overriddenGuy = Annotation::forClass($testClass)->fetch('guy'); } if ($overriddenGuy) { $guy = $overriddenGuy; } $cest = new TestCase\Cest($this->dispatcher, array('name' => $methodName, 'instance' => $cestInstance, 'method' => $methodName, 'file' => $file, 'bootstrap' => $this->settings['bootstrap'], 'guy' => $guy)); $cest->getScenario()->env(Annotation::forMethod($testClass, $methodName)->fetchAll('env')); $cest->getScenario()->groups(\PHPUnit_Util_Test::getGroups($testClass, $methodName)); $cest->setDependencies(\PHPUnit_Util_Test::getDependencies($testClass, $methodName)); $cest->preload(); return $cest; }
/** * Custom implementation of native PHPUnit_Framework_TestSuite::createTest method * - Test Case class should be instantiated with MTF Object Manager * - Data Provider Test Suite should be instantiated with MTF Object Manager * * @param \ReflectionClass $theClass * @param string $name * @param array $arguments * @return \PHPUnit_Framework_Test * @throws \PHPUnit_Framework_Exception */ public static function createTest(\ReflectionClass $theClass, $name, array $arguments = []) { $objectManager = \Mtf\ObjectManager::getInstance(); $class = $theClass->getName(); $arguments['name'] = $name; $backupSettings = \PHPUnit_Util_Test::getBackupSettings($class, $name); $preserveGlobalState = \PHPUnit_Util_Test::getPreserveGlobalStateSettings($class, $name); $runTestInSeparateProcess = \PHPUnit_Util_Test::getProcessIsolationSettings($class, $name); try { $data = \PHPUnit_Util_Test::getProvidedData($class, $name); } catch (\Exception $e) { /** @var EventManager $eventManager */ $eventManager = $objectManager->get('Mtf\\System\\Event\\Event'); $eventManager->dispatchEvent(['exception'], [$e]); $message = sprintf('The data provider specified for %s::%s is invalid.', $class, $name); $_message = $e->getMessage(); if (!empty($_message)) { $message .= "\n" . $_message; } $data = new \PHPUnit_Framework_Warning($message); } // Test method with @dataProvider. if (isset($data)) { $test = $objectManager->create('Mtf\\TestSuite\\InjectableDataProvider', ['class' => $class . '::' . $name]); if (empty($data)) { $data = new \PHPUnit_Framework_Warning(sprintf('No tests found in suite "%s".', $test->getName())); } $groups = \PHPUnit_Util_Test::getGroups($class, $name); if ($data instanceof \PHPUnit_Framework_Warning) { $test->addTest($data, $groups); } else { foreach ($data as $_dataName => $_data) { $_arguments = $arguments; $_arguments['data'] = $_data; $_arguments['dataName'] = $_dataName; $_test = $objectManager->create($class, $_arguments); if ($runTestInSeparateProcess) { $_test->setRunTestInSeparateProcess(true); if ($preserveGlobalState !== null) { $_test->setPreserveGlobalState($preserveGlobalState); } } if ($backupSettings['backupGlobals'] !== null) { $_test->setBackupGlobals($backupSettings['backupGlobals']); } if ($backupSettings['backupStaticAttributes'] !== null) { $_test->setBackupStaticAttributes($backupSettings['backupStaticAttributes']); } $test->addTest($_test, $groups); } } } else { $test = $objectManager->create($class, $arguments); } if (!isset($test)) { throw new \PHPUnit_Framework_Exception('No valid test provided.'); } if ($test instanceof \PHPUnit_Framework_TestCase) { $test->setName($name); if ($runTestInSeparateProcess) { $test->setRunTestInSeparateProcess(true); if ($preserveGlobalState !== null) { $test->setPreserveGlobalState($preserveGlobalState); } } if ($backupSettings['backupGlobals'] !== null) { $test->setBackupGlobals($backupSettings['backupGlobals']); } if ($backupSettings['backupStaticAttributes'] !== null) { $test->setBackupStaticAttributes($backupSettings['backupStaticAttributes']); } } return $test; }
/** * @param ReflectionClass $class * @param ReflectionMethod $method */ protected function addTestMethod(ReflectionClass $class, ReflectionMethod $method) { if (!$this->isTestMethod($method)) { return; } $name = $method->getName(); if (!$method->isPublic()) { $this->addTest(self::warning(sprintf('Test method "%s" in test class "%s" is not public.', $name, $class->getName()))); return; } $test = self::createTest($class, $name); if ($test instanceof PHPUnit_Framework_TestCase || $test instanceof PHPUnit_Framework_TestSuite_DataProvider) { $test->setDependencies(PHPUnit_Util_Test::getDependencies($class->getName(), $name)); } $this->addTest($test, PHPUnit_Util_Test::getGroups($class->getName(), $name)); }
/** * @param string $className * @return PHPUnit_Framework_TestSuite */ public static function suite($className) { $suite = new PHPUnit_Framework_TestSuite(); $suite->setName($className); $class = new ReflectionClass($className); $classGroups = PHPUnit_Util_Test::getGroups($className); $staticProperties = $class->getStaticProperties(); // Create tests from Selenese/HTML files. if (isset($staticProperties['seleneseDirectory']) && is_dir($staticProperties['seleneseDirectory'])) { $files = array_merge(self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'), self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html')); // Create tests from Selenese/HTML files for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($files as $file) { $browserSuite->addTest(new $className($file, array(), '', $browser), $classGroups); } $suite->addTest($browserSuite); } } else { foreach ($files as $file) { $suite->addTest(new $className($file), $classGroups); } } } // Create tests from test methods for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($className, $name); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name); foreach ($data as $_dataName => $_data) { $dataSuite->addTest(new $className($name, $_data, $_dataName, $browser), $groups); } $browserSuite->addTest($dataSuite); } else { if ($data === FALSE) { $browserSuite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name))); } else { $browserSuite->addTest(new $className($name, array(), '', $browser), $groups); } } } } $suite->addTest($browserSuite); } } else { foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($className, $name); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name); foreach ($data as $_dataName => $_data) { $dataSuite->addTest(new $className($name, $_data, $_dataName), $groups); } $suite->addTest($dataSuite); } else { if ($data === FALSE) { $suite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name))); } else { $suite->addTest(new $className($name), $groups); } } } } } return $suite; }
public function groupsForTest(\PHPUnit_Framework_Test $test) { $groups = []; $filename = Descriptor::getTestFileName($test); if ($test instanceof TestInterface) { $groups = $test->getMetadata()->getGroups(); } if ($test instanceof Reported) { $info = $test->getReportFields(); if (isset($info['class'])) { $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups($info['class'], $info['name'])); } $filename = str_replace(['\\\\', '//'], ['\\', '/'], $info['file']); } if ($test instanceof \PHPUnit_Framework_TestCase) { $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false))); } foreach ($this->testsInGroups as $group => $tests) { foreach ($tests as $testPattern) { if ($filename == $testPattern) { $groups[] = $group; } if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) { $groups[] = $group; } } } return array_unique($groups); }
/** * @param string $className * @return PHPUnit_Framework_TestSuite */ public static function suite($className) { $suite = new PHPUnit_Framework_TestSuite(); $suite->setName($className); $class = new ReflectionClass($className); $classGroups = PHPUnit_Util_Test::getGroups($className); $staticProperties = $class->getStaticProperties(); if (defined('XLITE_TEST_BROWSERS_LIST')) { $staticProperties['browsers'] = unserialize(XLITE_TEST_BROWSERS_LIST); } // Leave only one browser in deployment mode if (defined('DEPLOYMENT_TEST') && !empty($staticProperties['browsers'])) { $_browsers = array(); foreach ($staticProperties['browsers'] as $key => $value) { $_browsers[$key] = $value; break; } $staticProperties['browsers'] = $_browsers; } // Create tests from Selenese/HTML files. if (isset($staticProperties['seleneseDirectory']) && is_dir($staticProperties['seleneseDirectory'])) { $files = array_merge(self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'), self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html')); // Create tests from Selenese/HTML files for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($files as $file) { $browserSuite->addTest(new $className($file, array(), '', $browser), $classGroups); } $suite->addTest($browserSuite); } } else { foreach ($files as $file) { $suite->addTest(new $className($file), $classGroups); } } } // Create tests from test methods for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { if (defined('NO_RESTORE')) { $browserSuite = new PHPUnit_Framework_TestSuite(); } else { $browserSuite = new XLite_Tests_TestSuite(); } $browserSuite->setName($className . ': ' . $browser['name']); foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($className, $name); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name); foreach ($data as $_dataName => $_data) { $dataSuite->addTest(new $className($name, $_data, $_dataName, $browser), $groups); } $browserSuite->addTest($dataSuite); } else { if ($data === FALSE) { $browserSuite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name))); } else { $browserSuite->addTest(new $className($name, array(), '', $browser), $groups); } } } } $suite->addTest($browserSuite); } } else { foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($className, $name); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name); foreach ($data as $_dataName => $_data) { $dataSuite->addTest(new $className($name, $_data, $_dataName), $groups); } $suite->addTest($dataSuite); } else { if ($data === FALSE) { $suite->addTest(new PHPUnit_Framework_Warning(sprintf('The data provider specified for %s::%s is invalid.', $className, $name))); } else { $suite->addTest(new $className($name), $groups); } } } } } return $suite; }
/** * @param string $className * @return PHPUnit_Framework_TestSuite */ public static function suite($className) { $suite = new PHPUnit_Extensions_SeleniumTestSuite(); $suite->setName($className); $class = new ReflectionClass($className); $classGroups = PHPUnit_Util_Test::getGroups($className); $staticProperties = $class->getStaticProperties(); // Create tests from Selenese/HTML files. if (isset($staticProperties['seleneseDirectory']) && is_dir($staticProperties['seleneseDirectory'])) { $files = array_merge(self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'), self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html')); // Create tests from Selenese/HTML files for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($files as $file) { self::addConfiguredTestTo($browserSuite, new $className($file, array(), '', $browser), $classGroups); } $suite->addTest($browserSuite); } } else { foreach ($files as $file) { self::addConfiguredTestTo($suite, new $className($file), $classGroups); } } } // Create tests from test methods for multiple browsers. if (!empty($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $test = PHPUnit_Framework_TestSuite::createTest($class, $name); if ($test instanceof PHPUnit_Framework_TestCase) { $test->setupSpecificBrowser($browser); $groups = PHPUnit_Util_Test::getGroups($className, $name); self::addConfiguredTestTo($browserSuite, $test, $groups); } else { $browserSuite->addTest($test); } } } $suite->addTest($browserSuite); } } else { foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $test = PHPUnit_Framework_TestSuite::createTest($class, $name); if ($test instanceof PHPUnit_Framework_TestCase) { $groups = PHPUnit_Util_Test::getGroups($className, $name); self::addConfiguredTestTo($suite, $test, $groups); } else { $suite->addTest($test); } } } } return $suite; }
/** * @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); $docComment = $method->getDocComment(); if (!$theClass->isInstantiable()) { return self::warning(sprintf('Cannot instantiate class "%s".', $className)); } // @expectedException ExceptionClass on TestCase::testMethod() // @expectedException ExceptionClass message on TestCase::testMethod() // @expectedException ExceptionClass message code on TestCase::testMethod() if (preg_match('(@expectedException\\s+([:.\\w]+)(?:[\\t ]+(\\S*))?(?:[\\t ]+(\\S*))?\\s*$)m', $docComment, $matches)) { $expectedException = $matches[1]; if (isset($matches[2])) { $expectedExceptionMessage = trim($matches[2]); } else { $expectedExceptionMessage = ''; } if (isset($matches[3])) { $expectedExceptionCode = (int) $matches[3]; } else { $expectedExceptionCode = 0; } } $constructor = $theClass->getConstructor(); 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); $groups = PHPUnit_Util_Test::getGroups($method, $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, $expectedExceptionMessage, $expectedExceptionCode); } $test->addTest($_test, $groups); } } else { $test = new $className(); } } } if ($test instanceof PHPUnit_Framework_TestCase) { $test->setName($name); if (isset($expectedException)) { $test->setExpectedException($expectedException, $expectedExceptionMessage, $expectedExceptionCode); } } return $test; }
/** * Registers and configures the deprecation handler. * * The following reporting modes are supported: * - use "weak" to hide the deprecation report but keep a global count; * - use "/some-regexp/" to stop the test suite whenever a deprecation * message matches the given regular expression; * - use a number to define the upper bound of allowed deprecations, * making the test suite fail whenever more notices are trigerred. * * @param int|string|false $mode The reporting mode. Defaults to not allowing any deprecations. */ public static function register($mode = 0) { if (self::$isRegistered) { return; } if (self::MODE_WEAK !== $mode && (!isset($mode[0]) || '/' !== $mode[0])) { $mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0; } $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 (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']; if (0 !== error_reporting()) { $group = 'unsilenced'; } elseif (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)) { $group = 'legacy'; } else { $group = 'remaining'; } if (isset($mode[0]) && '/' === $mode[0] && preg_match($mode, $msg)) { $e = new \Exception($msg); $r = new \ReflectionProperty($e, 'trace'); $r->setAccessible(true); $r->setValue($e, array_slice($trace, 1, $i)); echo "\n" . ucfirst($group) . ' deprecation triggered by ' . $class . '::' . $method . ':'; echo "\n" . $msg; echo "\nStack trace:"; echo "\n" . str_replace(' ' . getcwd() . DIRECTORY_SEPARATOR, ' ', $e->getTraceAsString()); echo "\n"; exit(1); } if ('legacy' !== $group && self::MODE_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); } } elseif (!isset($mode[0]) || '/' !== $mode[0]) { 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 (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) { exit(1); } }); } }
/** * @param string $className * @return PHPUnit_Framework_TestSuite * @access public */ public static function suite($className) { $suite = new PHPUnit_Framework_TestSuite(); $suite->setName($className); $class = new ReflectionClass($className); $classGroups = PHPUnit_Util_Test::getGroups($class); $staticProperties = $class->getStaticProperties(); // Create tests from Selenese/HTML files. if (isset($staticProperties['seleneseDirectory']) && is_dir($staticProperties['seleneseDirectory'])) { $files = new PHPUnit_Util_FilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($staticProperties['seleneseDirectory'])), '.htm'); // Create tests from Selenese/HTML files for multiple browsers. if (isset($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($files as $file) { $browserSuite->addTest(new $className((string) $file, array(), $browser)); } $suite->addTest($browserSuite, $classGroups); } } else { foreach ($files as $file) { $suite->addTest(new $className((string) $file), $classGroups); } } } // Create tests from test methods for multiple browsers. if (isset($staticProperties['browsers'])) { foreach ($staticProperties['browsers'] as $browser) { $browserSuite = new PHPUnit_Framework_TestSuite(); $browserSuite->setName($className . ': ' . $browser['name']); foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($method, $classGroups); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite($className . '::' . $name); foreach ($data as $_data) { $dataSuite->addTest(new $className($name, $_data, $browser), $groups); } $browserSuite->addTest($dataSuite); } else { $browserSuite->addTest(new $className($name, array(), $browser), $groups); } } } $suite->addTest($browserSuite); } } else { foreach ($class->getMethods() as $method) { if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) { $name = $method->getName(); $data = PHPUnit_Util_Test::getProvidedData($className, $name); $groups = PHPUnit_Util_Test::getGroups($method, $classGroups); // Test method with @dataProvider. if (is_array($data) || $data instanceof Iterator) { $dataSuite = new PHPUnit_Framework_TestSuite($className . '::' . $name); foreach ($data as $_data) { $dataSuite->addTest(new $className($name, $_data), $groups); } $suite->addTest($dataSuite); } else { $suite->addTest(new $className($name), $groups); } } } } return $suite; }
protected function _isBenchmarkGroup() { $groups = \PHPUnit_Util_Test::getGroups(get_class($this), $this->getName(false)); return in_array('benchmark', $groups); }
protected function createTestFromPhpUnitMethod(\ReflectionClass $class, \ReflectionMethod $method) { if (!\PHPUnit_Framework_TestSuite::isTestMethod($method) and strpos($method->name, 'should') !== 0) { return; } $test = \PHPUnit_Framework_TestSuite::createTest($class, $method->name); if ($test instanceof TestCase\Test) { $test->setBootstrap($this->settings['bootstrap']); $test->setDispatcher($this->dispatcher); $test->setGuyClass($this->settings['class_name']); $groups = \PHPUnit_Util_Test::getGroups($class->name, $method->name); $test->getScenario()->groups($groups); } else { if ($this->settings['bootstrap']) { require_once $this->settings['bootstrap']; } } return $test; }
public function groupsForTest(\PHPUnit_Framework_Test $test) { $groups = []; if ($test instanceof ScenarioDriven) { $groups = $test->getScenario()->getGroups(); } if ($test instanceof Reported) { $info = $test->getReportFields(); if (isset($info['class'])) { $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups($info['class'], $info['name'])); } $filename = $info['file']; } else { $groups = array_merge($groups, \PHPUnit_Util_Test::getGroups(get_class($test), $test->getName(false))); $filename = (new \ReflectionClass($test))->getFileName(); } foreach ($this->testsInGroups as $group => $tests) { foreach ($tests as $testPattern) { if ($filename == $testPattern) { $groups[] = $group; } if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) { $groups[] = $group; } } } return array_unique($groups); }
/** * @param ReflectionClass $theClass * @param string $name * * @return PHPUnit_Framework_Test * * @throws PHPUnit_Framework_Exception */ public static function createTest(ReflectionClass $theClass, $name) { $className = $theClass->getName(); if (!$theClass->isInstantiable()) { return self::warning(sprintf('Cannot instantiate class "%s".', $className)); } $backupSettings = PHPUnit_Util_Test::getBackupSettings($className, $name); $preserveGlobalState = PHPUnit_Util_Test::getPreserveGlobalStateSettings($className, $name); $runTestInSeparateProcess = PHPUnit_Util_Test::getProcessIsolationSettings($className, $name); $constructor = $theClass->getConstructor(); if ($constructor !== null) { $parameters = $constructor->getParameters(); // TestCase() or TestCase($name) if (count($parameters) < 2) { $test = new $className(); } else { try { $data = PHPUnit_Util_Test::getProvidedData($className, $name); } catch (PHPUnit_Framework_IncompleteTestError $e) { $message = sprintf('Test for %s::%s marked incomplete by data provider', $className, $name); $_message = $e->getMessage(); if (!empty($_message)) { $message .= "\n" . $_message; } $data = self::incompleteTest($className, $name, $message); } catch (PHPUnit_Framework_SkippedTestError $e) { $message = sprintf('Test for %s::%s skipped by data provider', $className, $name); $_message = $e->getMessage(); if (!empty($_message)) { $message .= "\n" . $_message; } $data = self::skipTest($className, $name, $message); } catch (Throwable $_t) { $t = $_t; } catch (Exception $_t) { $t = $_t; } if (isset($t)) { $message = sprintf('The data provider specified for %s::%s is invalid.', $className, $name); $_message = $t->getMessage(); if (!empty($_message)) { $message .= "\n" . $_message; } $data = self::warning($message); } // Test method with @dataProvider. if (isset($data)) { $test = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name); if (empty($data)) { $data = self::warning(sprintf('No tests found in suite "%s".', $test->getName())); } $groups = PHPUnit_Util_Test::getGroups($className, $name); if ($data instanceof PHPUnit_Framework_Warning || $data instanceof PHPUnit_Framework_SkippedTestCase || $data instanceof PHPUnit_Framework_IncompleteTestCase) { $test->addTest($data, $groups); } else { foreach ($data as $_dataName => $_data) { $_test = new $className($name, $_data, $_dataName); if ($runTestInSeparateProcess) { $_test->setRunTestInSeparateProcess(true); if ($preserveGlobalState !== null) { $_test->setPreserveGlobalState($preserveGlobalState); } } if ($backupSettings['backupGlobals'] !== null) { $_test->setBackupGlobals($backupSettings['backupGlobals']); } if ($backupSettings['backupStaticAttributes'] !== null) { $_test->setBackupStaticAttributes($backupSettings['backupStaticAttributes']); } $test->addTest($_test, $groups); } } } else { $test = new $className(); } } } if (!isset($test)) { throw new PHPUnit_Framework_Exception('No valid test provided.'); } if ($test instanceof PHPUnit_Framework_TestCase) { $test->setName($name); if ($runTestInSeparateProcess) { $test->setRunTestInSeparateProcess(true); if ($preserveGlobalState !== null) { $test->setPreserveGlobalState($preserveGlobalState); } } if ($backupSettings['backupGlobals'] !== null) { $test->setBackupGlobals($backupSettings['backupGlobals']); } if ($backupSettings['backupStaticAttributes'] !== null) { $test->setBackupStaticAttributes($backupSettings['backupStaticAttributes']); } } return $test; }