Merge "Cleanup live update feature flag and FilterWrapperWidget"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiTestCase.php
index 7e1f9d8..f1ff947 100644 (file)
@@ -3,6 +3,8 @@
 abstract class ApiTestCase extends MediaWikiLangTestCase {
        protected static $apiUrl;
 
+       protected static $errorFormatter = null;
+
        /**
         * @var ApiTestContext
         */
@@ -196,8 +198,31 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
                return $data[0]['tokens'];
        }
 
+       protected static function getErrorFormatter() {
+               if ( self::$errorFormatter === null ) {
+                       self::$errorFormatter = new ApiErrorFormatter(
+                               new ApiResult( false ),
+                               Language::factory( 'en' ),
+                               'none'
+                       );
+               }
+               return self::$errorFormatter;
+       }
+
+       public static function apiExceptionHasCode( ApiUsageException $ex, $code ) {
+               return (bool)array_filter(
+                       self::getErrorFormatter()->arrayFromStatus( $ex->getStatusValue() ),
+                       function ( $e ) use ( $code ) {
+                               return is_array( $e ) && $e['code'] === $code;
+                       }
+               );
+       }
+
+       /**
+        * @coversNothing
+        */
        public function testApiTestGroup() {
-               $groups = PHPUnit_Util_Test::getGroups( get_class( $this ) );
+               $groups = PHPUnit_Util_Test::getGroups( static::class );
                $constraint = PHPUnit_Framework_Assert::logicalOr(
                        $this->contains( 'medium' ),
                        $this->contains( 'large' )