From 7b2fb55711d12ca5e313349c0db49e02d5ee6f1b Mon Sep 17 00:00:00 2001 From: mainframe98 Date: Sun, 8 Sep 2019 12:28:55 +0200 Subject: [PATCH] Mark passing non ObjectFactory spec to ApiModuleManager as deprecated 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 | 3 +-- tests/phpunit/includes/api/ApiMainTest.php | 21 +++++++++++-------- .../includes/api/ApiModuleManagerTest.php | 6 ++++++ .../includes/api/format/ApiFormatBaseTest.php | 18 ++++++++++------ 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/includes/api/ApiModuleManager.php b/includes/api/ApiModuleManager.php index 3d4ccaf0fa..8d5a82b92e 100644 --- a/includes/api/ApiModuleManager.php +++ b/includes/api/ApiModuleManager.php @@ -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 ) ) { diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index 1e2135b836..3a3f5f115b 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -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; diff --git a/tests/phpunit/includes/api/ApiModuleManagerTest.php b/tests/phpunit/includes/api/ApiModuleManagerTest.php index 7747c70618..e99e9a9fe1 100644 --- a/tests/phpunit/includes/api/ApiModuleManagerTest.php +++ b/tests/phpunit/includes/api/ApiModuleManagerTest.php @@ -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 ); diff --git a/tests/phpunit/includes/api/format/ApiFormatBaseTest.php b/tests/phpunit/includes/api/format/ApiFormatBaseTest.php index 03359f806b..286e8a84ce 100644 --- a/tests/phpunit/includes/api/format/ApiFormatBaseTest.php +++ b/tests/phpunit/includes/api/format/ApiFormatBaseTest.php @@ -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(); -- 2.20.1