mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-46193 phpunit: Use random starting value on initialization.
This commit is contained in:
parent
4de51c25ae
commit
529495f7ce
@ -461,8 +461,13 @@ class phpunit_util extends testing_util {
|
||||
$suites .= $suite;
|
||||
}
|
||||
}
|
||||
// Start a sequence between 100000 and 199000 to ensure each call to init produces
|
||||
// different ids in the database. This reduces the risk that hard coded values will
|
||||
// end up being placed in phpunit or behat test code.
|
||||
$sequencestart = 100000 + mt_rand(0, 99) * 1000;
|
||||
|
||||
$data = preg_replace('|<!--@plugin_suites_start@-->.*<!--@plugin_suites_end@-->|s', $suites, $data, 1);
|
||||
$data = preg_replace('|<!--@PHPUNIT_SEQUENCE_START@-->|s', $sequencestart, $data, 1);
|
||||
|
||||
$result = false;
|
||||
if (is_writable($CFG->dirroot)) {
|
||||
|
@ -458,7 +458,11 @@ abstract class testing_util {
|
||||
// To reduce the chance of the coding error, we start sequences at different values where possible.
|
||||
// In a attempt to avoid tables with existing id's we start at a high number.
|
||||
// Reset the value each time all database sequences are reset.
|
||||
self::$sequencenextstartingid = 100000;
|
||||
if (defined('PHPUNIT_SEQUENCE_START')) {
|
||||
self::$sequencenextstartingid = PHPUNIT_SEQUENCE_START;
|
||||
} else {
|
||||
self::$sequencenextstartingid = 100000;
|
||||
}
|
||||
|
||||
$dbfamily = $DB->get_dbfamily();
|
||||
if ($dbfamily === 'postgres') {
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
<php>
|
||||
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests-->
|
||||
<const name="PHPUNIT_SEQUENCE_START" value="<!--@PHPUNIT_SEQUENCE_START@-->"/>
|
||||
|
||||
<!--Following constants instruct tests to fetch external test files from alternative location or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server-->
|
||||
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/> uncomment and alter to fetch external test files from alternative location-->
|
||||
|
Loading…
x
Reference in New Issue
Block a user