X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiTestCase.php;h=f1ff94751ee6a871c25b66a1f8441fe47983ff1f;hb=4ad03aa11dacd2f443105e43fd1429398aa73bdc;hp=7e1f9d8775ef8fa4ccd9ec3841e78b716a18e62a;hpb=ff2dfbe9420b2ae8a942e1b6c3baa554d4a0a513;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 7e1f9d8775..f1ff94751e 100644 --- a/tests/phpunit/includes/api/ApiTestCase.php +++ b/tests/phpunit/includes/api/ApiTestCase.php @@ -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' )