tests: Replace assertEmpty with assertSame

assertSame avoids use of loose comparisons and
allows to check the expected type

Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
This commit is contained in:
Umherirrender 2022-11-24 23:22:36 +01:00
parent 03835eb843
commit c6fecd5ab0
14 changed files with 30 additions and 30 deletions

View file

@ -13,7 +13,6 @@
<exclude name="MediaWiki.Commenting.PropertyDocumentation.WrongStyle" /> <exclude name="MediaWiki.Commenting.PropertyDocumentation.WrongStyle" />
<exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" /> <exclude name="MediaWiki.ControlStructures.AssignmentInControlStructures.AssignmentInControlStructures" />
<exclude name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" /> <exclude name="MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName" />
<exclude name="MediaWiki.PHPUnit.AssertEmpty.AssertEmptyUsed" />
<exclude name="MediaWiki.Usage.DbrQueryUsage.DbrQueryFound" /> <exclude name="MediaWiki.Usage.DbrQueryUsage.DbrQueryFound" />
<exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle" /> <exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgTitle" />
<exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgVersion" /> <exclude name="MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgVersion" />

View file

@ -196,7 +196,7 @@ class HtmlTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideExpandAttributesEmpty * @dataProvider provideExpandAttributesEmpty
*/ */
public function testExpandAttributesEmpty( array $attribs ) { public function testExpandAttributesEmpty( array $attribs ) {
$this->assertEmpty( Html::expandAttributes( $attribs ) ); $this->assertSame( '', Html::expandAttributes( $attribs ) );
} }
public function provideExpandAttributesClass() { public function provideExpandAttributesClass() {

View file

@ -414,7 +414,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
$this->overrideUserPermissions( $this->user, [ 'edit' ] ); $this->overrideUserPermissions( $this->user, [ 'edit' ] );
$this->assertEmpty( $permissionManager->getPermissionErrors( 'edit', $this->user, $title ) ); $this->assertSame( [], $permissionManager->getPermissionErrors( 'edit', $this->user, $title ) );
$this->assertTrue( $permissionManager->userCan( 'edit', $this->user, $title ) ); $this->assertTrue( $permissionManager->userCan( 'edit', $this->user, $title ) );
} }
@ -444,7 +444,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase {
$title $title
) )
); );
$this->assertEmpty( $this->assertSame(
[],
$permissionManager->getPermissionErrors( $permissionManager->getPermissionErrors(
'edit', 'edit',
$user, $user,

View file

@ -242,7 +242,7 @@ class ContributionsLookupTest extends MediaWikiIntegrationTestCase {
$segment0 = $segment0 =
$contributionsLookup->getContributions( $target, 10, self::$performer, '', 'not-a-tag' ); $contributionsLookup->getContributions( $target, 10, self::$performer, '', 'not-a-tag' );
$this->assertEmpty( $segment0->getRevisions() ); $this->assertSame( [], $segment0->getRevisions() );
} }
/** /**

View file

@ -641,7 +641,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiIntegrationTestCase {
$dataUpdates = $updater->getSecondaryDataUpdates(); $dataUpdates = $updater->getSecondaryDataUpdates();
$this->assertEmpty( $dataUpdates ); $this->assertSame( [], $dataUpdates );
} }
/** /**

View file

@ -2257,7 +2257,7 @@ class TitleTest extends MediaWikiIntegrationTestCase {
$this->getExistingTestPage( $title->getSubpage( 'A' ) ); $this->getExistingTestPage( $title->getSubpage( 'A' ) );
$this->getExistingTestPage( $title->getSubpage( 'B' ) ); $this->getExistingTestPage( $title->getSubpage( 'B' ) );
$this->assertEmpty( $title->getSubpages() ); $this->assertSame( [], $title->getSubpages() );
} }
public function provideNamespaces() { public function provideNamespaces() {

View file

@ -542,7 +542,7 @@ class RecentChangeTest extends MediaWikiIntegrationTestCase {
$errors = $rc->doMarkPatrolled( $errors = $rc->doMarkPatrolled(
$this->mockUserAuthorityWithPermissions( $this->user, [ 'patrol', 'autopatrol' ] ) $this->mockUserAuthorityWithPermissions( $this->user, [ 'patrol', 'autopatrol' ] )
); );
$this->assertEmpty( $errors ); $this->assertSame( [], $errors );
$reloadedRC = RecentChange::newFromId( $rc->getAttribute( 'rc_id' ) ); $reloadedRC = RecentChange::newFromId( $rc->getAttribute( 'rc_id' ) );
$this->assertSame( '1', $reloadedRC->getAttribute( 'rc_patrolled' ) ); $this->assertSame( '1', $reloadedRC->getAttribute( 'rc_patrolled' ) );

View file

@ -44,7 +44,7 @@ class FileBackendGroupIntegrationTest extends MediaWikiIntegrationTestCase {
} }
} }
$this->assertEmpty( $this->assertSame( [],
array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) ); array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) );
$services = $this->getServiceContainer(); $services = $this->getServiceContainer();

View file

@ -764,7 +764,7 @@ class PageStoreTest extends MediaWikiIntegrationTestCase {
$this->getExistingTestPage( $title->getSubpage( 'B' ) ); $this->getExistingTestPage( $title->getSubpage( 'B' ) );
$pageStore = $this->getPageStore(); $pageStore = $this->getPageStore();
$this->assertEmpty( $pageStore->getSubpages( $title, 100 ) ); $this->assertCount( 0, $pageStore->getSubpages( $title, 100 ) );
} }
/** /**

View file

@ -376,7 +376,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
$manager = $this->getManager(); $manager = $this->getManager();
$anon = new UserIdentityValue( 0, 'Anon' ); $anon = new UserIdentityValue( 0, 'Anon' );
$this->assertEmpty( $manager->getUserGroupMemberships( $anon ) ); $this->assertSame( [], $manager->getUserGroupMemberships( $anon ) );
} }
/** /**
@ -386,7 +386,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
$manager = $this->getManager(); $manager = $this->getManager();
$anon = new UserIdentityValue( 0, 'Anon' ); $anon = new UserIdentityValue( 0, 'Anon' );
$this->assertEmpty( $manager->getUserFormerGroups( $anon ) ); $this->assertSame( [], $manager->getUserFormerGroups( $anon ) );
} }
/** /**
@ -837,7 +837,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
'GetAutoPromoteGroups', 'GetAutoPromoteGroups',
function ( User $hookUser, array &$promote ) use ( $user ){ function ( User $hookUser, array &$promote ) use ( $user ){
$this->assertTrue( $user->equals( $hookUser ) ); $this->assertTrue( $user->equals( $hookUser ) );
$this->assertEmpty( $promote ); $this->assertSame( [], $promote );
$promote[] = 'from_hook'; $promote[] = 'from_hook';
} }
); );
@ -859,16 +859,16 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
] ]
] ]
] ); ] );
$this->assertEmpty( $manager->getUserAutopromoteGroups( $this->assertSame( [], $manager->getUserAutopromoteGroups(
$this->getTestUser( [ 'group1' ] )->getUser() ) $this->getTestUser( [ 'group1' ] )->getUser() )
); );
$this->assertEmpty( $manager->getUserAutopromoteGroups( $this->assertSame( [], $manager->getUserAutopromoteGroups(
$this->getTestUser( [ 'group1', 'group2' ] )->getUser() ) $this->getTestUser( [ 'group1', 'group2' ] )->getUser() )
); );
$this->assertEmpty( $manager->getUserAutopromoteGroups( $this->assertSame( [], $manager->getUserAutopromoteGroups(
$this->getTestUser( [ 'group1', 'group3', 'group4' ] )->getUser() ) $this->getTestUser( [ 'group1', 'group3', 'group4' ] )->getUser() )
); );
$this->assertEmpty( $manager->getUserAutopromoteGroups( $this->assertSame( [], $manager->getUserAutopromoteGroups(
$this->getTestUser( [ 'group1', 'group3' ] )->getUser() ) $this->getTestUser( [ 'group1', 'group3' ] )->getUser() )
); );
$this->assertArrayEquals( $this->assertArrayEquals(
@ -886,7 +886,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_ISBOT ] ] 'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_ISBOT ] ]
] ); ] );
$notBot = $this->getTestUser()->getUser(); $notBot = $this->getTestUser()->getUser();
$this->assertEmpty( $manager->getUserAutopromoteGroups( $notBot ) ); $this->assertSame( [], $manager->getUserAutopromoteGroups( $notBot ) );
$bot = $this->getTestUser( [ 'bot' ] )->getUser(); $bot = $this->getTestUser( [ 'bot' ] )->getUser();
$this->assertArrayEquals( [ 'test_autoconfirmed' ], $this->assertArrayEquals( [ 'test_autoconfirmed' ],
$manager->getUserAutopromoteGroups( $bot ) ); $manager->getUserAutopromoteGroups( $bot ) );
@ -901,7 +901,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_BLOCKED ] ] 'Autopromote' => [ 'test_autoconfirmed' => [ APCOND_BLOCKED ] ]
] ); ] );
$nonBlockedUser = $this->getTestUser()->getUser(); $nonBlockedUser = $this->getTestUser()->getUser();
$this->assertEmpty( $manager->getUserAutopromoteGroups( $nonBlockedUser ) ); $this->assertSame( [], $manager->getUserAutopromoteGroups( $nonBlockedUser ) );
$blockedUser = $this->getTestUser( [ 'blocked' ] )->getUser(); $blockedUser = $this->getTestUser( [ 'blocked' ] )->getUser();
$block = new DatabaseBlock(); $block = new DatabaseBlock();
$block->setTarget( $blockedUser ); $block->setTarget( $blockedUser );
@ -948,7 +948,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
$sc = RequestContext::importScopedSession( $sinfo ); // load new context $sc = RequestContext::importScopedSession( $sinfo ); // load new context
$info = $context->exportSession(); $info = $context->exportSession();
$this->assertEmpty( $user->getBlock() ); $this->assertNull( $user->getBlock() );
} }
/** /**
@ -1044,7 +1044,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
->getUserGroupManager( 'TEST_DOMAIN' ); ->getUserGroupManager( 'TEST_DOMAIN' );
$user = $this->getTestUser()->getUser(); $user = $this->getTestUser()->getUser();
$this->expectException( PreconditionException::class ); $this->expectException( PreconditionException::class );
$this->assertEmpty( $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) ); $this->assertSame( [], $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) );
} }
/** /**
@ -1053,7 +1053,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
public function testAddUserToAutopromoteOnceGroupsAnon() { public function testAddUserToAutopromoteOnceGroupsAnon() {
$manager = $this->getManager(); $manager = $this->getManager();
$anon = new UserIdentityValue( 0, 'TEST' ); $anon = new UserIdentityValue( 0, 'TEST' );
$this->assertEmpty( $manager->addUserToAutopromoteOnceGroups( $anon, 'TEST' ) ); $this->assertSame( [], $manager->addUserToAutopromoteOnceGroups( $anon, 'TEST' ) );
} }
/** /**
@ -1063,7 +1063,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
$manager = $this->getManager(); $manager = $this->getManager();
$user = $this->getTestUser()->getUser(); $user = $this->getTestUser()->getUser();
$this->getServiceContainer()->getConfiguredReadOnlyMode()->setReason( 'TEST' ); $this->getServiceContainer()->getConfiguredReadOnlyMode()->setReason( 'TEST' );
$this->assertEmpty( $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) ); $this->assertSame( [], $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) );
} }
/** /**
@ -1072,7 +1072,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
public function testAddUserToAutopromoteOnceGroupsNoGroups() { public function testAddUserToAutopromoteOnceGroupsNoGroups() {
$manager = $this->getManager(); $manager = $this->getManager();
$user = $this->getTestUser()->getUser(); $user = $this->getTestUser()->getUser();
$this->assertEmpty( $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) ); $this->assertSame( [], $manager->addUserToAutopromoteOnceGroups( $user, 'TEST' ) );
} }
/** /**
@ -1090,7 +1090,7 @@ class UserGroupManagerTest extends MediaWikiIntegrationTestCase {
function ( User $hookUser, array $added, array $removed ) use ( $user, &$hookCalled ) { function ( User $hookUser, array $added, array $removed ) use ( $user, &$hookCalled ) {
$this->assertTrue( $user->equals( $hookUser ) ); $this->assertTrue( $user->equals( $hookUser ) );
$this->assertArrayEquals( [ 'autopromoteonce' ], $added ); $this->assertArrayEquals( [ 'autopromoteonce' ], $added );
$this->assertEmpty( $removed ); $this->assertSame( [], $removed );
$hookCalled = true; $hookCalled = true;
} }
); );

View file

@ -34,7 +34,7 @@ class PermissionStatusTest extends MediaWikiUnitTestCase {
$this->assertStatusOK( $status ); $this->assertStatusOK( $status );
$this->assertStatusGood( $status ); $this->assertStatusGood( $status );
$this->assertEmpty( $status->getErrors() ); $this->assertSame( [], $status->getErrors() );
} }
public function testBlock() { public function testBlock() {

View file

@ -386,8 +386,8 @@ class HandlerTest extends \MediaWikiUnitTestCase {
$response = new Response(); $response = new Response();
$handler->applyConditionalResponseHeaders( $response ); $handler->applyConditionalResponseHeaders( $response );
$this->assertEmpty( $response->getHeaderLine( 'ETag' ) ); $this->assertSame( '', $response->getHeaderLine( 'ETag' ) );
$this->assertEmpty( $response->getHeaderLine( 'Last-Modified' ) ); $this->assertSame( '', $response->getHeaderLine( 'Last-Modified' ) );
} }
public function provideCacheControl() { public function provideCacheControl() {

View file

@ -100,7 +100,7 @@ class DnsSrvDiscovererTest extends PHPUnit\Framework\TestCase {
[ 'target' => '.', 'port' => '1', 'pri' => '1', 'weight' => '1' ], [ 'target' => '.', 'port' => '1', 'pri' => '1', 'weight' => '1' ],
] ); ] );
$this->assertEmpty( $dsd->getServers() ); $this->assertSame( [], $dsd->getServers() );
} }
private function mockResolver() { private function mockResolver() {

View file

@ -214,7 +214,7 @@ class MaintenanceParametersTest extends TestCase {
$params->validate(); $params->validate();
$this->assertFalse( $params->hasErrors() ); $this->assertFalse( $params->hasErrors() );
$this->assertEmpty( $params->getErrors() ); $this->assertSame( [], $params->getErrors() );
$this->assertSame( $expectedOptions, $params->getOptions() ); $this->assertSame( $expectedOptions, $params->getOptions() );
$this->assertSame( $expectedArgs, $params->getArgs() ); $this->assertSame( $expectedArgs, $params->getArgs() );