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
This commit is contained in:
thiemowmde 2024-09-13 12:37:00 +02:00
parent 3b6e74ded4
commit f5a5598ba4
2 changed files with 5 additions and 7 deletions

View file

@ -74,7 +74,7 @@ class Hooks implements
return false; return false;
} }
$extensionRegistry = $extensionRegistry ?: ExtensionRegistry::getInstance(); $extensionRegistry ??= ExtensionRegistry::getInstance();
$contentModels = $extensionRegistry->getAttribute( 'CodeMirrorContentModels' ); $contentModels = $extensionRegistry->getAttribute( 'CodeMirrorContentModels' );
$isRTL = $out->getTitle()->getPageLanguage()->isRTL(); $isRTL = $out->getTitle()->getPageLanguage()->isRTL();
// Disable CodeMirror if we're on an edit page with a conflicting gadget. See T178348. // Disable CodeMirror if we're on an edit page with a conflicting gadget. See T178348.

View file

@ -144,10 +144,6 @@ class HookTest extends MediaWikiIntegrationTestCase {
[ $out->getUser(), 'usebetatoolbar', 0, $conds['usebetatoolbar'] ] [ $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 = $this->getMockExtensionRegistry( (bool)$conds['gadget'] );
$extensionRegistry->method( 'getAttribute' ) $extensionRegistry->method( 'getAttribute' )
->with( 'CodeMirrorContentModels' ) ->with( 'CodeMirrorContentModels' )
@ -155,6 +151,8 @@ class HookTest extends MediaWikiIntegrationTestCase {
$gadgetRepoMock = null; $gadgetRepoMock = null;
if ( $conds['gadget'] ) { if ( $conds['gadget'] ) {
$this->markTestSkippedIfExtensionNotLoaded( 'Gadgets' );
$gadgetMock = $this->createMock( Gadget::class ); $gadgetMock = $this->createMock( Gadget::class );
$gadgetMock->expects( $this->once() ) $gadgetMock->expects( $this->once() )
->method( 'isEnabled' ) ->method( 'isEnabled' )
@ -194,7 +192,7 @@ class HookTest extends MediaWikiIntegrationTestCase {
/** /**
* @param string $contentModel * @param string $contentModel
* @param bool $isRTL * @param bool $isRTL
* @return OutputPage|MockObject * @return OutputPage&MockObject
*/ */
private function getMockOutputPage( string $contentModel = CONTENT_MODEL_WIKITEXT, bool $isRTL = false ) { private function getMockOutputPage( string $contentModel = CONTENT_MODEL_WIKITEXT, bool $isRTL = false ) {
$out = $this->createMock( OutputPage::class ); $out = $this->createMock( OutputPage::class );
@ -214,7 +212,7 @@ class HookTest extends MediaWikiIntegrationTestCase {
/** /**
* @param bool $gadgetsEnabled * @param bool $gadgetsEnabled
* @return MockObject|ExtensionRegistry * @return ExtensionRegistry&MockObject
*/ */
private function getMockExtensionRegistry( bool $gadgetsEnabled ) { private function getMockExtensionRegistry( bool $gadgetsEnabled ) {
$mock = $this->createMock( ExtensionRegistry::class ); $mock = $this->createMock( ExtensionRegistry::class );