Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
use MediaWiki\Permissions\PermissionStatus;
|
|
|
|
/**
|
|
* @covers PermissionsError
|
|
*/
|
|
class PermissionsErrorTest extends MediaWikiIntegrationTestCase {
|
|
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
$this->setGroupPermissions( '*', 'testpermission', true );
|
|
}
|
|
|
|
public static function provideConstruction() {
|
|
$status = new PermissionStatus();
|
|
$status->error( 'cat', 1, 2 );
|
|
$status->warning( 'dog', 3, 4 );
|
|
$expected = [ [ 'cat', 1, 2 ], [ 'dog', 3, 4 ] ];
|
|
yield [ null, $status, $expected ];
|
|
yield [ 'testpermission', $status, $expected ];
|
|
|
|
yield [ 'testpermission', [], [ [ 'badaccess-groups', Message::listParam( [ '*' ], 'comma' ), 1 ] ] ];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideConstruction
|
|
*/
|
|
public function testConstruction( $permission, $errors, $expected ) {
|
|
$e = new PermissionsError( $permission, $errors );
|
|
$this->assertEquals( $permission, $e->permission );
|
|
$this->assertArrayEquals( $expected, $e->errors );
|
|
}
|
|
|
|
public static function provideInvalidConstruction() {
|
|
yield [ null, null ];
|
|
yield [ null, [] ];
|
|
yield [ null, new PermissionStatus() ];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideInvalidConstruction
|
|
*/
|
|
public function testInvalidConstruction( $permission, $errors ) {
|
|
$this->expectException( InvalidArgumentException::class );
|
|
$e = new PermissionsError( $permission, $errors );
|
|
}
|
|
}
|