Mark passing non ObjectFactory spec to ApiModuleManager as deprecated
authormainframe98 <k.s.werf@hotmail.com>
Sun, 8 Sep 2019 10:28:55 +0000 (12:28 +0200)
committermainframe98 <k.s.werf@hotmail.com>
Mon, 9 Sep 2019 19:59:03 +0000 (21:59 +0200)
With Iee04afc27283547dd68d6db93f44ac2e0ebf1258, passing both the $class
and $factory parameter is deprecated in favor of just passing an
ObjectFactory spec as the third parameter.

Change-Id: I7b04d82c9daba52f5dc5e6c528739336279c7550

includes/api/ApiModuleManager.php
tests/phpunit/includes/api/ApiMainTest.php
tests/phpunit/includes/api/ApiModuleManagerTest.php
tests/phpunit/includes/api/format/ApiFormatBaseTest.php

index 3d4ccaf..8d5a82b 100644 (file)
@@ -114,8 +114,7 @@ class ApiModuleManager extends ContextSource {
                        ];
 
                        if ( is_callable( $factory ) ) {
-                               // Uncomment this when callers are cleaned up:
-                               // wfDeprecated( __METHOD__ . ' with $class and $factory', '1.34' );
+                               wfDeprecated( __METHOD__ . ' with $class and $factory', '1.34' );
                                $spec['factory'] = $factory;
                        }
                } elseif ( !is_array( $spec ) ) {
index 1e2135b..3a3f5f1 100644 (file)
@@ -242,11 +242,12 @@ class ApiMainTest extends ApiTestCase {
                $mock->method( 'needsToken' )->willReturn( true );
 
                $api = new ApiMain( new FauxRequest( [ 'action' => 'testmodule' ] ) );
-               $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
-                       function () use ( $mock ) {
+               $api->getModuleManager()->addModule( 'testmodule', 'action', [
+                       'class' => get_class( $mock ),
+                       'factory' => function () use ( $mock ) {
                                return $mock;
                        }
-               );
+               );
                $api->execute();
        }
 
@@ -260,11 +261,12 @@ class ApiMainTest extends ApiTestCase {
                $mock->method( 'mustBePosted' )->willReturn( false );
 
                $api = new ApiMain( new FauxRequest( [ 'action' => 'testmodule' ] ) );
-               $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
-                       function () use ( $mock ) {
+               $api->getModuleManager()->addModule( 'testmodule', 'action', [
+                       'class' => get_class( $mock ),
+                       'factory' => function () use ( $mock ) {
                                return $mock;
                        }
-               );
+               );
                $api->execute();
        }
 
@@ -309,11 +311,12 @@ class ApiMainTest extends ApiTestCase {
                $req->setRequestURL( "http://localhost" );
 
                $api = new ApiMain( $req );
-               $api->getModuleManager()->addModule( 'testmodule', 'action', get_class( $mock ),
-                       function () use ( $mock ) {
+               $api->getModuleManager()->addModule( 'testmodule', 'action', [
+                       'class' => get_class( $mock ),
+                       'factory' => function () use ( $mock ) {
                                return $mock;
                        }
-               );
+               );
 
                $wrapper = TestingAccessWrapper::newFromObject( $api );
                $wrapper->mInternalMode = false;
index 7747c70..e99e9a9 100644 (file)
@@ -79,6 +79,12 @@ class ApiModuleManagerTest extends MediaWikiTestCase {
         * @dataProvider addModuleProvider
         */
        public function testAddModule( $name, $group, $spec, $factory ) {
+               if ( $factory ) {
+                       $this->hideDeprecated(
+                               ApiModuleManager::class . '::addModule with $class and $factory'
+                       );
+               }
+
                $moduleManager = $this->getModuleManager();
                $moduleManager->addModule( $name, $group, $spec, $factory );
 
index 03359f8..286e8a8 100644 (file)
@@ -365,13 +365,19 @@ class ApiFormatBaseTest extends ApiFormatTestBase {
                $main = new ApiMain( $context );
                $printer = $this->getMockFormatter( $main, 'mockfm' );
                $mm = $printer->getMain()->getModuleManager();
-               $mm->addModule( 'mockfm', 'format', ApiFormatBase::class, function () {
-                       return $mock;
-               } );
-               if ( $registerNonHtml ) {
-                       $mm->addModule( 'mock', 'format', ApiFormatBase::class, function () {
+               $mm->addModule( 'mockfm', 'format', [
+                       'class' => ApiFormatBase::class,
+                       'factory' => function () {
                                return $mock;
-                       } );
+                       }
+               ] );
+               if ( $registerNonHtml ) {
+                       $mm->addModule( 'mock', 'format', [
+                               'class' => ApiFormatBase::class,
+                               'factory' => function () {
+                                       return $mock;
+                               }
+                       ] );
                }
 
                $printer->initPrinter();