本文整理汇总了PHP中phpunit_util::get_version_hash方法的典型用法代码示例。如果您正苦于以下问题:PHP phpunit_util::get_version_hash方法的具体用法?PHP phpunit_util::get_version_hash怎么用?PHP phpunit_util::get_version_hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpunit_util
的用法示例。
在下文中一共展示了phpunit_util::get_version_hash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install_site
/**
* Perform a fresh test site installation
*
* Note: To be used from CLI scripts only.
*
* @static
* @return void may terminate execution with exit code
*/
public static function install_site()
{
global $DB, $CFG;
if (!self::is_test_site()) {
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGERROR, 'Can not install on non-test site!!');
}
if ($DB->get_tables()) {
list($errorcode, $message) = phpunit_util::testing_ready_problem();
if ($errorcode) {
phpunit_bootstrap_error(PHPUNIT_EXITCODE_REINSTALL, 'Database tables already present, Moodle PHPUnit test environment can not be initialised');
} else {
phpunit_bootstrap_error(0, 'Moodle PHPUnit test environment is already initialised');
}
}
$options = array();
$options['adminpass'] = 'admin';
$options['shortname'] = 'phpunit';
$options['fullname'] = 'PHPUnit test site';
install_cli_database($options, false);
// install timezone info
$timezones = get_records_csv($CFG->libdir . '/timezone.txt', 'timezone');
update_timezone_records($timezones);
// add test db flag
$hash = phpunit_util::get_version_hash();
set_config('phpunittest', $hash);
// store data for all tables
$data = array();
$structure = array();
$tables = $DB->get_tables();
foreach ($tables as $table) {
$columns = $DB->get_columns($table);
$structure[$table] = $columns;
if (isset($columns['id']) and $columns['id']->auto_increment) {
$data[$table] = $DB->get_records($table, array(), 'id ASC');
} else {
// there should not be many of these
$data[$table] = $DB->get_records($table, array());
}
}
$data = serialize($data);
file_put_contents("{$CFG->dataroot}/phpunit/tabledata.ser", $data);
phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/tabledata.ser");
$structure = serialize($structure);
file_put_contents("{$CFG->dataroot}/phpunit/tablestructure.ser", $structure);
phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/tablestructure.ser");
// hash all plugin versions - helps with very fast detection of db structure changes
file_put_contents("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
}
示例2: install_site
/**
* Perform a fresh test site installation
*
* Note: To be used from CLI scripts only.
*
* @static
* @return void may terminate execution with exit code
*/
public static function install_site()
{
global $DB, $CFG;
if (!self::is_test_site()) {
cli_error('Can not install non-test sites!!', 131);
}
if ($DB->get_tables()) {
cli_error('Database tables already installed, drop the site first.', 133);
}
$options = array();
$options['adminpass'] = 'admin';
// removed later
$options['shortname'] = 'phpunit';
$options['fullname'] = 'PHPUnit test site';
install_cli_database($options, false);
// just in case remove admin password so that normal login is not possible
$DB->set_field('user', 'password', 'not cached', array('username' => 'admin'));
// add test db flag
set_config('phpunittest', 'phpunittest');
// store data for all tables
$data = array();
$tables = $DB->get_tables();
foreach ($tables as $table) {
$data[$table] = $DB->get_records($table, array());
}
$data = serialize($data);
@unlink("{$CFG->dataroot}/phpunit/tabledata.ser");
file_put_contents("{$CFG->dataroot}/phpunit/tabledata.ser", $data);
// hash all plugin versions - helps with very fast detection of db structure changes
$hash = phpunit_util::get_version_hash();
@unlink("{$CFG->dataroot}/phpunit/versionshash.txt");
file_put_contents("{$CFG->dataroot}/phpunit/versionshash.txt", $hash);
}