jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/405407 )
Change subject: ConfigFactory: Improve error message for invalid callback ...................................................................... ConfigFactory: Improve error message for invalid callback Getting the following error for an invalid callback in extension registration is not helpful: Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Invalid callback provided' in /includes/config/ConfigFactory.php:108 Changed message to Invalid callback '$1' provided Added a test case for the instanceof part of the if Change-Id: I425e2607b651c666336289c2c0d93730bb6312ed --- M includes/config/ConfigFactory.php M tests/phpunit/includes/config/ConfigFactoryTest.php 2 files changed, 15 insertions(+), 1 deletion(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/config/ConfigFactory.php b/includes/config/ConfigFactory.php index e175765..2c7afda 100644 --- a/includes/config/ConfigFactory.php +++ b/includes/config/ConfigFactory.php @@ -105,7 +105,12 @@ */ public function register( $name, $callback ) { if ( !is_callable( $callback ) && !( $callback instanceof Config ) ) { - throw new InvalidArgumentException( 'Invalid callback provided' ); + if ( is_array( $callback ) ) { + $callback = '[ ' . implode( ', ', $callback ) . ' ]'; + } elseif ( is_object( $callback ) ) { + $callback = 'instanceof ' . get_class( $callback ); + } + throw new InvalidArgumentException( 'Invalid callback \'' . $callback . '\' provided' ); } unset( $this->configs[$name] ); diff --git a/tests/phpunit/includes/config/ConfigFactoryTest.php b/tests/phpunit/includes/config/ConfigFactoryTest.php index 608d8d9..c0e51d7 100644 --- a/tests/phpunit/includes/config/ConfigFactoryTest.php +++ b/tests/phpunit/includes/config/ConfigFactoryTest.php @@ -25,6 +25,15 @@ /** * @covers ConfigFactory::register */ + public function testRegisterInvalidInstance() { + $factory = new ConfigFactory(); + $this->setExpectedException( InvalidArgumentException::class ); + $factory->register( 'invalidInstance', new stdClass ); + } + + /** + * @covers ConfigFactory::register + */ public function testRegisterInstance() { $config = GlobalVarConfig::newInstance(); $factory = new ConfigFactory(); -- To view, visit https://gerrit.wikimedia.org/r/405407 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I425e2607b651c666336289c2c0d93730bb6312ed Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Umherirrender <umherirrender_de...@web.de> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits