当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPUnit_Util_Test::getBackupSettings方法代码示例

本文整理汇总了PHP中PHPUnit_Util_Test::getBackupSettings方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Util_Test::getBackupSettings方法的具体用法?PHP PHPUnit_Util_Test::getBackupSettings怎么用?PHP PHPUnit_Util_Test::getBackupSettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPUnit_Util_Test的用法示例。


在下文中一共展示了PHPUnit_Util_Test::getBackupSettings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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();
     if (!$theClass->isInstantiable()) {
         return self::warning(sprintf('Cannot instantiate class "%s".', $className));
     }
     $classDocComment = $theClass->getDocComment();
     $method = new ReflectionMethod($className, $name);
     $methodDocComment = $method->getDocComment();
     $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 {
             $data = PHPUnit_Util_Test::getProvidedData($className, $name);
             $groups = PHPUnit_Util_Test::getGroups($className, $name);
             if (is_array($data) || $data instanceof Iterator) {
                 $test = new PHPUnit_Framework_TestSuite_DataProvider($className . '::' . $name);
                 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 ($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;
 }
开发者ID:arjenschol,项目名称:phpunit,代码行数:67,代码来源:TestSuite.php

示例2: createTest

 /**
  * @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']);
         }
//.........这里部分代码省略.........
开发者ID:441420776,项目名称:phpunit,代码行数:101,代码来源:TestSuite.php

示例3: createTest

 /**
  * 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;
 }
开发者ID:Mohitsahu123,项目名称:mtf,代码行数:85,代码来源:InjectableMethod.php


注:本文中的PHPUnit_Util_Test::getBackupSettings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。