services: Do not use deprecated ReflectionType::__toString() in tests
[lhc/web/wiklou.git] / tests / phpunit / includes / MediaWikiServicesTest.php
index 1cd40ed..d34ba0a 100644 (file)
@@ -11,7 +11,7 @@ use Wikimedia\Services\ServiceDisabledException;
  * @group MediaWiki
  */
 class MediaWikiServicesTest extends MediaWikiTestCase {
-       private $deprecatedServices = [ 'CryptRand' ];
+       private $deprecatedServices = [];
 
        /**
         * @return Config
@@ -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;
        }
@@ -364,7 +373,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
                } ) );
 
                $sortedNames = $names;
-               sort( $sortedNames );
+               natcasesort( $sortedNames );
 
                $this->assertSame( $sortedNames, $names,
                        'Please keep service getters sorted alphabetically' );