From de4a9c6b9a6a9be1b466d92edaad88e08d71fb22 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Tue, 25 Jan 2011 16:32:43 +0000 Subject: [PATCH] Reset the cache used in User::idFromName(), otherwise tests will try to add the user '127.0.0.1' multiple times, resulting in a database error (duplicate key for `user_name` field) --- includes/User.php | 7 +++++++ tests/phpunit/MediaWikiTestCase.php | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/includes/User.php b/includes/User.php index 0b4cf361e5..9cd33f9928 100644 --- a/includes/User.php +++ b/includes/User.php @@ -441,6 +441,13 @@ class User { return $result; } + /** + * Reset the cache used in idFromName(). For use in tests. + */ + public static function resetIdByNameCache() { + self::$idCacheByName = array(); + } + /** * Does the string match an anonymous IPv4 address? * diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 4cd9c8152f..48b6212aa7 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -81,7 +81,9 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { function addDBData() {} private function addCoreDBData() { - + + User::resetIdByNameCache(); + //Make sysop user $user = User::newFromName( 'UTSysop' ); -- 2.20.1