MDL-46193 phpunit: Use random starting value on initialization.

This commit is contained in:
Russell Smith 2014-06-24 19:25:51 +10:00
parent 4de51c25ae
commit 529495f7ce
3 changed files with 11 additions and 1 deletions

View File

@ -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)) {

View File

@ -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') {

View File

@ -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-->