From: Timo Tijhof Date: Fri, 14 Apr 2017 23:13:39 +0000 (-0700) Subject: phpunit: Make LogFormatterTest less slow X-Git-Tag: 1.31.0-rc.0~3505^2 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=8596a01658f30724463f8bee7ee07d2a26b8e58e;p=lhc%2Fweb%2Fwiklou.git phpunit: Make LogFormatterTest less slow Right now it's quite slow because it reloads LocalisationCache for every test case. Change the reload to only happen once for the entire class. Also use RequestContext instead of wgLang to match logic in the parent class (MediaWikiLangTestCase). $ phpunit includes/logging/LogFormatterTest.php Before - run 1) Time: 23.56 seconds, Memory: 48.00MB - run 2) Time: 22.41 seconds, Memory: 48.75MB After - run 1) Time: 14.27 seconds, Memory: 47.50MB - run 2) Time: 13.45 seconds, Memory: 47.25MB Change-Id: Ia791563ca9094c36782acfe9826def45f2a1d621 --- diff --git a/tests/phpunit/includes/logging/LogFormatterTest.php b/tests/phpunit/includes/logging/LogFormatterTest.php index c2b791e79c..1ef3df6ca1 100644 --- a/tests/phpunit/includes/logging/LogFormatterTest.php +++ b/tests/phpunit/includes/logging/LogFormatterTest.php @@ -4,6 +4,7 @@ * @group Database */ class LogFormatterTest extends MediaWikiLangTestCase { + private static $oldExtMsgFiles; /** * @var User @@ -30,21 +31,33 @@ class LogFormatterTest extends MediaWikiLangTestCase { */ protected $user_comment; + public static function setUpBeforeClass() { + parent::setUpBeforeClass(); + + global $wgExtensionMessagesFiles; + self::$oldExtMsgFiles = $wgExtensionMessagesFiles; + $wgExtensionMessagesFiles['LogTests'] = __DIR__ . '/LogTests.i18n.php'; + Language::getLocalisationCache()->recache( 'en' ); + } + + public static function tearDownAfterClass() { + global $wgExtensionMessagesFiles; + $wgExtensionMessagesFiles = self::$oldExtMsgFiles; + Language::getLocalisationCache()->recache( 'en' ); + + parent::tearDownAfterClass(); + } + protected function setUp() { parent::setUp(); - global $wgLang; - $this->setMwGlobals( [ 'wgLogTypes' => [ 'phpunit' ], 'wgLogActionsHandlers' => [ 'phpunit/test' => 'LogFormatter', 'phpunit/param' => 'LogFormatter' ], 'wgUser' => User::newFromName( 'Testuser' ), - 'wgExtensionMessagesFiles' => [ 'LogTests' => __DIR__ . '/LogTests.i18n.php' ], ] ); - Language::getLocalisationCache()->recache( $wgLang->getCode() ); - $this->user = User::newFromName( 'Testuser' ); $this->title = Title::newFromText( 'SomeTitle' ); $this->target = Title::newFromText( 'TestTarget' ); @@ -52,18 +65,11 @@ class LogFormatterTest extends MediaWikiLangTestCase { $this->context = new RequestContext(); $this->context->setUser( $this->user ); $this->context->setTitle( $this->title ); - $this->context->setLanguage( $wgLang ); + $this->context->setLanguage( RequestContext::getMain()->getLanguage() ); $this->user_comment = ''; } - protected function tearDown() { - parent::tearDown(); - - global $wgLang; - Language::getLocalisationCache()->recache( $wgLang->getCode() ); - } - public function newLogEntry( $action, $params ) { $logEntry = new ManualLogEntry( 'phpunit', $action ); $logEntry->setPerformer( $this->user );