本文整理汇总了PHP中PHPUnit_Util_Test类的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test类的具体用法?PHP PHPUnit_Util_Test怎么用?PHP PHPUnit_Util_Test使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPUnit_Util_Test类的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: tearDown
public function tearDown()
{
$doc = \PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($this), $this->getName(false));
if (isset($doc['method']['memcheck'])) {
$memory = 0;
// allocate variable
$zero = 0;
// allocate zero value
$r = array(0, 0, 0);
// allocate result
for ($i = 0; $i < 3; $i++) {
$memory = memory_get_usage(0);
$this->data = [];
$this->runTest();
unset($this->data);
ION::dispatch(ION::LOOP_NONBLOCK | ION::LOOP_ONCE);
// ammm, i think libevent free unpinned data-chunks in the loop (todo: analyze it)
$r[$i] = memory_get_usage(0) - $memory;
if ($r[$i] < 0) {
// free memory possible
$r[$i] = $zero;
// this hack remove 8-bytes-memory-leak
}
}
if (array_sum($r)) {
$this->fail("Memory leak detected: +" . implode(" B, +", $r) . " B");
}
}
}
示例3: __construct
/**
* Constructor adds test groups defined on global level
* and adds additional logic for test names retrieval
*
* @see PHPUnit_Framework_TestSuite::__construct()
*/
public function __construct($theClass = '', $groups = array())
{
if (!$theClass instanceof ReflectionClass) {
$theClass = EcomDev_Utils_Reflection::getReflection($theClass);
}
// Check annotations for test case name
$annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($theClass->getName());
if (isset($annotations['name'])) {
$this->suiteName = $annotations['name'];
}
// Creates all test instances
parent::__construct($theClass);
// Just sort-out them by our internal groups
foreach ($groups as $group) {
$this->groups[$group] = $this->tests();
}
foreach ($this->tests() as $test) {
if ($test instanceof PHPUnit_Framework_TestSuite) {
/* @todo
* Post an issue into PHPUnit bugtracker for
* impossibility for specifying group by parent test case
* Because it is a very dirty hack :(
**/
$testGroups = array();
foreach ($groups as $group) {
$testGroups[$group] = $test->tests();
}
EcomDev_Utils_Reflection::setRestrictedPropertyValue($test, 'groups', $testGroups);
}
}
// Remove un grouped tests group, if it exists
if (isset($this->groups[self::NO_GROUP_KEYWORD])) {
unset($this->groups[self::NO_GROUP_KEYWORD]);
}
}
示例4: setUp
/**
* Start and clear caching proxy server if test is annotated with @clearCache
*/
protected function setUp()
{
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($this), $this->getName());
if (isset($annotations['class']['clearCache']) || isset($annotations['method']['clearCache'])) {
$this->getProxy()->clear();
}
}
示例5: beforeClass
public function beforeClass(SuiteEvent $e)
{
foreach ($e->getSuite()->tests() as $test) {
/** @var $test \PHPUnit_Framework_Test * */
$testClass = get_class($test);
$this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
}
$this->runHooks('beforeClass');
}
示例6: executeAfterMethods
protected function executeAfterMethods($testMethod, $I)
{
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($this->testClassInstance), $testMethod);
if (!empty($annotations['method']['after'])) {
foreach ($annotations['method']['after'] as $m) {
$this->executeContextMethod(trim($m), $I);
}
}
}
示例7: 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);
}
}
}
示例8: makeSuite
protected static function makeSuite($className, $group = null)
{
$suite = new PHPUnit_Framework_TestSuite();
$suite->setName($className);
$class = new ReflectionClass($className);
$parser = new Parser();
$parser->startExternalParse(Title::newMainPage(), new ParserOptions(), Parser::OT_HTML, true);
foreach (self::$engineConfigurations as $engineName => $opts) {
if ($group !== null && $group !== $engineName) {
continue;
}
try {
$engineClass = "Scribunto_{$engineName}Engine";
$engine = new $engineClass(self::$engineConfigurations[$engineName] + array('parser' => $parser));
$engine->setTitle($parser->getTitle());
$engine->getInterpreter();
} catch (Scribunto_LuaInterpreterNotFoundError $e) {
$suite->addTest(new $className('skipUnavailable', array(), '', $engineName), 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::isPublicTestMethod($method)) {
$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;
}
示例9: enhancePhpunitTest
protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
{
$className = get_class($test);
$methodName = $test->getName(false);
$dependencies = \PHPUnit_Util_Test::getDependencies($className, $methodName);
$test->setDependencies($dependencies);
if ($test instanceof TestCaseFormat) {
$test->getMetadata()->setDependencies($dependencies);
$test->getMetadata()->setEnv(Annotation::forMethod($test, $methodName)->fetchAll('env'));
}
}
示例10: beforeClass
public function beforeClass(SuiteEvent $e)
{
foreach ($e->getSuite()->tests() as $test) {
/** @var $test \PHPUnit_Framework_Test * */
if ($test instanceof \PHPUnit_Framework_TestSuite_DataProvider) {
$potentialTestClass = strstr($test->getName(), '::', true);
$this->hooks[$potentialTestClass] = \PHPUnit_Util_Test::getHookMethods($potentialTestClass);
}
$testClass = get_class($test);
$this->hooks[$testClass] = \PHPUnit_Util_Test::getHookMethods($testClass);
}
$this->runHooks('beforeClass');
}
示例11: accept
/**
* @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);
}
示例12: enhancePhpunitTest
protected function enhancePhpunitTest(\PHPUnit_Framework_TestCase $test)
{
$className = get_class($test);
$methodName = $test->getName(false);
$dependencies = \PHPUnit_Util_Test::getDependencies($className, $methodName);
$test->setDependencies($dependencies);
if ($test instanceof UnitFormat) {
$feature = $test->getName();
$feature = preg_replace('/([A-Z]+)([A-Z][a-z])/', '\\1 \\2', $feature);
$feature = preg_replace('/([a-z\\d])([A-Z])/', '\\1 \\2', $feature);
$test->getMetadata()->setFeature(strtolower($feature));
$test->getMetadata()->setDependencies($dependencies);
$test->getMetadata()->setEnv(Annotation::forMethod($test, $methodName)->fetchAll('env'));
}
}
示例13: endTest
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);
}
}
示例14: codeCoverageEnd
public function codeCoverageEnd($status, $time)
{
$codeCoverage = $this->getTestResultObject()->getCodeCoverage();
if (!$codeCoverage) {
return;
}
$linesToBeCovered = \PHPUnit_Util_Test::getLinesToBeCovered(get_class($this->testClassInstance), 'test');
$linesToBeUsed = \PHPUnit_Util_Test::getLinesToBeUsed(get_class($this->testClassInstance), 'test');
try {
$codeCoverage->stop(true, $linesToBeCovered, $linesToBeUsed);
} catch (\PHP_CodeCoverage_Exception $cce) {
if ($status === \Codeception\Test\Test::STATUS_OK) {
$this->getTestResultObject()->addError($this, $cce, $time);
}
}
}
示例15: __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');
}