X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiTestCase.php;h=abef1c920682781101f196930ee5d10e2ee7986f;hb=13bb844fdfff794525e2cb202176ddee3a23ef06;hp=7e1f9d8775ef8fa4ccd9ec3841e78b716a18e62a;hpb=1dd2e07276e1deaf431ddb01c92111038f9e2cd6;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiTestCase.php b/tests/phpunit/includes/api/ApiTestCase.php index 7e1f9d8775..abef1c9206 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,28 @@ 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; + } + ); + } + 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' )