jenkins-bot has submitted this change and it was merged.
Change subject: tests: Clean up use of mt_rand()
......................................................................
tests: Clean up use of mt_rand()
* ApiQueryTest: One random is enough.
* FileBackendTest: More consistent and idiomatic via wfRandomString()
* MigrateFileRepoLayoutTest: Use getNewTempDirectory(). Similar to
what FileBackendTest used already.
* UploadFromUrlTestSuite: Use getNewTempDirectory().
Change-Id: I772de2134be41506d8ed08367be8c18f354bfc72
---
M includes/GlobalFunctions.php
M tests/phpunit/includes/api/query/ApiQueryTest.php
M tests/phpunit/includes/filebackend/FileBackendTest.php
M tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
M tests/phpunit/suites/UploadFromUrlTestSuite.php
5 files changed, 16 insertions(+), 20 deletions(-)
Approvals:
Aaron Schulz: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 43b936b..4a3fceb 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -374,20 +374,22 @@
* not likely to give duplicate values for any realistic
* number of articles.
*
+ * @note This is designed for use in relation to Special:RandomPage
+ * and the page_random database field.
+ *
* @return string
*/
function wfRandom() {
- # The maximum random value is "only" 2^31-1, so get two random
- # values to reduce the chance of dupes
+ // The maximum random value is "only" 2^31-1, so get two random
+ // values to reduce the chance of dupes
$max = mt_getrandmax() + 1;
$rand = number_format( ( mt_rand() * $max + mt_rand() ) / $max / $max,
12, '.', '' );
-
return $rand;
}
/**
- * Get a random string containing a number of pseudo-random hex
- * characters.
+ * Get a random string containing a number of pseudo-random hex characters.
+ *
* @note This is not secure, if you are trying to generate some sort
* of token please use MWCryptRand instead.
*
diff --git a/tests/phpunit/includes/api/query/ApiQueryTest.php
b/tests/phpunit/includes/api/query/ApiQueryTest.php
index 61b992b..eb1ad26 100644
--- a/tests/phpunit/includes/api/query/ApiQueryTest.php
+++ b/tests/phpunit/includes/api/query/ApiQueryTest.php
@@ -61,7 +61,7 @@
public function testTitlesAreRejectedIfInvalid() {
$title = false;
while ( !$title || Title::newFromText( $title )->exists() ) {
- $title = md5( mt_rand( 0, 10000 ) + rand( 0, 999000 ) );
+ $title = md5( mt_rand( 0, 100000 ) );
}
$data = $this->doApiRequest( array(
diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php
b/tests/phpunit/includes/filebackend/FileBackendTest.php
index 9bef8e0..e115d17 100644
--- a/tests/phpunit/includes/filebackend/FileBackendTest.php
+++ b/tests/phpunit/includes/filebackend/FileBackendTest.php
@@ -18,7 +18,6 @@
protected function setUp() {
global $wgFileBackends;
parent::setUp();
- $uniqueId = time() . '-' . mt_rand();
$tmpDir = $this->getNewTempDirectory();
if ( $this->getCliArg( 'use-filebackend' ) ) {
if ( self::$backendToUse ) {
@@ -58,7 +57,7 @@
'name' => 'localtesting',
'lockManager' => LockManagerGroup::singleton()->get(
'fsLockManager' ),
'parallelize' => 'implicit',
- 'wikiId' => wfWikiId() . $uniqueId,
+ 'wikiId' => wfWikiId() . wfRandomString(),
'backends' => array(
array(
'name' => 'localmultitesting1',
diff --git a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
index c839bc4..ee0cf2d 100644
--- a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
+++ b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
@@ -11,7 +11,7 @@
$filename = 'Foo.png';
- $this->tmpPrefix = wfTempDir() . '/migratefilelayout-test-' .
time() . '-' . mt_rand();
+ $this->tmpPrefix = $this->getNewTempDirectory();
$backend = new FSFileBackend( array(
'name' => 'local-migratefilerepolayouttest',
diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php
b/tests/phpunit/suites/UploadFromUrlTestSuite.php
index e867250..80893da 100644
--- a/tests/phpunit/suites/UploadFromUrlTestSuite.php
+++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php
@@ -21,6 +21,7 @@
$wgParserCacheType, $wgNamespaceAliases,
$wgNamespaceProtection,
$parserMemc;
+ $tmpDir = $this->getNewTempDirectory();
$tmpGlobals = array();
$tmpGlobals['wgScript'] = '/index.php';
@@ -38,10 +39,10 @@
'name' => 'local-backend',
'wikiId' => wfWikiId(),
'containerPaths' => array(
- 'local-public' => wfTempDir() .
'/test-repo/public',
- 'local-thumb' => wfTempDir() .
'/test-repo/thumb',
- 'local-temp' => wfTempDir() .
'/test-repo/temp',
- 'local-deleted' => wfTempDir() .
'/test-repo/delete',
+ 'local-public' =>
"{$tmpDir}/test-repo/public",
+ 'local-thumb' =>
"{$tmpDir}/test-repo/thumb",
+ 'local-temp' =>
"{$tmpDir}/test-repo/temp",
+ 'local-deleted' =>
"{$tmpDir}/test-repo/delete",
)
) ),
);
@@ -176,16 +177,10 @@
return $dir;
}
} else {
- $dir = wfTempDir() . "/mwParser-" . mt_rand() .
"-images";
+ $dir = $this->getNewTempDirectory();
}
wfDebug( "Creating upload directory $dir\n" );
-
- if ( file_exists( $dir ) ) {
- wfDebug( "Already exists!\n" );
-
- return $dir;
- }
wfMkdirParents( $dir . '/3/3a', null, __METHOD__ );
copy( "$IP/tests/phpunit/data/upload/headbg.jpg",
"$dir/3/3a/Foobar.jpg" );
--
To view, visit https://gerrit.wikimedia.org/r/256674
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I772de2134be41506d8ed08367be8c18f354bfc72
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits