本文整理汇总了PHP中PHPUnit_Util_Test::parseTestMethodAnnotations方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::parseTestMethodAnnotations方法的具体用法?PHP PHPUnit_Util_Test::parseTestMethodAnnotations怎么用?PHP PHPUnit_Util_Test::parseTestMethodAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Util_Test
的用法示例。
在下文中一共展示了PHPUnit_Util_Test::parseTestMethodAnnotations方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
}
示例2: __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]);
}
}
示例3: 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");
}
}
}
示例4: 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);
}
}
}
示例5: startTestSuite
/**
* A test suite started.
*
* @param PHPUnit_Framework_TestSuite $suite
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
if ($this->firstLevelTestSuite === null) {
Mage::dispatchEvent('phpunit_suite_start_before', array('suite' => $suite, 'listener' => $this));
// Apply app substitution for tests
if ($this->getAppReflection()->hasMethod('applyTestScope')) {
$this->getAppReflection()->getMethod('applyTestScope')->invoke(null);
}
$this->firstLevelTestSuite = $suite;
Mage::dispatchEvent('phpunit_suite_start_after', array('suite' => $suite, 'listener' => $this));
}
if (EcomDev_Utils_Reflection::getRestrictedPropertyValue($suite, 'testCase')) {
Mage::dispatchEvent('phpunit_test_case_start_before', array('suite' => $suite, 'listener' => $this));
EcomDev_PHPUnit_Test_Case_Util::getFixture($suite->getName())->setScope(EcomDev_PHPUnit_Model_FixtureInterface::SCOPE_SHARED)->loadForClass($suite->getName());
$annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($suite->getName());
EcomDev_PHPUnit_Test_Case_Util::getFixture($suite->getName())->setOptions($annotations['class'])->apply();
Mage::dispatchEvent('phpunit_test_case_start_after', array('suite' => $suite, 'listener' => $this));
}
}
示例6: getAnnotations
/**
* Returns the annotations for this test.
*
* @return array
* @since Method available since Release 3.4.0
*/
public function getAnnotations()
{
return PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($this), $this->name);
}
示例7: startTest
/**
* A test started.
*
* @param PHPUnit_Framework_Test $test
*/
public function startTest(PHPUnit_Framework_Test $test)
{
if (!$this->isOfInterest($test)) {
return;
}
$class = get_class($test);
if ($this->testClass != $class) {
if ($this->testClass != '') {
$this->doEndClass();
}
$classAnnotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class);
if (isset($classAnnotations['class']['testdox'][0])) {
$this->currentTestClassPrettified = $classAnnotations['class']['testdox'][0];
} else {
$this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
}
$this->startClass($class);
$this->testClass = $class;
$this->tests = [];
}
$annotations = $test->getAnnotations();
if (isset($annotations['method']['testdox'][0])) {
$this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
} else {
$this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false));
}
$this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
}
示例8: _processItem
/**
* Handling file
*
* @param array $items
* @param array $rewrites
* @param string $filename
* @param string $location
* @param string $path
* @throws \Exception
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _processItem(&$items, &$rewrites, $filename, $location, $path)
{
$filename = str_replace('\\', '/', $filename);
$posTestsPath = strpos($filename, $path);
$posClassName = $posTestsPath + strlen($path);
$classPath = str_replace('.php', '', $filename);
$className = str_replace('/', '\\', substr($classPath, $posClassName));
$reflectionClass = new \ReflectionClass($className);
if ($reflectionClass->isAbstract()) {
return;
}
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations($className);
list(, $targetClassName) = explode($location . '/', $filename);
$targetClassName = str_replace('.php', '', $targetClassName);
$targetClassName = str_replace('/', '\\', $targetClassName);
if (isset($this->_checkList[$targetClassName])) {
$annotations['class']['rewrite'][0] = $this->_checkList[$targetClassName];
$this->_checkList[$targetClassName] = $className;
} else {
$this->_checkList[$targetClassName] = $className;
}
if (isset($annotations['class']['rewrite'])) {
$original = $annotations['class']['rewrite'][0];
if (isset($items[$original])) {
if (isset($items[$original]['fallback'])) {
$message = "Class '{$className}' rewrites class '{$original}'.\n";
$prevClass = key($items[$original]['fallback']);
$message .= "Class '{$prevClass}' also rewrites class '{$original}'";
throw new \Exception("Multiple rewrites detected:\n" . $message);
}
if (isset($items[$className])) {
$items[$original]['fallback'][$className] = $items[$className];
} else {
$items[$original]['fallback'][$className]['class'] = $className;
}
$rewrites[$className] =& $items[$original]['fallback'][$className];
if (isset($items[$className])) {
unset($items[$className]);
}
} elseif (isset($rewrites[$original])) {
if (isset($rewrites[$original]['fallback'])) {
$message = "Class '{$className}' rewrites class '{$original}'.\n";
$prevClass = key($rewrites[$original]['fallback']);
$message .= "Class '{$prevClass}' also rewrites class '{$original}'";
throw new \Exception("Multiple rewrites detected:\n" . $message);
}
if (isset($items[$className])) {
$rewrites[$original]['fallback'][$className] = $items[$className];
} else {
$rewrites[$original]['fallback'][$className]['class'] = $className;
}
$rewrites[$className] =& $rewrites[$original]['fallback'][$className];
if (isset($items[$className])) {
unset($items[$className]);
}
} else {
$items[$original]['class'] = $original;
if (isset($items[$className])) {
$items[$original]['fallback'][$className] = $items[$className];
} else {
$items[$original]['fallback'][$className]['class'] = $className;
}
$rewrites[$className] =& $items[$original]['fallback'][$className];
if (isset($items[$className])) {
unset($items[$className]);
}
}
} else {
$items[$className]['class'] = $className;
}
}
示例9: startTest
public function startTest(\PHPUnit_Framework_Test $test)
{
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::register(get_class($test));
ClockMock::withClockMock(true);
}
if (in_array('dns-sensitive', $groups, true)) {
DnsMock::register(get_class($test));
}
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($test), $test->getName(false));
if (isset($annotations['class']['expectedDeprecation'])) {
$test->getTestResultObject()->addError($test, new \PHPUnit_Framework_AssertionFailedError('`@expectedDeprecation` annotations are not allowed at the class level.'), 0);
}
if (isset($annotations['method']['expectedDeprecation'])) {
if (!in_array('legacy', $groups, true)) {
$test->getTestResultObject()->addError($test, new \PHPUnit_Framework_AssertionFailedError('Only tests with the `@group legacy` annotation can have `@expectedDeprecation`.'), 0);
}
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
}
}
}
示例10: startTest
/**
* A test started
*
* @param \PHPUnit_Framework_Test $test
* @return void
*/
public function startTest(\PHPUnit_Framework_Test $test)
{
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations(get_class($test), $test->getName());
$this->_processBeforeScope($annotations['method'], self::SCOPE_TEST);
}
示例11: isClassHasAnnotation
/**
* @param string $className
* @param string $annotationName
*
* @return bool
*/
private static function isClassHasAnnotation($className, $annotationName)
{
$annotations = \PHPUnit_Util_Test::parseTestMethodAnnotations($className);
return isset($annotations['class'][$annotationName]);
}
示例12: getAnnotationByNameFromClass
/**
* Retrieves annotation by its name from different sources (class, method) based on meta information
*
* @param string $className
* @param string $name annotation name
* @param array|string $sources
* @param string $testName test method name
* @return array
*/
public static function getAnnotationByNameFromClass($className, $name, $sources = 'class', $testName = '')
{
if (is_string($sources)) {
$sources = array($sources);
}
$allAnnotations = PHPUnit_Util_Test::parseTestMethodAnnotations($className, $testName);
$annotation = array();
// Iterate over sources for annotation retrieval
foreach ($sources as $source) {
if (isset($allAnnotations[$source][$name])) {
$annotation = array_merge($allAnnotations[$source][$name], $annotation);
}
}
return $annotation;
}
示例13: setUpBeforeClass
/**
* Initializes test environment for subset of tests
*
*/
public static function setUpBeforeClass()
{
self::getFixture()->setScope(Mage_Test_Model_Fixture_Interface::SCOPE_SHARED)->loadForClass(get_called_class());
$annotations = PHPUnit_Util_Test::parseTestMethodAnnotations(get_called_class());
self::getFixture()->setOptions($annotations['class'])->apply();
parent::setUpBeforeClass();
}
示例14: testParseTestMethodAnnotationsIncorporatesTraits
public function testParseTestMethodAnnotationsIncorporatesTraits()
{
$result = PHPUnit_Util_Test::parseTestMethodAnnotations(ParseTestMethodAnnotationsMock::class);
$this->assertArrayHasKey('class', $result);
$this->assertArrayHasKey('method', $result);
$this->assertArrayHasKey('theClassAnnotation', $result['class']);
$this->assertArrayHasKey('theTraitAnnotation', $result['class']);
}