本文整理汇总了PHP中phpunit_util::lastdbwrites方法的典型用法代码示例。如果您正苦于以下问题:PHP phpunit_util::lastdbwrites方法的具体用法?PHP phpunit_util::lastdbwrites怎么用?PHP phpunit_util::lastdbwrites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpunit_util
的用法示例。
在下文中一共展示了phpunit_util::lastdbwrites方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_database
/**
* Reset all database tables to default values.
* @static
* @return bool true if reset done, false if skipped
*/
public static function reset_database()
{
global $DB;
if (!is_null(self::$lastdbwrites) and self::$lastdbwrites == $DB->perf_get_writes()) {
return false;
}
if (!parent::reset_database()) {
return false;
}
self::$lastdbwrites = $DB->perf_get_writes();
return true;
}
示例2: reset_all_data
//.........这里部分代码省略.........
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
if ($detectchanges !== false) {
$warnings[] = 'Warning: max_execution_time was changed to ' . ini_get('max_execution_time');
}
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$_GET = array();
$_POST = array();
$_FILES = array();
$_REQUEST = array();
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
$SESSION = new stdClass();
$_SESSION['SESSION'] =& $SESSION;
// set fresh new not-logged-in user
$user = new stdClass();
$user->id = 0;
$user->mnethostid = $CFG->mnet_localhost_id;
\core\session\manager::set_user($user);
// reset all static caches
\core\event\manager::phpunit_reset();
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches(true);
reset_text_filters_cache(true);
events_get_handlers('reset');
core_text::reset_caches();
get_message_processors(false, true);
filter_manager::reset_caches();
//TODO MDL-25290: add more resets here and probably refactor them to new core function
// Reset course and module caches.
if (class_exists('format_base')) {
// If file containing class is not loaded, there is no cache there anyway.
format_base::reset_course_cache(0);
}
get_fast_modinfo(0, 0, true);
// Reset other singletons.
if (class_exists('core_plugin_manager')) {
core_plugin_manager::reset_caches(true);
}
if (class_exists('\\core\\update\\checker')) {
\core\update\checker::reset_caches(true);
}
if (class_exists('\\core\\update\\deployer')) {
\core\update\deployer::reset_caches(true);
}
// purge dataroot directory
self::reset_dataroot();
// restore original config once more in case resetting of caches changed CFG
$CFG = self::get_global_backup('CFG');
// inform data generator
self::get_data_generator()->reset();
// fix PHP settings
error_reporting($CFG->debug);
// verify db writes just in case something goes wrong in reset
if (self::$lastdbwrites != $DB->perf_get_writes()) {
error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
self::$lastdbwrites = $DB->perf_get_writes();
}
if ($warnings) {
$warnings = implode("\n", $warnings);
trigger_error($warnings, E_USER_WARNING);
}
}
示例3: reset_all_data
/**
* Reset contents of all database tables to initial values, reset caches, etc.
*
* Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
*
* @static
* @param bool $logchanges log changes in global state and database in error log
* @return void
*/
public static function reset_all_data($logchanges = false)
{
global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION, $GROUPLIB_CACHE;
// reset global $DB in case somebody mocked it
$DB = self::get_global_backup('DB');
if ($DB->is_transaction_started()) {
// we can not reset inside transaction
$DB->force_transaction_rollback();
}
$resetdb = self::reset_database();
$warnings = array();
if ($logchanges) {
if ($resetdb) {
$warnings[] = 'Warning: unexpected database modification, resetting DB state';
}
$oldcfg = self::get_global_backup('CFG');
$oldsite = self::get_global_backup('SITE');
foreach ($CFG as $k => $v) {
if (!property_exists($oldcfg, $k)) {
$warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
} else {
if ($oldcfg->{$k} !== $CFG->{$k}) {
$warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
}
}
unset($oldcfg->{$k});
}
if ($oldcfg) {
foreach ($oldcfg as $k => $v) {
$warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
$SESSION = new stdClass();
$_SESSION['SESSION'] =& $SESSION;
// set fresh new not-logged-in user
$user = new stdClass();
$user->id = 0;
$user->mnethostid = $CFG->mnet_localhost_id;
session_set_user($user);
// reset all static caches
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches();
events_get_handlers('reset');
textlib::reset_caches();
if (class_exists('repository')) {
repository::reset_caches();
}
$GROUPLIB_CACHE = null;
//TODO MDL-25290: add more resets here and probably refactor them to new core function
// purge dataroot directory
self::reset_dataroot();
// restore original config once more in case resetting of caches changed CFG
$CFG = self::get_global_backup('CFG');
// inform data generator
self::get_data_generator()->reset();
// fix PHP settings
error_reporting($CFG->debug);
// verify db writes just in case something goes wrong in reset
if (self::$lastdbwrites != $DB->perf_get_writes()) {
error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
self::$lastdbwrites = $DB->perf_get_writes();
}
if ($warnings) {
$warnings = implode("\n", $warnings);
trigger_error($warnings, E_USER_WARNING);
}
}
示例4: runBare
/**
* Runs the bare test sequence.
* @return void
*/
final public 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.
phpunit_util::display_debugging_messages();
phpunit_util::reset_debugging();
} 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');
}
}
}
示例5: reset_all_data
//.........这里部分代码省略.........
$warnings[] = 'Warning: unexpected new $CFG->'.$k.' value';
} else if ($oldcfg->$k !== $CFG->$k) {
$warnings[] = 'Warning: unexpected change of $CFG->'.$k.' value';
}
unset($oldcfg->$k);
}
if ($oldcfg) {
foreach($oldcfg as $k=>$v) {
$warnings[] = 'Warning: unexpected removal of $CFG->'.$k;
}
}
if ($USER->id != 0) {
$warnings[] = 'Warning: unexpected change of $USER';
}
if ($COURSE->id != $oldsite->id) {
$warnings[] = 'Warning: unexpected change of $COURSE';
}
}
if (ini_get('max_execution_time') != 0) {
// This is special warning for all resets because we do not want any
// libraries to mess with timeouts unintentionally.
// Our PHPUnit integration is not supposed to change it either.
// TODO: MDL-38912 uncomment and fix all + somehow resolve timeouts in failed tests.
//$warnings[] = 'Warning: max_execution_time was changed.';
set_time_limit(0);
}
// restore original globals
$_SERVER = self::get_global_backup('_SERVER');
$CFG = self::get_global_backup('CFG');
$SITE = self::get_global_backup('SITE');
$COURSE = $SITE;
// reinitialise following globals
$OUTPUT = new bootstrap_renderer();
$PAGE = new moodle_page();
$FULLME = null;
$ME = null;
$SCRIPT = null;
$SESSION = new stdClass();
$_SESSION['SESSION'] =& $SESSION;
// set fresh new not-logged-in user
$user = new stdClass();
$user->id = 0;
$user->mnethostid = $CFG->mnet_localhost_id;
session_set_user($user);
// reset all static caches
accesslib_clear_all_caches(true);
get_string_manager()->reset_caches();
events_get_handlers('reset');
textlib::reset_caches();
if (class_exists('repository')) {
repository::reset_caches();
}
$GROUPLIB_CACHE = null;
//TODO MDL-25290: add more resets here and probably refactor them to new core function
// Reset course and module caches.
$reset = 'reset';
get_fast_modinfo($reset);
// Reset other singletons.
if (class_exists('plugin_manager')) {
plugin_manager::reset_caches(true);
}
if (class_exists('available_update_checker')) {
available_update_checker::reset_caches(true);
}
// purge dataroot directory
self::reset_dataroot();
// restore original config once more in case resetting of caches changed CFG
$CFG = self::get_global_backup('CFG');
// inform data generator
self::get_data_generator()->reset();
// fix PHP settings
error_reporting($CFG->debug);
// verify db writes just in case something goes wrong in reset
if (self::$lastdbwrites != $DB->perf_get_writes()) {
error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
self::$lastdbwrites = $DB->perf_get_writes();
}
if ($warnings) {
$warnings = implode("\n", $warnings);
trigger_error($warnings, E_USER_WARNING);
}
}