Pmiazga has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366874 )

Change subject: Hygiene: Dependency Injection for Popups
......................................................................

Hygiene: Dependency Injection for Popups

Changes:
 - removed ugly PopupsContext::getInstance
 - removed ugly PopupsContextTestWrapper helper
 - defined all services inside ServiceWirings
 - fixed unit tests to test classes directly or use MediawikiServices

Change-Id: Ie27e28bb07aebe01014848c290369b1b1f098e9b
---
M extension.json
M includes/PopupsContext.php
M includes/PopupsHooks.php
A includes/ServiceWirings.php
M includes/UserPreferencesChangeHandler.php
M tests/phpunit/PopupsContextTest.php
M tests/phpunit/PopupsHooksTest.php
M tests/phpunit/UserPreferencesChangeHandlerTest.php
8 files changed, 128 insertions(+), 155 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups 
refs/changes/74/366874/1

diff --git a/extension.json b/extension.json
index a9f673d..7974040 100644
--- a/extension.json
+++ b/extension.json
@@ -129,5 +129,8 @@
                "localBasePath": "",
                "remoteExtPath": "Popups"
        },
+       "ServiceWiringFiles": [
+               "includes/ServiceWirings.php"
+       ],
        "manifest_version": 1
 }
diff --git a/includes/PopupsContext.php b/includes/PopupsContext.php
index 24abb31..7d86120 100644
--- a/includes/PopupsContext.php
+++ b/includes/PopupsContext.php
@@ -20,14 +20,10 @@
  */
 namespace Popups;
 
-use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 use ExtensionRegistry;
 use Config;
 use Popups\EventLogging\EventLogger;
-use Popups\EventLogging\EventLoggerFactory;
-use Popups\EventLogging\MWEventLogger;
-use Popups\EventLogging\NullLogger;
 
 /**
  * Popups Module
@@ -89,35 +85,13 @@
         * @param EventLogger $eventLogger A logger capable of logging 
EventLogging
         *  events
         */
-       protected function __construct( Config $config, ExtensionRegistry 
$extensionRegistry,
+       public function __construct( Config $config, ExtensionRegistry 
$extensionRegistry,
                PopupsGadgetsIntegration $gadgetsIntegration, EventLogger 
$eventLogger ) {
-               /** @todo Use MediaWikiServices Service Locator when it's ready 
*/
                $this->extensionRegistry = $extensionRegistry;
                $this->gadgetsIntegration = $gadgetsIntegration;
                $this->eventLogger = $eventLogger;
 
                $this->config = $config;
-       }
-
-       /**
-        * Get a PopupsContext instance
-        *
-        * @return PopupsContext
-        */
-       public static function getInstance() {
-               if ( !self::$instance ) {
-                       /** @todo Use MediaWikiServices Service Locator when 
it's ready */
-
-                       $registry = ExtensionRegistry::getInstance();
-                       $config = 
MediaWikiServices::getInstance()->getConfigFactory()
-                               ->makeConfig( PopupsContext::EXTENSION_NAME );
-                       $gadgetsIntegration = new PopupsGadgetsIntegration( 
$config, $registry );
-                       $eventLoggerFactory = new EventLoggerFactory( $config, 
$registry );
-
-                       self::$instance = new PopupsContext( $config, $registry,
-                               $gadgetsIntegration, $eventLoggerFactory->get() 
);
-               }
-               return self::$instance;
        }
 
        /**
@@ -188,16 +162,7 @@
         * @return \Psr\Log\LoggerInterface
         */
        public function getLogger() {
-               return LoggerFactory::getInstance( self::LOGGER_CHANNEL );
-       }
-
-       /**
-        * Get Module config
-        *
-        * @return \Config
-        */
-       public function getConfig() {
-               return $this->config;
+               return MediaWikiServices::getInstance()->getService( 
'Popups.Logger' );
        }
 
        /**
diff --git a/includes/PopupsHooks.php b/includes/PopupsHooks.php
index 9a7807e..0897e78 100644
--- a/includes/PopupsHooks.php
+++ b/includes/PopupsHooks.php
@@ -20,6 +20,7 @@
  */
 namespace Popups;
 
+use MediaWiki\MediaWikiServices;
 use User;
 use OutputPage;
 use Skin;
@@ -40,7 +41,9 @@
         */
        static function onGetBetaPreferences( User $user, array &$prefs ) {
                global $wgExtensionAssetsPath;
-               if ( PopupsContext::getInstance()->isBetaFeatureEnabled() !== 
true ) {
+
+               $context = MediaWikiServices::getInstance()->getService( 
'Popups.Context' );
+               if ( $context->isBetaFeatureEnabled() !== true ) {
                        return;
                }
                $prefs[PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME] = [
@@ -65,7 +68,7 @@
         * @param array &$prefs Preferences description array, to be fed to a 
HTMLForm object
         */
        static function onGetPreferences( User $user, array &$prefs ) {
-               $context = PopupsContext::getInstance();
+               $context = MediaWikiServices::getInstance()->getService( 
'Popups.Context' );
 
                if ( !$context->showPreviewsOptInOnPreferencesPage() ) {
                        return;
@@ -108,17 +111,17 @@
         * @return bool
         */
        public static function onBeforePageDisplay( OutputPage &$out, Skin 
&$skin ) {
-               $module = PopupsContext::getInstance();
+               $context = MediaWikiServices::getInstance()->getService( 
'Popups.Context' );
                $user = $out->getUser();
 
-               if ( !$module->areDependenciesMet() ) {
-                       $logger = $module->getLogger();
+               if ( !$context->areDependenciesMet() ) {
+                       $logger = $context->getLogger();
                        $logger->error( 'Popups requires the PageImages and 
TextExtracts extensions. '
                                . 'If Beta mode is on it requires also 
BetaFeatures extension' );
                        return true;
                }
 
-               if ( !$module->isBetaFeatureEnabled() || 
$module->shouldSendModuleToUser( $user ) ) {
+               if ( !$context->isBetaFeatureEnabled() || 
$context->shouldSendModuleToUser( $user ) ) {
                        $out->addModules( [ 'ext.popups' ] );
                }
 
@@ -129,7 +132,7 @@
         * @param array &$vars Array of variables to be added into the output 
of the startup module
         */
        public static function onResourceLoaderGetConfigVars( array &$vars ) {
-               $conf = PopupsContext::getInstance()->getConfig();
+               $conf = MediaWikiServices::getInstance()->getService( 
'Popups.Config' );
                $vars['wgPopupsSchemaSamplingRate'] = $conf->get( 
'PopupsSchemaSamplingRate' );
                $vars['wgPopupsBetaFeature'] = $conf->get( 'PopupsBetaFeature' 
);
                $vars['wgPopupsGateway'] = $conf->get( 'PopupsGateway' );
@@ -150,11 +153,11 @@
         * @param OutputPage $out OutputPage instance calling the hook
         */
        public static function onMakeGlobalVariablesScript( array &$vars, 
OutputPage $out ) {
-               $module = PopupsContext::getInstance();
+               $context = MediaWikiServices::getInstance()->getService( 
'Popups.Context' );
                $user = $out->getUser();
 
-               $vars['wgPopupsShouldSendModuleToUser'] = 
$module->shouldSendModuleToUser( $user );
-               $vars['wgPopupsConflictsWithNavPopupGadget'] = 
$module->conflictsWithNavPopupsGadget(
+               $vars['wgPopupsShouldSendModuleToUser'] = 
$context->shouldSendModuleToUser( $user );
+               $vars['wgPopupsConflictsWithNavPopupGadget'] = 
$context->conflictsWithNavPopupsGadget(
                        $user );
        }
 
@@ -164,8 +167,9 @@
         * @param array &$wgDefaultUserOptions Reference to default options 
array
         */
        public static function onUserGetDefaultOptions( &$wgDefaultUserOptions 
) {
+               $context = MediaWikiServices::getInstance()->getService( 
'Popups.Context' );
                $wgDefaultUserOptions[ 
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME ] =
-                       
PopupsContext::getInstance()->getDefaultIsEnabledState();
+                       $context->getDefaultIsEnabledState();
        }
 
 }
diff --git a/includes/ServiceWirings.php b/includes/ServiceWirings.php
new file mode 100644
index 0000000..5be618f
--- /dev/null
+++ b/includes/ServiceWirings.php
@@ -0,0 +1,44 @@
+<?php
+
+use MediaWiki\MediaWikiServices;
+use Popups\PopupsContext;
+use Popups\PopupsGadgetsIntegration;
+use Popups\EventLogging\EventLoggerFactory;
+use Popups\UserPreferencesChangeHandler;
+use \MediaWiki\Logger\LoggerFactory;
+
+return [
+       'Popups.Config' => function ( MediaWikiServices $services ) {
+               return $services->getService( 'ConfigFactory' )
+                       ->makeConfig( PopupsContext::EXTENSION_NAME );
+       },
+       'Popups.GadgetsIntegration' => function( MediaWikiServices $services ) {
+               return new PopupsGadgetsIntegration(
+                       $services->getService( 'Popups.Config' ),
+                       ExtensionRegistry::getInstance()
+               );
+       },
+       'Popups.EventLogger' => function( MediaWikiServices $serivces ) {
+               $factory = new EventLoggerFactory(
+                       $serivces->getService( 'Popups.Config' ),
+                       ExtensionRegistry::getInstance()
+               );
+               return $factory->get();
+       },
+       'Popups.UserPreferencesChangeHandler' => function( MediaWikiServices 
$services ) {
+               return new UserPreferencesChangeHandler(
+                       $services->getService( ' Popups.Context' )
+               );
+       },
+       'Popups.Logger' => function( MediaWikiServices $services ) {
+               return LoggerFactory::getInstance( 
PopupsContext::LOGGER_CHANNEL );
+       },
+       'Popups.Context' => function ( MediaWikiServices $services ) {
+               return new PopupsContext(
+                       $services->getService( 'Popups.Config' ),
+                       ExtensionRegistry::getInstance(),
+                       $services->getService( 'Popups.GadgetsIntegration' ),
+                       $services->getService( 'Popups.EventLogger' )
+               );
+       }
+];
diff --git a/includes/UserPreferencesChangeHandler.php 
b/includes/UserPreferencesChangeHandler.php
index b705eda..5f6a023 100644
--- a/includes/UserPreferencesChangeHandler.php
+++ b/includes/UserPreferencesChangeHandler.php
@@ -30,10 +30,6 @@
  */
 class UserPreferencesChangeHandler {
        /**
-        * @var UserPreferencesChangeHandler
-        */
-       private static $instance;
-       /**
         * @var PopupsContext
         */
        private $popupsContext;
@@ -42,7 +38,7 @@
         * UserPreferencesChangeHandler constructor.
         * @param PopupsContext $context Popups context instance
         */
-       public function __construct( PopupsContext $context ) {
+       public function __construct( $context ) {
                $this->popupsContext = $context;
        }
 
@@ -70,10 +66,7 @@
         * @return UserPreferencesChangeHandler
         */
        private static function newFromGlobalState() {
-               if ( self::$instance === null ) {
-                       self::$instance = new UserPreferencesChangeHandler( 
PopupsContext::getInstance() );
-               }
-               return self::$instance;
+               return MediaWikiServices::getInstance()->getService( 
'Popups.UserPreferencesChangeHandler' );
        }
 
        /**
diff --git a/tests/phpunit/PopupsContextTest.php 
b/tests/phpunit/PopupsContextTest.php
index 7ac4589..79a90f9 100644
--- a/tests/phpunit/PopupsContextTest.php
+++ b/tests/phpunit/PopupsContextTest.php
@@ -18,7 +18,6 @@
  * @file
  * @ingroup extensions
  */
-require_once 'PopupsContextTestWrapper.php';
 
 use Popups\PopupsContext;
 
@@ -35,11 +34,30 @@
         */
        const ANONYMOUS_USER = 0;
 
-       public function tearDown() {
-               PopupsContextTestWrapper::resetTestInstance();
-               parent::tearDown();
+       /**
+        * Helper method to quickly build Popups Context
+        * @param ExtensionRegistry|null $registry
+        * @param \Popups\PopupsGadgetsIntegration|null $integration
+        * @param \Popups\EventLogging\EventLogger $eventLogger
+        * @return PopupsContext
+        */
+       protected function getContext( $registry = null, $integration = null, 
$eventLogger = null ) {
+               $config = new GlobalVarConfig();
+               $registry = $registry ?: ExtensionRegistry::getInstance();
+               if ( $eventLogger === null ) {
+                       $eventLogger = $this->getMockBuilder( 
\Popups\EventLogging\EventLogger::class )
+                       ->getMock();
+               }
+               if ( $integration === null ) {
+                       $integration = $this->getMockBuilder( 
\Popups\PopupsGadgetsIntegration::class )
+                               ->disableOriginalConstructor()
+                               ->setMethods( [ 'conflictsWithNavPopupsGadget' 
] )
+                               ->getMock();
+                       $integration->method( 'conflictsWithNavPopupsGadget' )
+                               ->willReturn( false );
+               }
+               return new PopupsContext( $config, $registry, $integration, 
$eventLogger );
        }
-
        /**
         * @covers ::showPreviewsOptInOnPreferencesPage
         * @dataProvider provideConfigForShowPreviewsInOptIn
@@ -48,30 +66,8 @@
         */
        public function testShowPreviewsPreferencesPage( $config, $expected ) {
                $this->setMwGlobals( $config );
-               $context = PopupsContext::getInstance();
+               $context = $this->getContext();
                $this->assertEquals( $expected, 
$context->showPreviewsOptInOnPreferencesPage() );
-       }
-
-       /**
-        * @covers ::__construct
-        * @covers ::getConfig
-        */
-       public function testContextAndConfigInitialization() {
-               $configMock = $this->getMock( Config::class );
-
-               $configFactoryMock = $this->getMock( ConfigFactory::class, [ 
'makeConfig' ] );
-               $configFactoryMock->expects( $this->once() )
-                       ->method( 'makeConfig' )
-                       ->with( PopupsContext::EXTENSION_NAME )
-                       ->will( $this->returnValue( $configMock ) );
-
-               $mwServices = $this->overrideMwServices();
-               $mwServices->redefineService( 'ConfigFactory', function () use 
( $configFactoryMock ) {
-                       return $configFactoryMock;
-               } );
-
-               $context = PopupsContext::getInstance();
-               $this->assertSame( $context->getConfig(), $configMock );
        }
 
        /**
@@ -112,7 +108,7 @@
                $this->setMwGlobals( [
                        "wgPopupsBetaFeature" => false
                ] );
-               $context = PopupsContext::getInstance();
+               $context = $this->getContext();
                $user = $this->getMutableTestUser()->getUser();
                $user->setOption( 
PopupsContext::PREVIEWS_OPTIN_PREFERENCE_NAME, $optIn );
                $this->assertEquals( $context->shouldSendModuleToUser( $user ), 
$expected );
@@ -148,14 +144,15 @@
                $this->setMwGlobals( [
                        "wgPopupsBetaFeature" => true
                ] );
-               $context = PopupsContext::getInstance();
+
+               $context = $this->getContext();
                $user = $this->getMutableTestUser()->getUser();
                $user->setOption( PopupsContext::PREVIEWS_BETA_PREFERENCE_NAME, 
$optIn );
                $this->assertEquals( $context->shouldSendModuleToUser( $user ), 
$expected );
        }
 
        /**
-        * Check that Page Previews are disabled for anonymous user
+        * Check tst Page Previews are disabled for anonymous user
         * @covers ::shouldSendModuleToUser
         * @covers ::isBetaFeatureEnabled
         * @dataProvider providerAnonUserHasDisabledPagePreviews
@@ -169,7 +166,7 @@
                        "wgPopupsBetaFeature" => $betaFeatureEnabled,
                ] );
 
-               $context = PopupsContext::getInstance();
+               $context = $this->getContext();
                $this->assertEquals( $expected, 
$context->shouldSendModuleToUser( $user ) );
        }
 
@@ -216,7 +213,7 @@
                $mock->expects( $this->any() )
                        ->method( 'isLoaded' )
                        ->will( new 
PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( $returnValues ) );
-               $context = new PopupsContextTestWrapper( new GlobalVarConfig(), 
$mock );
+               $context = $this->getContext( $mock );
                $this->assertEquals( $expected, $context->areDependenciesMet() 
);
        }
 
@@ -267,27 +264,6 @@
                        ]
                ];
        }
-       /**
-        * @covers ::getLogger
-        */
-       public function testGetLogger() {
-               $loggerMock = $this->getMock( \Psr\Log\LoggerInterface::class );
-
-               $this->setLogger( PopupsContext::LOGGER_CHANNEL, $loggerMock );
-               $context = PopupsContext::getInstance();
-               $this->assertSame( $loggerMock, $context->getLogger() );
-       }
-
-       /**
-        * @covers ::getInstance
-        */
-       public function testGetInstanceReturnsSameObjectEveryTime() {
-               $first = PopupsContext::getInstance();
-               $second = PopupsContext::getInstance();
-
-               $this->assertSame( $first, $second );
-               $this->assertInstanceOf( PopupsContext::class, $first );
-       }
 
        /**
         * @covers ::getDefaultIsEnabledState
@@ -296,7 +272,8 @@
                $this->setMwGlobals( [
                        'wgPopupsOptInDefaultState' => "2"
                ] );
-               $this->assertEquals( "2", 
PopupsContext::getInstance()->getDefaultIsEnabledState() );
+               $context = $this->getContext();
+               $this->assertEquals( "2", $context->getDefaultIsEnabledState() 
);
        }
 
        /**
@@ -315,8 +292,7 @@
                        ->with( $user )
                        ->willReturn( true );
 
-               $context = new PopupsContextTestWrapper( $this->getConfigMock(),
-                       ExtensionRegistry::getInstance(), $integrationMock );
+               $context = $this->getContext( null, $integrationMock );
                $this->assertEquals( true, 
$context->conflictsWithNavPopupsGadget( $user ) );
        }
 
@@ -327,24 +303,9 @@
                $loggerMock = $this->getMock( 
\Popups\EventLogging\EventLogger::class );
                $loggerMock->expects( $this->once() )
                        ->method( 'log' );
-               $integrationMock = $this->getMockBuilder( 
\Popups\PopupsGadgetsIntegration::class )
-                       ->disableOriginalConstructor()
-                       ->setMethods( [ 'conflictsWithNavPopupsGadget' ] )
-                       ->getMock();
 
-               $context = new PopupsContextTestWrapper( $this->getConfigMock(),
-                       ExtensionRegistry::getInstance(), $integrationMock, 
$loggerMock );
+               $context = $this->getContext( null, null, $loggerMock );
                $context->logUserDisabledPagePreviewsEvent();
        }
 
-       /**
-        * @return PHPUnit_Framework_MockObject_MockObject|Config
-        */
-       private function getConfigMock() {
-               $mock = $this->getMockBuilder( 'Config' )
-                       ->setMethods( [ 'get', 'has' ] )
-                       ->getMock();
-
-               return $mock;
-       }
 }
diff --git a/tests/phpunit/PopupsHooksTest.php 
b/tests/phpunit/PopupsHooksTest.php
index bc73e40..84ac85a 100644
--- a/tests/phpunit/PopupsHooksTest.php
+++ b/tests/phpunit/PopupsHooksTest.php
@@ -18,7 +18,6 @@
  * @file
  * @ingroup extensions
  */
-require_once 'PopupsContextTestWrapper.php';
 use Popups\PopupsContext;
 use Popups\PopupsHooks;
 
@@ -31,8 +30,18 @@
 class PopupsHooksTest extends MediaWikiTestCase {
 
        protected function tearDown() {
-               PopupsContextTestWrapper::resetTestInstance();
+               $services = \MediaWiki\MediaWikiServices::getInstance();
+               $services->resetServiceForTesting( 'Popups.Context' );
+               $services->resetServiceForTesting( 'Popups.Config' );
                parent::tearDown();
+       }
+
+       private function overrideContext( $context ) {
+               \MediaWiki\MediaWikiServices::getInstance()->redefineService( 
'Popups.Context',
+                       function() use ( $context ) {
+                               return $context;
+                       }
+               );
        }
 
        /**
@@ -63,7 +72,7 @@
         * @covers ::onGetPreferences
         */
        public function testOnGetPreferencesPreviewsDisabled() {
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'showPreviewsOptInOnPreferencesPage' ] )
                        ->getMock();
@@ -71,7 +80,7 @@
                        ->method( 'showPreviewsOptInOnPreferencesPage' )
                        ->will( $this->returnValue( false ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                $prefs = [ 'someNotEmptyValue' => 'notEmpty' ];
 
                PopupsHooks::onGetPreferences( $this->getTestUser()->getUser(), 
$prefs );
@@ -84,7 +93,7 @@
         */
        public function testOnGetPreferencesNavPopupGadgetIsOn() {
                $userMock = $this->getTestUser()->getUser();
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'showPreviewsOptInOnPreferencesPage', 
'conflictsWithNavPopupsGadget' ] )
                        ->getMock();
@@ -98,7 +107,7 @@
                        ->with( $userMock )
                        ->will( $this->returnValue( true ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                $prefs = [];
 
                PopupsHooks::onGetPreferences( $this->getTestUser()->getUser(), 
$prefs );
@@ -114,7 +123,7 @@
         * @covers ::onGetPreferences
         */
        public function testOnGetPreferencesPreviewsEnabled() {
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'showPreviewsOptInOnPreferencesPage', 
'conflictsWithNavPopupsGadget' ] )
                        ->getMock();
@@ -126,7 +135,7 @@
                        ->method( 'conflictsWithNavPopupsGadget' )
                        ->will( $this->returnValue( false ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                $prefs = [
                        'skin' => 'skin stuff',
                        'someNotEmptyValue' => 'notEmpty',
@@ -145,7 +154,7 @@
         * @covers ::onGetPreferences
         */
        public function 
testOnGetPreferencesPreviewsEnabledWhenSkinIsNotAvailable() {
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'showPreviewsOptInOnPreferencesPage', 
'conflictsWithNavPopupsGadget' ] )
                        ->getMock();
@@ -157,7 +166,7 @@
                        ->method( 'conflictsWithNavPopupsGadget' )
                        ->will( $this->returnValue( false ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                $prefs = [
                        'someNotEmptyValue' => 'notEmpty',
                        'other' => 'notEmpty'
@@ -202,7 +211,7 @@
                $userOptions = [
                        'test' => 'not_empty'
                ];
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->setMethods( [ 'getDefaultIsEnabledState' ] )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -211,7 +220,7 @@
                        ->method( 'getDefaultIsEnabledState' )
                        ->willReturn( true );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
 
                PopupsHooks::onUserGetDefaultOptions( $userOptions );
                $this->assertCount( 2, $userOptions );
@@ -231,7 +240,7 @@
                $loggerMock->expects( $this->once() )
                        ->method( 'error' );
 
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'areDependenciesMet', 'getLogger' ] )
                        ->getMock();
@@ -242,7 +251,7 @@
                        ->method( 'getLogger' )
                        ->will( $this->returnValue( $loggerMock ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                PopupsHooks::onBeforePageDisplay( $outPageMock, $skinMock );
        }
 
@@ -279,7 +288,7 @@
                        ->method( 'addModules' )
                        ->with( [ 'ext.popups' ] );
 
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->setMethods( [ 'areDependenciesMet', 
'isBetaFeatureEnabled', 'shouldSendModuleToUser' ] )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -296,7 +305,7 @@
                        ->method( 'shouldSendModuleToUser' )
                        ->will( $this->returnValue( $shouldSendModuleToUser ) );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
                PopupsHooks::onBeforePageDisplay( $outPageMock, $skinMock );
        }
 
@@ -314,7 +323,7 @@
                        ->method( 'getUser' )
                        ->willReturn( $user );
 
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContext::class )
                        ->setMethods( [ 'shouldSendModuleToUser', 
'conflictsWithNavPopupsGadget' ] )
                        ->disableOriginalConstructor()
                        ->getMock();
@@ -327,7 +336,7 @@
                        ->with( $user )
                        ->willReturn( false );
 
-               PopupsContextTestWrapper::injectTestInstance( $contextMock );
+               $this->overrideContext( $contextMock );
 
                $vars = [];
 
diff --git a/tests/phpunit/UserPreferencesChangeHandlerTest.php 
b/tests/phpunit/UserPreferencesChangeHandlerTest.php
index e393359..58af8bd 100644
--- a/tests/phpunit/UserPreferencesChangeHandlerTest.php
+++ b/tests/phpunit/UserPreferencesChangeHandlerTest.php
@@ -18,7 +18,6 @@
  * @file
  * @ingroup extensions
  */
-require_once 'PopupsContextTestWrapper.php';
 use Popups\PopupsContext;
 use Popups\UserPreferencesChangeHandler;
 
@@ -30,18 +29,13 @@
  */
 class UserPreferencesChangeHandlerTest extends MediaWikiTestCase {
 
-       protected function tearDown() {
-               PopupsContextTestWrapper::resetTestInstance();
-               parent::tearDown();
-       }
-
        /**
         * @covers ::handle
         * @covers ::__construct
         * @dataProvider provideDataForEventHandling
         */
        public function testEventHandling( $oldOption, $newOption, 
$expectedMethodCallsCount ) {
-               $contextMock = $this->getMockBuilder( 
PopupsContextTestWrapper::class )
+               $contextMock = $this->getMockBuilder( PopupsContexts::class )
                        ->disableOriginalConstructor()
                        ->setMethods( [ 'logUserDisabledPagePreviewsEvent' ] )
                        ->getMock();

-- 
To view, visit https://gerrit.wikimedia.org/r/366874
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie27e28bb07aebe01014848c290369b1b1f098e9b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Pmiazga <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to