Prefer the …::class feature over hard-coded strings in all tests

The codebase already used the …::class feature in many places. So this
is more for consistency than anything. The …::class feature makes it
much easier to do refactoring in the future.

Note this patch is exclusively touching tests. That should make it
relatively easy to review this. As long as the CI is fine with it, it
should be ok. Right? ;-)

Change-Id: I4d2adee76b4adbc83b2061161fd4e863ba833fcb
This commit is contained in:
Thiemo Kreuz 2019-02-19 11:35:54 +01:00 committed by Thiemo Kreuz (WMDE)
parent 2e45f12018
commit c36d2bd0e8
16 changed files with 50 additions and 50 deletions

View file

@ -6,7 +6,7 @@
class EchoAttributeManagerTest extends MediaWikiTestCase {
public function testNewFromGlobalVars() {
$this->assertInstanceOf( 'EchoAttributeManager', EchoAttributeManager::newFromGlobalVars() );
$this->assertInstanceOf( EchoAttributeManager::class, EchoAttributeManager::newFromGlobalVars() );
}
public static function getUserLocatorsProvider() {
@ -479,7 +479,7 @@ class EchoAttributeManagerTest extends MediaWikiTestCase {
* Mock object of User
*/
protected function mockUser() {
$user = $this->getMockBuilder( 'User' )
$user = $this->getMockBuilder( User::class )
->disableOriginalConstructor()
->getMock();
$user->expects( $this->any() )

View file

@ -28,7 +28,7 @@ class BundlerTest extends MediaWikiTestCase {
}
private function createNotificationForBundling( $bundleHash, $timestamp, $readStatus ) {
$mock = $this->getMockBuilder( 'EchoNotification' )
$mock = $this->getMockBuilder( EchoNotification::class )
->disableOriginalConstructor()
->setMethods( [
'getBundlingKey',

View file

@ -31,7 +31,7 @@ class ContainmentSetTest extends MediaWikiTestCase {
$inner = [ 'bing', 'bang' ];
// We use a mock instead of the real thing for the $this->once() assertion
// verifying that the cache doesn't just keep asking the inner object
$list = $this->getMockBuilder( 'EchoArrayList' )
$list = $this->getMockBuilder( EchoArrayList::class )
->disableOriginalConstructor()
->getMock();
$list->expects( $this->once() )

View file

@ -878,7 +878,7 @@ TEXT
* @dataProvider provider_extractSections
*/
public function testExtractSections( $content, $result ) {
$discussionParser = TestingAccessWrapper::newFromClass( 'EchoDiscussionParser' );
$discussionParser = TestingAccessWrapper::newFromClass( EchoDiscussionParser::class );
$sections = $discussionParser->extractSections( $content );
$this->assertEquals( $result, $sections );
@ -979,7 +979,7 @@ TEXT
// store diff in some local cache var, to circumvent
// EchoDiscussionParser::getChangeInterpretationForRevision's attempt to
// retrieve parent revision from DB
$class = new ReflectionClass( 'EchoDiscussionParser' );
$class = new ReflectionClass( EchoDiscussionParser::class );
$property = $class->getProperty( 'revisionInterpretationCache' );
$property->setAccessible( true );
$property->setValue( [ $revision->getId() => $output ] );
@ -1698,7 +1698,7 @@ TEXT
'anonymousUsers' => [ '127.0.0.1' ],
];
$discussionParser = TestingAccessWrapper::newFromClass( 'EchoDiscussionParser' );
$discussionParser = TestingAccessWrapper::newFromClass( EchoDiscussionParser::class );
$this->assertEquals( 4, $discussionParser->getOverallUserMentionsCount( $userMentions ) );
}
@ -1730,7 +1730,7 @@ TEXT
*/
public function testGetUserMentions( $userLinks, $expectedUserMentions, $agent ) {
$title = Title::newFromText( 'Test' );
$discussionParser = TestingAccessWrapper::newFromClass( 'EchoDiscussionParser' );
$discussionParser = TestingAccessWrapper::newFromClass( EchoDiscussionParser::class );
$this->assertEquals( $expectedUserMentions, $discussionParser->getUserMentions( $title, $agent, $userLinks ) );
}
@ -1775,7 +1775,7 @@ TEXT
] );
$title = Title::newFromText( 'Test' );
$discussionParser = TestingAccessWrapper::newFromClass( 'EchoDiscussionParser' );
$discussionParser = TestingAccessWrapper::newFromClass( EchoDiscussionParser::class );
$this->assertEquals( 4, $discussionParser->getOverallUserMentionsCount( $discussionParser->getUserMentions( $title, 1, $userLinks ) ) );
}

View file

@ -10,7 +10,7 @@ class MWEchoDbFactoryTest extends MediaWikiTestCase {
public function testNewFromDefault() {
$db = MWEchoDbFactory::newFromDefault();
$this->assertInstanceOf( 'MWEchoDbFactory', $db );
$this->assertInstanceOf( MWEchoDbFactory::class, $db );
return $db;
}
@ -27,7 +27,7 @@ class MWEchoDbFactoryTest extends MediaWikiTestCase {
* @depends testNewFromDefault
*/
public function testGetLB( MWEchoDbFactory $db ) {
$reflection = new ReflectionClass( 'MWEchoDbFactory' );
$reflection = new ReflectionClass( MWEchoDbFactory::class );
$method = $reflection->getMethod( 'getLB' );
$method->setAccessible( true );
$this->assertInstanceOf( ILoadBalancer::class, $method->invoke( $db ) );

View file

@ -32,7 +32,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
$this->assertTrue( $exception, "Got exception" );
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
$this->assertInstanceOf( 'MWEchoNotifUser', $notifUser );
$this->assertInstanceOf( MWEchoNotifUser::class, $notifUser );
}
public function testGetEmailFormat() {
@ -113,7 +113,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
$dbResult += [
'markRead' => true
];
$gateway = $this->getMockBuilder( 'EchoUserNotificationGateway' )
$gateway = $this->getMockBuilder( EchoUserNotificationGateway::class )
->disableOriginalConstructor()
->getMock();
$gateway->expects( $this->any() )
@ -130,7 +130,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
}
public function mockEchoNotificationMapper( array $result = [] ) {
$mapper = $this->getMockBuilder( 'EchoNotificationMapper' )
$mapper = $this->getMockBuilder( EchoNotificationMapper::class )
->disableOriginalConstructor()
->getMock();
$mapper->expects( $this->any() )
@ -147,7 +147,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
}
protected function mockEchoNotification() {
$notification = $this->getMockBuilder( 'EchoNotification' )
$notification = $this->getMockBuilder( EchoNotification::class )
->disableOriginalConstructor()
->getMock();
$notification->expects( $this->any() )
@ -158,7 +158,7 @@ class MWEchoNotifUserTest extends MediaWikiTestCase {
}
protected function mockEchoEvent() {
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )

View file

@ -21,7 +21,7 @@ class EchoUserLocatorTest extends MediaWikiTestCase {
}
wfGetDB( DB_MASTER )->insert( 'watchlist', $rows, __METHOD__ );
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -264,7 +264,7 @@ class EchoUserLocatorTest extends MediaWikiTestCase {
}
protected function mockEchoEvent() {
return $this->getMockBuilder( 'EchoEvent' )
return $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
}

View file

@ -54,7 +54,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
[ [ 123 ] ],
// event user locator config
[
[ 'EchoUserLocator::locateFromEventExtra', [ 'other-user' ] ],
[ [ EchoUserLocator::class, 'locateFromEventExtra' ], [ 'other-user' ] ],
],
// additional setup
function ( $test, $event ) {
@ -79,7 +79,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
],
] );
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -97,7 +97,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
public function testEvaluateUserLocatorPassesParameters() {
$test = $this;
$callback = function ( $event, $firstOption, $secondOption ) use ( $test ) {
$test->assertInstanceOf( 'EchoEvent', $event );
$test->assertInstanceOf( EchoEvent::class, $event );
$test->assertEquals( 'first', $firstOption );
$test->assertEquals( 'second', $secondOption );
@ -157,7 +157,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
],
] );
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -173,7 +173,7 @@ class NotificationControllerTest extends MediaWikiTestCase {
}
public function testDoesNotDeliverDisabledEvent() {
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )

View file

@ -65,7 +65,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase {
* Mock object of User
*/
protected function mockUser( $group = 'echo_group' ) {
$user = $this->getMockBuilder( 'User' )
$user = $this->getMockBuilder( User::class )
->disableOriginalConstructor()
->getMock();
$user->expects( $this->any() )
@ -85,7 +85,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase {
* Mock object of MWEchoDbFactory
*/
protected function mockMWEchoDbFactory( array $dbResult = [] ) {
$dbFactory = $this->getMockBuilder( 'MWEchoDbFactory' )
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
->disableOriginalConstructor()
->getMock();
$dbFactory->expects( $this->any() )
@ -106,7 +106,7 @@ class EchoUserNotificationGatewayTest extends MediaWikiTestCase {
'selectRow' => '',
'selectRowCount' => '',
];
$db = $this->getMockBuilder( 'DatabaseMysqli' )
$db = $this->getMockBuilder( DatabaseMysqli::class )
->disableOriginalConstructor()
->getMock();
$db->expects( $this->any() )

View file

@ -102,7 +102,7 @@ class SuppressionMaintenanceTest extends MediaWikiTestCase {
protected static function attachTitleFor( $id, $providedText, $providedNamespace ) {
return function ( $test, $gen ) use ( $id, $providedText, $providedNamespace ) {
$title = $test->getMock( 'Title' );
$title = $test->getMock( Title::class );
$title->expects( $test->any() )
->method( 'getArticleId' )
->will( $test->returnValue( $id ) );

View file

@ -10,7 +10,7 @@ class EchoAbstractMapperTest extends MediaWikiTestCase {
$mapper->attachListener( 'testMethod', 'key_a', function () {
} );
$class = new ReflectionClass( 'EchoAbstractMapperStub' );
$class = new ReflectionClass( EchoAbstractMapperStub::class );
$property = $class->getProperty( 'listeners' );
$property->setAccessible( true );
$listeners = $property->getValue( $mapper );

View file

@ -50,7 +50,7 @@ class EchoEventMapperTest extends MediaWikiTestCase {
)
);
$res = $eventMapper->fetchById( 1 );
$this->assertInstanceOf( 'EchoEvent', $res );
$this->assertInstanceOf( EchoEvent::class, $res );
}
/**
@ -72,7 +72,7 @@ class EchoEventMapperTest extends MediaWikiTestCase {
* Mock object of EchoEvent
*/
protected function mockEchoEvent() {
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -86,7 +86,7 @@ class EchoEventMapperTest extends MediaWikiTestCase {
* Mock object of MWEchoDbFactory
*/
protected function mockMWEchoDbFactory( $dbResult ) {
$dbFactory = $this->getMockBuilder( 'MWEchoDbFactory' )
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
->disableOriginalConstructor()
->getMock();
$dbFactory->expects( $this->any() )
@ -107,7 +107,7 @@ class EchoEventMapperTest extends MediaWikiTestCase {
'select' => '',
'selectRow' => ''
];
$db = $this->getMockBuilder( 'DatabaseMysqli' )
$db = $this->getMockBuilder( DatabaseMysqli::class )
->disableOriginalConstructor()
->getMock();
$db->expects( $this->any() )

View file

@ -45,7 +45,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
$this->assertInternalType( 'array', $res );
$this->assertNotEmpty( $res );
foreach ( $res as $row ) {
$this->assertInstanceOf( 'EchoNotification', $row );
$this->assertInstanceOf( EchoNotification::class, $row );
}
}
@ -96,7 +96,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
$this->assertInternalType( 'array', $res );
$this->assertNotEmpty( $res );
foreach ( $res as $row ) {
$this->assertInstanceOf( 'EchoNotification', $row );
$this->assertInstanceOf( EchoNotification::class, $row );
}
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [] ) );
@ -129,7 +129,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
];
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) );
$row = $notifMapper->fetchNewestByUserBundleHash( User::newFromId( 1 ), 'testdisplayhash' );
$this->assertInstanceOf( 'EchoNotification', $row );
$this->assertInstanceOf( EchoNotification::class, $row );
}
public function testFetchByUserOffset() {
@ -157,12 +157,12 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
];
$notifMapper = new EchoNotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) );
$row = $notifMapper->fetchByUserOffset( User::newFromId( 1 ), 500 );
$this->assertInstanceOf( 'EchoNotification', $row );
$this->assertInstanceOf( EchoNotification::class, $row );
}
public function testDeleteByUserEventOffset() {
$this->setMwGlobals( [ 'wgUpdateRowsPerQuery' => 4 ] );
$mockDb = $this->getMockBuilder( 'DatabaseMysqli' )
$mockDb = $this->getMockBuilder( DatabaseMysqli::class )
->disableOriginalConstructor()
->getMock();
$mockDb->expects( $this->any() )
@ -197,7 +197,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
* Mock object of User
*/
protected function mockUser() {
$user = $this->getMockBuilder( 'User' )
$user = $this->getMockBuilder( User::class )
->disableOriginalConstructor()
->getMock();
$user->expects( $this->any() )
@ -217,7 +217,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
* Mock object of EchoNotification
*/
protected function mockEchoNotification() {
$event = $this->getMockBuilder( 'EchoNotification' )
$event = $this->getMockBuilder( EchoNotification::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -233,7 +233,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
*/
protected function mockMWEchoDbFactory( $dbResultOrMockDb ) {
$mockDb = is_array( $dbResultOrMockDb ) ? $this->mockDb( $dbResultOrMockDb ) : $dbResultOrMockDb;
$dbFactory = $this->getMockBuilder( 'MWEchoDbFactory' )
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
->disableOriginalConstructor()
->getMock();
$dbFactory->expects( $this->any() )
@ -255,7 +255,7 @@ class EchoNotificationMapperTest extends MediaWikiTestCase {
'delete' => ''
];
$db = $this->getMockBuilder( 'DatabaseMysqli' )
$db = $this->getMockBuilder( DatabaseMysqli::class )
->disableOriginalConstructor()
->getMock();
$db->expects( $this->any() )

View file

@ -53,7 +53,7 @@ class EchoTargetPageMapperTest extends MediaWikiTestCase {
* Mock object of MWEchoDbFactory
*/
protected function mockMWEchoDbFactory( $dbResult ) {
$dbFactory = $this->getMockBuilder( 'MWEchoDbFactory' )
$dbFactory = $this->getMockBuilder( MWEchoDbFactory::class )
->disableOriginalConstructor()
->getMock();
$dbFactory->expects( $this->any() )
@ -74,7 +74,7 @@ class EchoTargetPageMapperTest extends MediaWikiTestCase {
'select' => '',
'delete' => ''
];
$db = $this->getMockBuilder( 'DatabaseMysqli' )
$db = $this->getMockBuilder( DatabaseMysqli::class )
->disableOriginalConstructor()
->getMock();
$db->expects( $this->any() )

View file

@ -9,14 +9,14 @@ class EchoNotificationTest extends MediaWikiTestCase {
$row = $this->mockNotificationRow() + $this->mockEventRow();
$notif = EchoNotification::newFromRow( (object)$row );
$this->assertInstanceOf( 'EchoNotification', $notif );
$this->assertInstanceOf( EchoNotification::class, $notif );
// getReadTimestamp() should return null
$this->assertNull( $notif->getReadTimestamp() );
$this->assertEquals(
$notif->getTimestamp(),
wfTimestamp( TS_MW, $row['notification_timestamp'] )
);
$this->assertInstanceOf( 'EchoEvent', $notif->getEvent() );
$this->assertInstanceOf( EchoEvent::class, $notif->getEvent() );
$this->assertNull( $notif->getTargetPages() );
// Provide a read timestamp
@ -33,7 +33,7 @@ class EchoNotificationTest extends MediaWikiTestCase {
] );
$this->assertNotEmpty( $notif->getTargetPages() );
foreach ( $notif->getTargetPages() as $targetPage ) {
$this->assertInstanceOf( 'EchoTargetPage', $targetPage );
$this->assertInstanceOf( EchoTargetPage::class, $targetPage );
}
}

View file

@ -14,7 +14,7 @@ class EchoTargetPageTest extends MediaWikiTestCase {
);
$this->assertInstanceOf(
'EchoTargetPage',
EchoTargetPage::class,
EchoTargetPage::create(
$this->mockTitle( 1 ),
$this->mockEchoEvent()
@ -28,7 +28,7 @@ class EchoTargetPageTest extends MediaWikiTestCase {
'etp_event' => 3
];
$obj = EchoTargetPage::newFromRow( $row );
$this->assertInstanceOf( 'EchoTargetPage', $obj );
$this->assertInstanceOf( EchoTargetPage::class, $obj );
return $obj;
}
@ -62,7 +62,7 @@ class EchoTargetPageTest extends MediaWikiTestCase {
* Mock object of Title
*/
protected function mockTitle( $pageId ) {
$event = $this->getMockBuilder( 'Title' )
$event = $this->getMockBuilder( Title::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )
@ -76,7 +76,7 @@ class EchoTargetPageTest extends MediaWikiTestCase {
* Mock object of EchoEvent
*/
protected function mockEchoEvent( $eventId = 1 ) {
$event = $this->getMockBuilder( 'EchoEvent' )
$event = $this->getMockBuilder( EchoEvent::class )
->disableOriginalConstructor()
->getMock();
$event->expects( $this->any() )