From 529495f7ce730657375e0f803b590d183b3d11b3 Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Tue, 24 Jun 2014 19:25:51 +1000 Subject: [PATCH] MDL-46193 phpunit: Use random starting value on initialization. --- lib/phpunit/classes/util.php | 5 +++++ lib/testing/classes/util.php | 6 +++++- phpunit.xml.dist | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 393cc30bba8..7df1a891a21 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -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('|.*|s', $suites, $data, 1); + $data = preg_replace('||s', $sequencestart, $data, 1); $result = false; if (is_writable($CFG->dirroot)) { diff --git a/lib/testing/classes/util.php b/lib/testing/classes/util.php index 56bf482f301..1cc7e52b4c0 100644 --- a/lib/testing/classes/util.php +++ b/lib/testing/classes/util.php @@ -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') { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 8e680eb887f..853b4eef932 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -20,6 +20,7 @@ +