From eafbacb43ca433141c72c81558ed44ad5ff52694 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Mon, 16 Sep 2019 21:14:07 +0200 Subject: [PATCH] services: Do not use deprecated ReflectionType::__toString() in tests The \MediaWikiServicesTest::provideGetService() PHPUnit data provider method uses the ReflectionType::__toString() method to obtain the return type of service instantiator callables as a string. In PHP 7.4, calling this method generates an E_DEPRECATED notice. The solution is to use ReflectionType::getName() instead, available since PHP 7.1.[1] This patch updates the method to use ReflectionType::getName() if it is available, and fall back to ReflectionType::__toString() otherwise. --- [1] https://github.com/php/php-src/blob/php-7.4.0RC1/UPGRADING#L395 Bug: T233012 Change-Id: I69b97f75795e6c4e005bf1a23fb798f7e52da2fd --- tests/phpunit/includes/MediaWikiServicesTest.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index 8fa0cd60ec..d34ba0a542 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -308,7 +308,16 @@ class MediaWikiServicesTest extends MediaWikiTestCase { throw new MWException( 'All service callbacks must have a return type defined, ' . "none found for $name" ); } - $ret[$name] = [ $name, $fun->getReturnType()->__toString() ]; + + $returnType = $fun->getReturnType(); + + // ReflectionType::__toString() generates deprecation notices in PHP 7.4 and above + // TODO: T228342 - remove this check after MediaWiki only supports PHP 7.1+ + if ( is_callable( [ $returnType, 'getName' ] ) ) { + $ret[$name] = [ $name, $returnType->getName() ]; + } else { + $ret[$name] = [ $name, $fun->getReturnType()->__toString() ]; + } } return $ret; } -- 2.20.1