diff --git a/.phan/config.php b/.phan/config.php index 76efd06d..9178fb24 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -1,3 +1,19 @@ userOptionsLookup = $userOptionsLookup; $this->useV6 = $config->get( 'CodeMirrorV6' ); $this->conflictingGadgets = $config->get( 'CodeMirrorConflictingGadgets' ); $this->isSupportedRtlWiki = $config->get( 'CodeMirrorRTL' ); + $this->gadgetRepo = $gadgetRepo; } /** @@ -88,15 +92,13 @@ class Hooks implements * @return bool */ private function conflictingGadgetsEnabled( ExtensionRegistry $extensionRegistry, User $user ): bool { - if ( !$extensionRegistry->isLoaded( 'Gadgets' ) ) { + if ( !$extensionRegistry->isLoaded( 'Gadgets' ) || !$this->gadgetRepo ) { return false; } - // @phan-suppress-next-line PhanUndeclaredClassMethod Code path won't be followed if class doesn't exist. - $gadgetRepo = GadgetRepo::singleton(); - $conflictingGadgets = array_intersect( $this->conflictingGadgets, $gadgetRepo->getGadgetIds() ); + $conflictingGadgets = array_intersect( $this->conflictingGadgets, $this->gadgetRepo->getGadgetIds() ); foreach ( $conflictingGadgets as $conflictingGadget ) { try { - if ( $gadgetRepo->getGadget( $conflictingGadget )->isEnabled( $user ) ) { + if ( $this->gadgetRepo->getGadget( $conflictingGadget )->isEnabled( $user ) ) { return true; } } catch ( InvalidArgumentException $e ) { diff --git a/tests/phpunit/HookTest.php b/tests/phpunit/HookTest.php index da411f63..40461abe 100644 --- a/tests/phpunit/HookTest.php +++ b/tests/phpunit/HookTest.php @@ -59,7 +59,7 @@ class HookTest extends MediaWikiIntegrationTestCase { $isFirstCall = false; } ); - $hooks = new Hooks( $userOptionsLookup, $this->getServiceContainer()->getMainConfig() ); + $hooks = new Hooks( $userOptionsLookup, $this->getServiceContainer()->getMainConfig(), null ); $method = $readOnly ? 'onEditPage__showReadOnlyForm_initial' : 'onEditPage__showEditForm_initial'; $hooks->{$method}( $this->createMock( EditPage::class ), $out ); } @@ -97,7 +97,7 @@ class HookTest extends MediaWikiIntegrationTestCase { // CodeMirror 5 $this->overrideConfigValues( [ 'CodeMirrorV6' => false ] ); - $hook = new Hooks( $userOptionsLookup, $config ); + $hook = new Hooks( $userOptionsLookup, $config, null ); $preferences = []; $hook->onGetPreferences( $user, $preferences ); self::assertArrayHasKey( 'usecodemirror', $preferences ); @@ -107,7 +107,7 @@ class HookTest extends MediaWikiIntegrationTestCase { // CodeMirror 6 $this->overrideConfigValues( [ 'CodeMirrorV6' => true ] ); - $hook = new Hooks( $userOptionsLookup, $config ); + $hook = new Hooks( $userOptionsLookup, $config, null ); $preferences = []; $hook->onGetPreferences( $user, $preferences ); self::assertArrayHasKey( 'usecodemirror', $preferences ); @@ -153,6 +153,7 @@ class HookTest extends MediaWikiIntegrationTestCase { ->with( 'CodeMirrorContentModels' ) ->willReturn( [ CONTENT_MODEL_WIKITEXT ] ); + $gadgetRepoMock = null; if ( $conds['gadget'] ) { $gadgetMock = $this->createMock( Gadget::class ); $gadgetMock->expects( $this->once() ) @@ -165,10 +166,9 @@ class HookTest extends MediaWikiIntegrationTestCase { $gadgetRepoMock->expects( $this->once() ) ->method( 'getGadgetIds' ) ->willReturn( [ $conds['gadget'] ] ); - GadgetRepo::setSingleton( $gadgetRepoMock ); } - $hooks = new Hooks( $userOptionsLookup, $this->getServiceContainer()->getMainConfig() ); + $hooks = new Hooks( $userOptionsLookup, $this->getServiceContainer()->getMainConfig(), $gadgetRepoMock ); self::assertSame( $expectation, $hooks->shouldLoadCodeMirror( $out, $extensionRegistry ) ); }