parseTestMethodAnnotations() 공개 정적인 메소드

public static parseTestMethodAnnotations ( string $className, string $methodName = '' ) : array
$className string
$methodName string
리턴 array
예제 #1
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
파일: Cest.php 프로젝트: corcre/elabftw
 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * 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
0
 /**
  * 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
0
 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']);
 }