abstract class ApiTestCase extends MediaWikiLangTestCase {
protected static $apiUrl;
+ protected static $errorFormatter = null;
+
/**
* @var ApiTestContext
*/
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' )