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


PHP phpunit_util::reset_all_database_sequences方法代码示例

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


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

示例1: runBare

 /**
  * Runs the bare test sequence.
  * @return void
  */
 public final function runBare()
 {
     global $DB;
     if (phpunit_util::$lastdbwrites != $DB->perf_get_writes()) {
         // this happens when previous test does not reset, we can not use transactions
         $this->testdbtransaction = null;
     } else {
         if ($DB->get_dbfamily() === 'postgres' or $DB->get_dbfamily() === 'mssql') {
             // database must allow rollback of DDL, so no mysql here
             $this->testdbtransaction = $DB->start_delegated_transaction();
         }
     }
     try {
         parent::runBare();
         // set DB reference in case somebody mocked it in test
         $DB = phpunit_util::get_global_backup('DB');
     } catch (Exception $e) {
         // cleanup after failed expectation
         phpunit_util::reset_all_data();
         throw $e;
     }
     if (!$this->testdbtransaction or $this->testdbtransaction->is_disposed()) {
         $this->testdbtransaction = null;
     }
     if ($this->resetAfterTest === true) {
         if ($this->testdbtransaction) {
             $DB->force_transaction_rollback();
             phpunit_util::reset_all_database_sequences();
             phpunit_util::$lastdbwrites = $DB->perf_get_writes();
             // no db reset necessary
         }
         phpunit_util::reset_all_data();
     } else {
         if ($this->resetAfterTest === false) {
             if ($this->testdbtransaction) {
                 $this->testdbtransaction->allow_commit();
             }
             // keep all data untouched for other tests
         } else {
             // reset but log what changed
             if ($this->testdbtransaction) {
                 try {
                     $this->testdbtransaction->allow_commit();
                 } catch (dml_transaction_exception $e) {
                     phpunit_util::reset_all_data();
                     throw new coding_exception('Invalid transaction state detected in test ' . $this->getName());
                 }
             }
             phpunit_util::reset_all_data(true);
         }
     }
     // make sure test did not forget to close transaction
     if ($DB->is_transaction_started()) {
         phpunit_util::reset_all_data();
         if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
             throw new coding_exception('Test ' . $this->getName() . ' did not close database transaction');
         }
     }
 }
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:63,代码来源:advanced_testcase.php

示例2: runBare

 /**
  * Runs the bare test sequence.
  * @return void
  */
 public final function runBare()
 {
     global $DB;
     if (phpunit_util::$lastdbwrites != $DB->perf_get_writes()) {
         // this happens when previous test does not reset, we can not use transactions
         $this->testdbtransaction = null;
     } else {
         if ($DB->get_dbfamily() === 'postgres' or $DB->get_dbfamily() === 'mssql') {
             // database must allow rollback of DDL, so no mysql here
             $this->testdbtransaction = $DB->start_delegated_transaction();
         }
     }
     try {
         $this->setCurrentTimeStart();
         parent::runBare();
         // set DB reference in case somebody mocked it in test
         $DB = phpunit_util::get_global_backup('DB');
         // Deal with any debugging messages.
         $debugerror = phpunit_util::display_debugging_messages();
         $this->resetDebugging();
         if ($debugerror) {
             trigger_error('Unexpected debugging() call detected.', E_USER_NOTICE);
         }
     } catch (Exception $ex) {
         $e = $ex;
     } catch (Throwable $ex) {
         // Engine errors in PHP7 throw exceptions of type Throwable (this "catch" will be ignored in PHP5).
         $e = $ex;
     }
     if (isset($e)) {
         // cleanup after failed expectation
         self::resetAllData();
         throw $e;
     }
     if (!$this->testdbtransaction or $this->testdbtransaction->is_disposed()) {
         $this->testdbtransaction = null;
     }
     if ($this->resetAfterTest === true) {
         if ($this->testdbtransaction) {
             $DB->force_transaction_rollback();
             phpunit_util::reset_all_database_sequences();
             phpunit_util::$lastdbwrites = $DB->perf_get_writes();
             // no db reset necessary
         }
         self::resetAllData(null);
     } else {
         if ($this->resetAfterTest === false) {
             if ($this->testdbtransaction) {
                 $this->testdbtransaction->allow_commit();
             }
             // keep all data untouched for other tests
         } else {
             // reset but log what changed
             if ($this->testdbtransaction) {
                 try {
                     $this->testdbtransaction->allow_commit();
                 } catch (dml_transaction_exception $e) {
                     self::resetAllData();
                     throw new coding_exception('Invalid transaction state detected in test ' . $this->getName());
                 }
             }
             self::resetAllData(true);
         }
     }
     // make sure test did not forget to close transaction
     if ($DB->is_transaction_started()) {
         self::resetAllData();
         if ($this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED or $this->getStatus() == PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE) {
             throw new coding_exception('Test ' . $this->getName() . ' did not close database transaction');
         }
     }
 }
开发者ID:aleph-n,项目名称:lms.aaenl,代码行数:76,代码来源:advanced_testcase.php


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