From 8e14ff1bc01af238077fa03821a6b649e6f617f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Tue, 27 May 2025 00:01:41 +0200 Subject: [PATCH] phpunit: Remove superfluous Title::clearCaches() calls Why: - Various tests have been calling Title::clearCaches() on an ad-hoc basis at the end of test methods, or in tearDown(), to work around stale Title instances persisting across tests in Title's internal caches. - MediaWikiIntegrationTestCase takes care of this since Ie6cac7e1282f794277dfc8ff3673f12e9969818c, making these calls unnecessary. What: - Remove now-redundant Title::clearCaches() calls from tearDown() overrides and the end of test methods. - Preserve in-test Title::clearCaches() calls that are likely intended to force internal caches to reflect changes happening within the test itself. Bug: T395214 Change-Id: Ib5d42389cef20f3839c7f7a80041d002f0f09449 (cherry picked from commit 6483181044496c339ad497cc885319b20de7f6e7) --- tests/phpunit/includes/ResourceLoader/WikiModuleTest.php | 5 ----- tests/phpunit/includes/api/ApiComparePagesTest.php | 2 -- tests/phpunit/includes/linker/LinkRendererTest.php | 5 ----- tests/phpunit/includes/parser/ExtraParserTest.php | 2 +- tests/phpunit/includes/search/TitleMatcherTest.php | 5 ----- tests/phpunit/includes/title/TitleTest.php | 1 - tests/phpunit/includes/title/TitleUrlTest.php | 5 ----- 7 files changed, 1 insertion(+), 24 deletions(-) diff --git a/tests/phpunit/includes/ResourceLoader/WikiModuleTest.php b/tests/phpunit/includes/ResourceLoader/WikiModuleTest.php index 73f6be19d05..1739460af57 100644 --- a/tests/phpunit/includes/ResourceLoader/WikiModuleTest.php +++ b/tests/phpunit/includes/ResourceLoader/WikiModuleTest.php @@ -448,11 +448,6 @@ class WikiModuleTest extends ResourceLoaderTestCase { 'Redirect resolved by getContent' ); } - - protected function tearDown(): void { - Title::clearCaches(); - parent::tearDown(); - } } class TestResourceLoaderWikiModule extends WikiModule { diff --git a/tests/phpunit/includes/api/ApiComparePagesTest.php b/tests/phpunit/includes/api/ApiComparePagesTest.php index b86c753f5e6..72363a61df8 100644 --- a/tests/phpunit/includes/api/ApiComparePagesTest.php +++ b/tests/phpunit/includes/api/ApiComparePagesTest.php @@ -138,8 +138,6 @@ class ApiComparePagesTest extends ApiTestCase { ], 'comment' => 'Test for ApiComparePages', ] ); - - Title::clearCaches(); // Otherwise it has the wrong latest revision for some reason } protected function doReplacements( &$value ) { diff --git a/tests/phpunit/includes/linker/LinkRendererTest.php b/tests/phpunit/includes/linker/LinkRendererTest.php index d4b242c83be..c2ba172ed0e 100644 --- a/tests/phpunit/includes/linker/LinkRendererTest.php +++ b/tests/phpunit/includes/linker/LinkRendererTest.php @@ -304,9 +304,4 @@ class LinkRendererTest extends MediaWikiLangTestCase { $linkRenderer->getLinkClasses( $redirectTitle ) ); } - - protected function tearDown(): void { - Title::clearCaches(); - parent::tearDown(); - } } diff --git a/tests/phpunit/includes/parser/ExtraParserTest.php b/tests/phpunit/includes/parser/ExtraParserTest.php index 7817744c27f..8124f36420a 100644 --- a/tests/phpunit/includes/parser/ExtraParserTest.php +++ b/tests/phpunit/includes/parser/ExtraParserTest.php @@ -274,7 +274,7 @@ class ExtraParserTest extends MediaWikiIntegrationTestCase { MainConfigNames::InterwikiCache, ClassicInterwikiLookup::buildCdbHash( $testInterwikis ) ); - Title::clearCaches(); + $this->parser->startExternalParse( Title::newFromText( __FUNCTION__ ), $this->options, diff --git a/tests/phpunit/includes/search/TitleMatcherTest.php b/tests/phpunit/includes/search/TitleMatcherTest.php index b7cc9b3aec7..baae409f4f0 100644 --- a/tests/phpunit/includes/search/TitleMatcherTest.php +++ b/tests/phpunit/includes/search/TitleMatcherTest.php @@ -168,9 +168,4 @@ class TitleMatcherTest extends MediaWikiIntegrationTestCase { $result = $matcher->getNearMatchResultSet( 'Test Link Wrong' ); $this->assertSame( 0, $result->numRows() ); } - - protected function tearDown(): void { - Title::clearCaches(); - parent::tearDown(); - } } diff --git a/tests/phpunit/includes/title/TitleTest.php b/tests/phpunit/includes/title/TitleTest.php index 81e1e17ab2d..c4dbb546d81 100644 --- a/tests/phpunit/includes/title/TitleTest.php +++ b/tests/phpunit/includes/title/TitleTest.php @@ -82,7 +82,6 @@ class TitleTest extends MediaWikiIntegrationTestCase { } protected function tearDown(): void { - Title::clearCaches(); parent::tearDown(); // delete dummy pages $this->getNonexistingTestPage( 'UTest1' ); diff --git a/tests/phpunit/includes/title/TitleUrlTest.php b/tests/phpunit/includes/title/TitleUrlTest.php index 139bd704ed8..f416271b9b5 100644 --- a/tests/phpunit/includes/title/TitleUrlTest.php +++ b/tests/phpunit/includes/title/TitleUrlTest.php @@ -52,11 +52,6 @@ class TitleUrlTest extends MediaWikiLangTestCase { ] ); } - protected function tearDown(): void { - Title::clearCaches(); - parent::tearDown(); - } - public function testUrlsForSimpleTitle() { $title = Title::makeTitle( NS_USER, 'Göatee' ); $name = $title->getPrefixedURL();