mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-23 22:44:42 +00:00
tests: Make PHPUnit data providers static
Initally used a new sniff with autofix (T333745) Bug: T332865 Change-Id: Id40d7df5f9d380aca50ce4c15bbf83897333ecc5
This commit is contained in:
parent
d692bf34bb
commit
fc84a35180
|
@ -18,7 +18,7 @@ class ApiCoreThankUnitTest extends ApiTestCase {
|
|||
return new ApiCoreThank( new ApiMain(), 'thank' );
|
||||
}
|
||||
|
||||
private function createBlock( $options ) {
|
||||
private static function createBlock( $options ) {
|
||||
$options = array_merge( [
|
||||
'address' => 'Test user',
|
||||
'by' => new UserIdentityValue( 1, 'TestUser' ),
|
||||
|
@ -34,7 +34,30 @@ class ApiCoreThankUnitTest extends ApiTestCase {
|
|||
* @covers \MediaWiki\Extension\Thanks\ApiThank::dieOnBadUser
|
||||
* @covers \MediaWiki\Extension\Thanks\ApiThank::dieOnUserBlockedFromThanks
|
||||
*/
|
||||
public function testDieOnBadUser( $user, $dieMethod, $expectedError ) {
|
||||
public function testDieOnBadUser(
|
||||
$mockAnon,
|
||||
$mockPingLimited,
|
||||
$mockBlock,
|
||||
$dieMethod,
|
||||
$expectedError
|
||||
) {
|
||||
$user = $this->createMock( User::class );
|
||||
if ( $mockAnon !== null ) {
|
||||
$user->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->willReturn( $mockAnon );
|
||||
}
|
||||
if ( $mockPingLimited !== null ) {
|
||||
$user->expects( $this->once() )
|
||||
->method( 'pingLimiter' )
|
||||
->willReturn( $mockPingLimited );
|
||||
}
|
||||
if ( $mockBlock !== null ) {
|
||||
$user->expects( $this->once() )
|
||||
->method( 'getBlock' )
|
||||
->willReturn( $mockBlock );
|
||||
}
|
||||
|
||||
$module = $this->getModule();
|
||||
$method = new ReflectionMethod( $module, $dieMethod );
|
||||
$method->setAccessible( true );
|
||||
|
@ -48,67 +71,37 @@ class ApiCoreThankUnitTest extends ApiTestCase {
|
|||
$this->assertTrue( true );
|
||||
}
|
||||
|
||||
public function provideDieOnBadUser() {
|
||||
$testCases = [];
|
||||
|
||||
$mockUser = $this->createMock( User::class );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->willReturn( true );
|
||||
|
||||
$testCases[ 'anon' ] = [
|
||||
$mockUser,
|
||||
public static function provideDieOnBadUser() {
|
||||
return [
|
||||
'anon' => [
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
'dieOnBadUser',
|
||||
'notloggedin'
|
||||
];
|
||||
|
||||
$mockUser = $this->createMock( User::class );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->willReturn( false );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'pingLimiter' )
|
||||
->willReturn( true );
|
||||
|
||||
$testCases[ 'ping' ] = [
|
||||
$mockUser,
|
||||
],
|
||||
'ping' => [
|
||||
false,
|
||||
true,
|
||||
null,
|
||||
'dieOnBadUser',
|
||||
'ratelimited'
|
||||
];
|
||||
|
||||
$mockUser = $this->createMock( User::class );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'isAnon' )
|
||||
->willReturn( false );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'pingLimiter' )
|
||||
->willReturn( false );
|
||||
|
||||
$mockUser = $this->createMock( User::class );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'getBlock' )
|
||||
->willReturn( $this->createBlock( [] ) );
|
||||
|
||||
$testCases[ 'sitewide blocked' ] = [
|
||||
$mockUser,
|
||||
],
|
||||
'sitewide blocked' => [
|
||||
null,
|
||||
null,
|
||||
self::createBlock( [] ),
|
||||
'dieOnUserBlockedFromThanks',
|
||||
'blocked'
|
||||
];
|
||||
|
||||
$mockUser = $this->createMock( User::class );
|
||||
$mockUser->expects( $this->once() )
|
||||
->method( 'getBlock' )
|
||||
->willReturn(
|
||||
$this->createBlock( [ 'sitewide' => false ] )
|
||||
);
|
||||
|
||||
$testCases[ 'partial blocked' ] = [
|
||||
$mockUser,
|
||||
],
|
||||
'partial blocked' => [
|
||||
null,
|
||||
null,
|
||||
self::createBlock( [ 'sitewide' => false ] ),
|
||||
'dieOnUserBlockedFromThanks',
|
||||
false
|
||||
],
|
||||
];
|
||||
|
||||
return $testCases;
|
||||
}
|
||||
|
||||
// @todo test userAlreadySentThanksForRevision
|
||||
|
|
Loading…
Reference in a new issue