From f5a5598ba421c45c7a625243436370e716670f2d Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Fri, 13 Sep 2024 12:37:00 +0200 Subject: [PATCH] Make use of upstream markTestSkippedIfExtensionNotLoaded This does the same as before. Also: * Make use of more fitting ??= operator. * We can use & for union types, I believe. Change-Id: I359408473882a9337b40ec464562a4358f8d3241 --- includes/Hooks.php | 2 +- tests/phpunit/HookTest.php | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/Hooks.php b/includes/Hooks.php index 6ff518f9..fd76922e 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -74,7 +74,7 @@ class Hooks implements return false; } - $extensionRegistry = $extensionRegistry ?: ExtensionRegistry::getInstance(); + $extensionRegistry ??= ExtensionRegistry::getInstance(); $contentModels = $extensionRegistry->getAttribute( 'CodeMirrorContentModels' ); $isRTL = $out->getTitle()->getPageLanguage()->isRTL(); // Disable CodeMirror if we're on an edit page with a conflicting gadget. See T178348. diff --git a/tests/phpunit/HookTest.php b/tests/phpunit/HookTest.php index 40461abe..a434297c 100644 --- a/tests/phpunit/HookTest.php +++ b/tests/phpunit/HookTest.php @@ -144,10 +144,6 @@ class HookTest extends MediaWikiIntegrationTestCase { [ $out->getUser(), 'usebetatoolbar', 0, $conds['usebetatoolbar'] ] ] ); - if ( $conds['gadget'] && !ExtensionRegistry::getInstance()->isLoaded( 'Gadgets' ) ) { - $this->markTestSkipped( 'Skipped as Gadgets extension is not available' ); - } - $extensionRegistry = $this->getMockExtensionRegistry( (bool)$conds['gadget'] ); $extensionRegistry->method( 'getAttribute' ) ->with( 'CodeMirrorContentModels' ) @@ -155,6 +151,8 @@ class HookTest extends MediaWikiIntegrationTestCase { $gadgetRepoMock = null; if ( $conds['gadget'] ) { + $this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' ); + $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) ->method( 'isEnabled' ) @@ -194,7 +192,7 @@ class HookTest extends MediaWikiIntegrationTestCase { /** * @param string $contentModel * @param bool $isRTL - * @return OutputPage|MockObject + * @return OutputPage&MockObject */ private function getMockOutputPage( string $contentModel = CONTENT_MODEL_WIKITEXT, bool $isRTL = false ) { $out = $this->createMock( OutputPage::class ); @@ -214,7 +212,7 @@ class HookTest extends MediaWikiIntegrationTestCase { /** * @param bool $gadgetsEnabled - * @return MockObject|ExtensionRegistry + * @return ExtensionRegistry&MockObject */ private function getMockExtensionRegistry( bool $gadgetsEnabled ) { $mock = $this->createMock( ExtensionRegistry::class );