Esempio n. 1
0
 /**
  * Runs the bare test sequence and log any changes in global state or database.
  * @return void
  */
 public final function runBare()
 {
     global $DB;
     try {
         parent::runBare();
     } catch (Exception $e) {
         // cleanup after failed expectation
         phpunit_util::reset_all_data();
         throw $e;
     }
     if ($DB->is_transaction_started()) {
         phpunit_util::reset_all_data();
         throw new coding_exception('basic_testcase ' . $this->getName() . ' is not supposed to use database transactions!');
     }
     phpunit_util::reset_all_data(true);
 }
Esempio n. 2
0
 /**
  * Runs the bare test sequence and log any changes in global state or database.
  * @return void
  */
 public final function runBare()
 {
     global $DB;
     try {
         parent::runBare();
     } 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
         phpunit_util::reset_all_data();
         throw $e;
     }
     if ($DB->is_transaction_started()) {
         phpunit_util::reset_all_data();
         throw new coding_exception('basic_testcase ' . $this->getName() . ' is not supposed to use database transactions!');
     }
     phpunit_util::reset_all_data(true);
 }
 /**
  * Runs the bare test sequence.
  * @return void
  */
 public function runBare()
 {
     try {
         parent::runBare();
     } catch (Exception $e) {
         if ($this->tdb->is_transaction_started()) {
             $this->tdb->force_transaction_rollback();
         }
         $this->tearDown();
         throw $e;
     }
 }
Esempio n. 4
0
 /**
  * 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();
         phpunit_util::reset_debugging();
         if ($debugerror) {
             trigger_error('Unenxpected debugging() call detected.', E_USER_NOTICE);
         }
     } 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(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) {
                     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');
         }
     }
 }
 /**
  * Runs the bare test sequence.
  * @return void
  */
 public function runBare()
 {
     try {
         parent::runBare();
     } 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)) {
         if ($this->tdb->is_transaction_started()) {
             $this->tdb->force_transaction_rollback();
         }
         $this->tearDown();
         throw $e;
     }
 }