From: Umherirrender Date: Sat, 13 Jan 2018 00:02:09 +0000 (+0100) Subject: Use ::class to resolve class names in tests X-Git-Tag: 1.31.0-rc.0~791 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=45da5815517c408bafed6b3744766860afdcd7b8;p=lhc%2Fweb%2Fwiklou.git Use ::class to resolve class names in tests This helps to find renamed or misspelled classes earlier. Phan will check the class names Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c --- diff --git a/tests/common/TestSetup.php b/tests/common/TestSetup.php index 3733e60f2b..c176a67f7f 100644 --- a/tests/common/TestSetup.php +++ b/tests/common/TestSetup.php @@ -39,7 +39,7 @@ class TestSetup { $wgMainStash = 'hash'; // Use memory job queue $wgJobTypeConf = [ - 'default' => [ 'class' => 'JobQueueMemory', 'order' => 'fifo' ], + 'default' => [ 'class' => JobQueueMemory::class, 'order' => 'fifo' ], ]; $wgUseDatabaseMessages = false; # Set for future resets @@ -47,10 +47,10 @@ class TestSetup { // Assume UTC for testing purposes $wgLocaltimezone = 'UTC'; - $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; + $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class; // Do not bother updating search tables - $wgSearchType = 'SearchEngineDummy'; + $wgSearchType = SearchEngineDummy::class; // Generic MediaWiki\Session\SessionManager configuration for tests // We use CookieSessionProvider because things might be expecting diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 6cf1fcac04..9b5897c89e 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -290,10 +290,10 @@ class ParserTestRunner { // Set up null lock managers $setup['wgLockManagers'] = [ [ 'name' => 'fsLockManager', - 'class' => 'NullLockManager', + 'class' => NullLockManager::class, ], [ 'name' => 'nullLockManager', - 'class' => 'NullLockManager', + 'class' => NullLockManager::class, ] ]; $reset = function () { LockManagerGroup::destroySingletons(); @@ -435,7 +435,7 @@ class ParserTestRunner { return new RepoGroup( [ - 'class' => 'MockLocalRepo', + 'class' => MockLocalRepo::class, 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index ed6479c8dc..fe8c917564 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -260,7 +260,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * which we can't allow, as that would open a new connection for mysql. * Replace with a HashBag. They would not be going to persist anyway. */ - $hashCache = [ 'class' => 'HashBagOStuff', 'reportDupes' => false ]; + $hashCache = [ 'class' => HashBagOStuff::class, 'reportDupes' => false ]; $objectCaches = [ CACHE_DB => $hashCache, CACHE_ACCEL => $hashCache, @@ -273,7 +273,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $defaultOverrides->set( 'ObjectCaches', $objectCaches ); $defaultOverrides->set( 'MainCacheType', CACHE_NONE ); - $defaultOverrides->set( 'JobTypeConf', [ 'default' => [ 'class' => 'JobQueueMemory' ] ] ); + $defaultOverrides->set( 'JobTypeConf', [ 'default' => [ 'class' => JobQueueMemory::class ] ] ); // Use a fast hash algorithm to hash passwords. $defaultOverrides->set( 'PasswordDefault', 'A' ); diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php index 1024ecd0a6..97198627ed 100644 --- a/tests/phpunit/ResourceLoaderTestCase.php +++ b/tests/phpunit/ResourceLoaderTestCase.php @@ -40,7 +40,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiTestCase { 'skin' => $options['skin'], 'target' => 'phpunit', ] ); - $ctx = $this->getMockBuilder( 'ResourceLoaderContext' ) + $ctx = $this->getMockBuilder( ResourceLoaderContext::class ) ->setConstructorArgs( [ $resourceLoader, $request ] ) ->setMethods( [ 'getDirection' ] ) ->getMock(); diff --git a/tests/phpunit/autoload.ide.php b/tests/phpunit/autoload.ide.php index 6f09d4c9b7..4b0b1873ab 100644 --- a/tests/phpunit/autoload.ide.php +++ b/tests/phpunit/autoload.ide.php @@ -90,7 +90,7 @@ if ( $maintenance->getDbType() === Maintenance::DB_NONE ) { || ( $wgLocalisationCacheConf['store'] == 'detect' && !$wgCacheDirectory ) ) ) { - $wgLocalisationCacheConf['storeClass'] = 'LCStoreNull'; + $wgLocalisationCacheConf['storeClass'] = LCStoreNull::class; } } diff --git a/tests/phpunit/includes/AutopromoteTest.php b/tests/phpunit/includes/AutopromoteTest.php index 24f6596ea9..8c4a488ef5 100644 --- a/tests/phpunit/includes/AutopromoteTest.php +++ b/tests/phpunit/includes/AutopromoteTest.php @@ -20,7 +20,7 @@ class AutopromoteTest extends MediaWikiTestCase { ] ); /** @var PHPUnit_Framework_MockObject_MockObject|User $userMock */ - $userMock = $this->getMock( 'User', [ 'getEditCount' ] ); + $userMock = $this->getMock( User::class, [ 'getEditCount' ] ); if ( $requirement > 0 ) { $userMock->expects( $this->once() ) ->method( 'getEditCount' ) diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index b765494966..1e46555cbd 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -174,7 +174,7 @@ class BlockTest extends MediaWikiLangTestCase { ); $this->assertInstanceOf( - 'Block', + Block::class, $userBlock, "'$username' block block object should be existent" ); diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 65c5d65a4b..8f0826b5e6 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -717,7 +717,7 @@ hello $ep->importFormData( $req ); $this->setExpectedException( - 'MWException', + MWException::class, 'This content model is not supported: testing' ); diff --git a/tests/phpunit/includes/LicensesTest.php b/tests/phpunit/includes/LicensesTest.php index c7b3ce897e..0e96bf44ee 100644 --- a/tests/phpunit/includes/LicensesTest.php +++ b/tests/phpunit/includes/LicensesTest.php @@ -20,6 +20,6 @@ class LicensesTest extends MediaWikiTestCase { 'name' => 'AnotherName', 'licenses' => $str, ] ); - $this->assertThat( $lc, $this->isInstanceOf( 'Licenses' ) ); + $this->assertThat( $lc, $this->isInstanceOf( Licenses::class ) ); } } diff --git a/tests/phpunit/includes/ListToggleTest.php b/tests/phpunit/includes/ListToggleTest.php index 7bbf448191..3574545e45 100644 --- a/tests/phpunit/includes/ListToggleTest.php +++ b/tests/phpunit/includes/ListToggleTest.php @@ -9,14 +9,14 @@ class ListToggleTest extends MediaWikiTestCase { * @covers ListToggle::__construct */ public function testConstruct() { - $output = $this->getMockBuilder( 'OutputPage' ) + $output = $this->getMockBuilder( OutputPage::class ) ->setMethods( null ) ->disableOriginalConstructor() ->getMock(); $listToggle = new ListToggle( $output ); - $this->assertInstanceOf( 'ListToggle', $listToggle ); + $this->assertInstanceOf( ListToggle::class, $listToggle ); $this->assertContains( 'mediawiki.checkboxtoggle', $output->getModules() ); $this->assertContains( 'mediawiki.checkboxtoggle.styles', $output->getModuleStyles() ); } @@ -25,7 +25,7 @@ class ListToggleTest extends MediaWikiTestCase { * @covers ListToggle::getHTML */ public function testGetHTML() { - $output = $this->createMock( 'OutputPage' ); + $output = $this->createMock( OutputPage::class ); $output->expects( $this->any() ) ->method( 'msg' ) ->will( $this->returnCallback( function ( $key ) { diff --git a/tests/phpunit/includes/MWTimestampTest.php b/tests/phpunit/includes/MWTimestampTest.php index c1a46fed5b..9735eebd4b 100644 --- a/tests/phpunit/includes/MWTimestampTest.php +++ b/tests/phpunit/includes/MWTimestampTest.php @@ -23,7 +23,7 @@ class MWTimestampTest extends MediaWikiLangTestCase { $expectedOutput, // The expected output $desc // Description ) { - $user = $this->createMock( 'User' ); + $user = $this->createMock( User::class ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' ) @@ -156,7 +156,7 @@ class MWTimestampTest extends MediaWikiLangTestCase { $expectedOutput, // The expected output $desc // Description ) { - $user = $this->createMock( 'User' ); + $user = $this->createMock( User::class ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' ) diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index e3d533617c..859a40fa5a 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -54,14 +54,14 @@ class MediaWikiServicesTest extends MediaWikiTestCase { public function testGetInstance() { $services = MediaWikiServices::getInstance(); - $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $services ); + $this->assertInstanceOf( MediaWikiServices::class, $services ); } public function testForceGlobalInstance() { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance( $newServices ); - $this->assertInstanceOf( 'MediaWiki\\MediaWikiServices', $oldServices ); + $this->assertInstanceOf( MediaWikiServices::class, $oldServices ); $this->assertNotSame( $oldServices, $newServices ); $theServices = MediaWikiServices::getInstance(); @@ -150,7 +150,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance( $newServices ); - $lbFactory = $this->getMockBuilder( 'LBFactorySimple' ) + $lbFactory = $this->getMockBuilder( \Wikimedia\Rdbms\LBFactorySimple::class ) ->disableOriginalConstructor() ->getMock(); @@ -225,7 +225,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { 'Test', function () use ( &$serviceCounter ) { $serviceCounter++; - $service = $this->createMock( 'MediaWiki\Services\DestructibleService' ); + $service = $this->createMock( MediaWiki\Services\DestructibleService::class ); $service->expects( $this->once() )->method( 'destroy' ); return $service; } @@ -254,7 +254,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $services->defineService( 'Test', function () { - $service = $this->createMock( 'MediaWiki\Services\DestructibleService' ); + $service = $this->createMock( MediaWiki\Services\DestructibleService::class ); $service->expects( $this->never() )->method( 'destroy' ); return $service; } @@ -316,7 +316,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { 'SearchEngineConfig' => [ 'SearchEngineConfig', SearchEngineConfig::class ], 'SkinFactory' => [ 'SkinFactory', SkinFactory::class ], 'DBLoadBalancerFactory' => [ 'DBLoadBalancerFactory', Wikimedia\Rdbms\LBFactory::class ], - 'DBLoadBalancer' => [ 'DBLoadBalancer', 'LoadBalancer' ], + 'DBLoadBalancer' => [ 'DBLoadBalancer', Wikimedia\Rdbms\LoadBalancer::class ], 'WatchedItemStore' => [ 'WatchedItemStore', WatchedItemStore::class ], 'WatchedItemQueryService' => [ 'WatchedItemQueryService', WatchedItemQueryService::class ], 'CryptRand' => [ 'CryptRand', CryptRand::class ], diff --git a/tests/phpunit/includes/MergeHistoryTest.php b/tests/phpunit/includes/MergeHistoryTest.php index f44ae32272..54db581c05 100644 --- a/tests/phpunit/includes/MergeHistoryTest.php +++ b/tests/phpunit/includes/MergeHistoryTest.php @@ -68,7 +68,7 @@ class MergeHistoryTest extends MediaWikiTestCase { public function testIsValidMergeRevisionLimit() { $limit = MergeHistory::REVISION_LIMIT; - $mh = $this->getMockBuilder( 'MergeHistory' ) + $mh = $this->getMockBuilder( MergeHistory::class ) ->setMethods( [ 'getRevisionCount' ] ) ->setConstructorArgs( [ Title::newFromText( 'Test' ), diff --git a/tests/phpunit/includes/MessageTest.php b/tests/phpunit/includes/MessageTest.php index f99cccddb9..fa7782474a 100644 --- a/tests/phpunit/includes/MessageTest.php +++ b/tests/phpunit/includes/MessageTest.php @@ -27,7 +27,7 @@ class MessageTest extends MediaWikiLangTestCase { $this->assertSame( $params, $message->getParams() ); $this->assertEquals( $expectedLang, $message->getLanguage() ); - $messageSpecifier = $this->getMockForAbstractClass( 'MessageSpecifier' ); + $messageSpecifier = $this->getMockForAbstractClass( MessageSpecifier::class ); $messageSpecifier->expects( $this->any() ) ->method( 'getKey' )->will( $this->returnValue( $key ) ); $messageSpecifier->expects( $this->any() ) @@ -200,16 +200,16 @@ class MessageTest extends MediaWikiLangTestCase { * @covers ::wfMessage */ public function testWfMessage() { - $this->assertInstanceOf( 'Message', wfMessage( 'mainpage' ) ); - $this->assertInstanceOf( 'Message', wfMessage( 'i-dont-exist-evar' ) ); + $this->assertInstanceOf( Message::class, wfMessage( 'mainpage' ) ); + $this->assertInstanceOf( Message::class, wfMessage( 'i-dont-exist-evar' ) ); } /** * @covers Message::newFromKey */ public function testNewFromKey() { - $this->assertInstanceOf( 'Message', Message::newFromKey( 'mainpage' ) ); - $this->assertInstanceOf( 'Message', Message::newFromKey( 'i-dont-exist-evar' ) ); + $this->assertInstanceOf( Message::class, Message::newFromKey( 'mainpage' ) ); + $this->assertInstanceOf( Message::class, Message::newFromKey( 'i-dont-exist-evar' ) ); } /** @@ -812,7 +812,7 @@ class MessageTest extends MediaWikiLangTestCase { $msg = unserialize( serialize( $msg ) ); $this->assertSame( '(foo)', $msg->parse() ); $title = TestingAccessWrapper::newFromObject( $msg )->title; - $this->assertInstanceOf( 'Title', $title ); + $this->assertInstanceOf( Title::class, $title ); $this->assertSame( 'Testing', $title->getFullText() ); $msg = new Message( 'mainpage' ); diff --git a/tests/phpunit/includes/OutputPageTest.php b/tests/phpunit/includes/OutputPageTest.php index 44b97078b4..be28e43fda 100644 --- a/tests/phpunit/includes/OutputPageTest.php +++ b/tests/phpunit/includes/OutputPageTest.php @@ -311,7 +311,7 @@ class OutputPageTest extends MediaWikiTestCase { 'wgResourceLoaderDebug' => false, 'wgLoadScript' => 'http://127.0.0.1:8080/w/load.php', ] ); - $class = new ReflectionClass( 'OutputPage' ); + $class = new ReflectionClass( OutputPage::class ); $method = $class->getMethod( 'makeResourceLoaderLink' ); $method->setAccessible( true ); $ctx = new RequestContext(); @@ -398,7 +398,7 @@ class OutputPageTest extends MediaWikiTestCase { $ctx = new RequestContext(); $ctx->setSkin( SkinFactory::getDefaultInstance()->makeSkin( 'fallback' ) ); $ctx->setLanguage( 'en' ); - $outputPage = $this->getMockBuilder( 'OutputPage' ) + $outputPage = $this->getMockBuilder( OutputPage::class ) ->setConstructorArgs( [ $ctx ] ) ->setMethods( [ 'isUserCssPreview', 'buildCssLinksArray' ] ) ->getMock(); @@ -434,7 +434,7 @@ class OutputPageTest extends MediaWikiTestCase { */ public function testVaryHeaders( $calls, $vary, $key ) { // get rid of default Vary fields - $outputPage = $this->getMockBuilder( 'OutputPage' ) + $outputPage = $this->getMockBuilder( OutputPage::class ) ->setConstructorArgs( [ new RequestContext() ] ) ->setMethods( [ 'getCacheVaryCookies' ] ) ->getMock(); @@ -539,7 +539,7 @@ class OutputPageTest extends MediaWikiTestCase { 'page_title' => 'Test2' ] ] ); - $outputPage = $this->getMockBuilder( 'OutputPage' ) + $outputPage = $this->getMockBuilder( OutputPage::class ) ->setConstructorArgs( [ new RequestContext() ] ) ->setMethods( [ 'addCategoryLinksToLBAndGetResult' ] ) ->getMock(); diff --git a/tests/phpunit/includes/PrefixSearchTest.php b/tests/phpunit/includes/PrefixSearchTest.php index 2f3e569613..ed34a8ab9b 100644 --- a/tests/phpunit/includes/PrefixSearchTest.php +++ b/tests/phpunit/includes/PrefixSearchTest.php @@ -58,8 +58,8 @@ class PrefixSearchTest extends MediaWikiLangTestCase { 'wgCapitalLinkOverrides' => [ self::NS_NONCAP => false ], ] ); - $this->originalHandlers = TestingAccessWrapper::newFromClass( 'Hooks' )->handlers; - TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = []; + $this->originalHandlers = TestingAccessWrapper::newFromClass( Hooks::class )->handlers; + TestingAccessWrapper::newFromClass( Hooks::class )->handlers = []; // Clear caches so that our new namespace appears MWNamespace::clearCaches(); @@ -74,7 +74,7 @@ class PrefixSearchTest extends MediaWikiLangTestCase { parent::tearDown(); - TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = $this->originalHandlers; + TestingAccessWrapper::newFromClass( Hooks::class )->handlers = $this->originalHandlers; SpecialPageFactory::resetList(); } diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index 427a95e656..511b109538 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -837,9 +837,9 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { public function provideGetContentHandler() { // NOTE: we expect the help namespace to always contain wikitext return [ - [ 'hello world', 'Help:Hello', null, null, 'WikitextContentHandler' ], - [ 'hello world', 'User:hello/there.css', null, null, 'CssContentHandler' ], - [ serialize( 'hello world' ), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ], + [ 'hello world', 'Help:Hello', null, null, WikitextContentHandler::class ], + [ 'hello world', 'User:hello/there.css', null, null, CssContentHandler::class ], + [ serialize( 'hello world' ), 'Dummy:Hello', null, null, DummyContentHandlerForTesting::class ], ]; } diff --git a/tests/phpunit/includes/SampleTest.php b/tests/phpunit/includes/SampleTest.php index c0930e3dbf..3d74ae3efc 100644 --- a/tests/phpunit/includes/SampleTest.php +++ b/tests/phpunit/includes/SampleTest.php @@ -36,7 +36,7 @@ class SampleTest extends MediaWikiLangTestCase { */ public function testTitleObjectStringConversion() { $title = Title::newFromText( "text" ); - $this->assertInstanceOf( 'Title', $title, "Title creation" ); + $this->assertInstanceOf( Title::class, $title, "Title creation" ); $this->assertEquals( "Text", $title, "Automatic string conversion" ); $title = Title::newFromText( "text", NS_MEDIA ); diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index ae23a4343e..54c05ecc0c 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -30,7 +30,7 @@ class StatusTest extends MediaWikiLangTestCase { * @covers Status::newFatal */ public function testNewFatalWithMessage() { - $message = $this->getMockBuilder( 'Message' ) + $message = $this->getMockBuilder( Message::class ) ->disableOriginalConstructor() ->getMock(); @@ -224,7 +224,7 @@ class StatusTest extends MediaWikiLangTestCase { } protected function getMockMessage( $key = 'key', $params = [] ) { - $message = $this->getMockBuilder( 'Message' ) + $message = $this->getMockBuilder( Message::class ) ->disableOriginalConstructor() ->getMock(); $message->expects( $this->atLeastOnce() ) @@ -311,7 +311,7 @@ class StatusTest extends MediaWikiLangTestCase { * @covers Status::cleanParams */ public function testCleanParams( $cleanCallback, $params, $expected ) { - $method = new ReflectionMethod( 'Status', 'cleanParams' ); + $method = new ReflectionMethod( Status::class, 'cleanParams' ); $method->setAccessible( true ); $status = new Status(); $status->cleanCallback = $cleanCallback; @@ -449,23 +449,23 @@ class StatusTest extends MediaWikiLangTestCase { Status $status, $expectedParams = [], $expectedKey, $expectedWrapper ) { $message = $status->getMessage( null, null, 'qqx' ); - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( $expectedParams, self::sanitizedMessageParams( $message ), 'Message::getParams' ); $this->assertEquals( $expectedKey, $message->getKey(), 'Message::getKey' ); $message = $status->getMessage( 'wrapper-short', 'wrapper-long' ); - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( $expectedWrapper, $message->getKey(), 'Message::getKey with wrappers' ); $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' ); $message = $status->getMessage( 'wrapper' ); - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' ); $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' ); $message = $status->getMessage( false, 'wrapper' ); - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( 'wrapper', $message->getKey(), 'Message::getKey with wrappers' ); $this->assertCount( 1, $message->getParams(), 'Message::getParams with wrappers' ); } @@ -560,7 +560,7 @@ class StatusTest extends MediaWikiLangTestCase { * @covers Status::getErrorMessage */ public function testGetErrorMessage() { - $method = new ReflectionMethod( 'Status', 'getErrorMessage' ); + $method = new ReflectionMethod( Status::class, 'getErrorMessage' ); $method->setAccessible( true ); $status = new Status(); $key = 'foo'; @@ -568,7 +568,7 @@ class StatusTest extends MediaWikiLangTestCase { /** @var Message $message */ $message = $method->invoke( $status, array_merge( [ $key ], $params ) ); - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( $key, $message->getKey() ); $this->assertEquals( $params, $message->getParams() ); } @@ -577,7 +577,7 @@ class StatusTest extends MediaWikiLangTestCase { * @covers Status::getErrorMessageArray */ public function testGetErrorMessageArray() { - $method = new ReflectionMethod( 'Status', 'getErrorMessageArray' ); + $method = new ReflectionMethod( Status::class, 'getErrorMessageArray' ); $method->setAccessible( true ); $status = new Status(); $key = 'foo'; @@ -595,7 +595,7 @@ class StatusTest extends MediaWikiLangTestCase { $this->assertInternalType( 'array', $messageArray ); $this->assertCount( 2, $messageArray ); foreach ( $messageArray as $message ) { - $this->assertInstanceOf( 'Message', $message ); + $this->assertInstanceOf( Message::class, $message ); $this->assertEquals( $key, $message->getKey() ); $this->assertEquals( $params, $message->getParams() ); } diff --git a/tests/phpunit/includes/TemplateParserTest.php b/tests/phpunit/includes/TemplateParserTest.php index 4a803e6374..ccccf0f949 100644 --- a/tests/phpunit/includes/TemplateParserTest.php +++ b/tests/phpunit/includes/TemplateParserTest.php @@ -116,7 +116,7 @@ class TemplateParserTest extends MediaWikiTestCase { $this->assertEquals( 'rrr', $tp->processTemplate( 'recurse', $data ) ); $tp->enableRecursivePartials( false ); - $this->setExpectedException( 'Exception' ); + $this->setExpectedException( Exception::class ); $tp->processTemplate( 'recurse', $data ); } diff --git a/tests/phpunit/includes/TitleArrayFromResultTest.php b/tests/phpunit/includes/TitleArrayFromResultTest.php index 8882214048..63956c123a 100644 --- a/tests/phpunit/includes/TitleArrayFromResultTest.php +++ b/tests/phpunit/includes/TitleArrayFromResultTest.php @@ -9,7 +9,7 @@ class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase { use MediaWikiCoversValidator; private function getMockResultWrapper( $row = null, $numRows = 1 ) { - $resultWrapper = $this->getMockBuilder( 'ResultWrapper' ) + $resultWrapper = $this->getMockBuilder( Wikimedia\Rdbms\ResultWrapper::class ) ->disableOriginalConstructor(); $resultWrapper = $resultWrapper->getMock(); @@ -61,7 +61,7 @@ class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase { $this->assertEquals( $resultWrapper, $object->res ); $this->assertSame( 0, $object->key ); - $this->assertInstanceOf( 'Title', $object->current ); + $this->assertInstanceOf( Title::class, $object->current ); $this->assertEquals( $namespace, $object->current->mNamespace ); $this->assertEquals( $title, $object->current->mTextform ); } @@ -94,7 +94,7 @@ class TitleArrayFromResultTest extends PHPUnit_Framework_TestCase { $title = 'foo'; $row = $this->getRowWithTitle( $namespace, $title ); $object = $this->getTitleArrayFromResult( $this->getMockResultWrapper( $row ) ); - $this->assertInstanceOf( 'Title', $object->current() ); + $this->assertInstanceOf( Title::class, $object->current() ); $this->assertEquals( $namespace, $object->current->mNamespace ); $this->assertEquals( $title, $object->current->mTextform ); } diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index 54cdbe28e7..f4eb6bf5d3 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -318,7 +318,7 @@ class TitleMethodsTest extends MediaWikiLangTestCase { */ public function testGetOtherPage( $text, $expected ) { if ( $expected === null ) { - $this->setExpectedException( 'MWException' ); + $this->setExpectedException( MWException::class ); } $title = Title::newFromText( $text ); diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index d12e4b8643..c81a07872e 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -163,7 +163,7 @@ class TitleTest extends MediaWikiTestCase { */ public function testSecureAndSplitValid( $text ) { $this->secureAndSplitGlobals(); - $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" ); + $this->assertInstanceOf( Title::class, Title::newFromText( $text ), "Valid: $text" ); } /** @@ -434,7 +434,7 @@ class TitleTest extends MediaWikiTestCase { $this->setContentLang( $contLang ); $title = Title::newFromText( $titleText ); - $this->assertInstanceOf( 'Title', $title, + $this->assertInstanceOf( Title::class, $title, "Test must be passed a valid title text, you gave '$titleText'" ); $this->assertEquals( $expected, diff --git a/tests/phpunit/includes/WebRequestTest.php b/tests/phpunit/includes/WebRequestTest.php index 041e7e3cd6..936f4f5bd6 100644 --- a/tests/phpunit/includes/WebRequestTest.php +++ b/tests/phpunit/includes/WebRequestTest.php @@ -126,7 +126,7 @@ class WebRequestTest extends MediaWikiTestCase { protected function mockWebRequest( $data = [] ) { // Cannot use PHPUnit getMockBuilder() as it does not support // overriding protected properties afterwards - $reflection = new ReflectionClass( 'WebRequest' ); + $reflection = new ReflectionClass( WebRequest::class ); $req = $reflection->newInstanceWithoutConstructor(); $prop = $reflection->getProperty( 'data' ); diff --git a/tests/phpunit/includes/XmlTest.php b/tests/phpunit/includes/XmlTest.php index 4a280da374..e46fc67f73 100644 --- a/tests/phpunit/includes/XmlTest.php +++ b/tests/phpunit/includes/XmlTest.php @@ -55,7 +55,7 @@ class XmlTest extends MediaWikiTestCase { * @covers Xml::expandAttributes */ public function testExpandAttributesException() { - $this->setExpectedException( 'MWException' ); + $this->setExpectedException( MWException::class ); Xml::expandAttributes( 'string' ); } diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index f97dd73e64..4d54334014 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -20,7 +20,7 @@ class ActionTest extends MediaWikiTestCase { 'disabled' => false, 'view' => true, 'edit' => true, - 'revisiondelete' => 'SpecialPageAction', + 'revisiondelete' => SpecialPageAction::class, 'dummy' => true, 'string' => 'NamedDummyAction', 'declared' => 'NonExistingClassName', diff --git a/tests/phpunit/includes/api/ApiContinuationManagerTest.php b/tests/phpunit/includes/api/ApiContinuationManagerTest.php index bb4ea75893..788d120c6b 100644 --- a/tests/phpunit/includes/api/ApiContinuationManagerTest.php +++ b/tests/phpunit/includes/api/ApiContinuationManagerTest.php @@ -22,7 +22,7 @@ class ApiContinuationManagerTest extends MediaWikiTestCase { $generator = new MockApiQueryBase( 'generator' ); $manager = self::getManager( '', $allModules, [ 'mock1', 'mock2' ] ); - $this->assertSame( 'ApiMain', $manager->getSource() ); + $this->assertSame( ApiMain::class, $manager->getSource() ); $this->assertSame( false, $manager->isGeneratorDone() ); $this->assertSame( $allModules, $manager->getRunModules() ); $manager->addContinueParam( $allModules[0], 'm1continue', [ 1, 2 ] ); diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php index c82edf0399..7eac55975a 100644 --- a/tests/phpunit/includes/api/ApiEditPageTest.php +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -478,7 +478,7 @@ class ApiEditPageTest extends ApiTestCase { public function testCheckDirectApiEditingDisallowed_forNonTextContent() { $this->setExpectedException( - 'ApiUsageException', + ApiUsageException::class, 'Direct editing via API is not supported for content model ' . 'testing used by Dummy:ApiEditPageTest_nonTextPageEdit' ); diff --git a/tests/phpunit/includes/api/ApiLoginTest.php b/tests/phpunit/includes/api/ApiLoginTest.php index 3cf1fdee8f..ed4d6834bc 100644 --- a/tests/phpunit/includes/api/ApiLoginTest.php +++ b/tests/phpunit/includes/api/ApiLoginTest.php @@ -142,7 +142,7 @@ class ApiLoginTest extends ApiTestCase { libxml_use_internal_errors( true ); $sxe = simplexml_load_string( $req->getContent() ); $this->assertNotInternalType( "bool", $sxe ); - $this->assertThat( $sxe, $this->isInstanceOf( "SimpleXMLElement" ) ); + $this->assertThat( $sxe, $this->isInstanceOf( SimpleXMLElement::class ) ); $this->assertNotInternalType( "null", $sxe->login[0] ); $a = $sxe->login[0]->attributes()->result[0]; diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index ad334e9401..83eba54bf8 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -126,7 +126,7 @@ class ApiMainTest extends ApiTestCase { $priv = TestingAccessWrapper::newFromObject( $api ); $priv->mInternalMode = false; - $module = $this->getMockBuilder( 'ApiBase' ) + $module = $this->getMockBuilder( ApiBase::class ) ->setConstructorArgs( [ $api, 'mock' ] ) ->setMethods( [ 'getConditionalRequestData' ] ) ->getMockForAbstractClass(); @@ -223,7 +223,7 @@ class ApiMainTest extends ApiTestCase { $priv = TestingAccessWrapper::newFromObject( $api ); $priv->mInternalMode = false; - $module = $this->getMockBuilder( 'ApiBase' ) + $module = $this->getMockBuilder( ApiBase::class ) ->setConstructorArgs( [ $api, 'mock' ] ) ->setMethods( [ 'getConditionalRequestData' ] ) ->getMockForAbstractClass(); @@ -491,7 +491,7 @@ class ApiMainTest extends ApiTestCase { )->inLanguage( 'en' )->useDatabase( false )->text(); $dbex = new DBQueryError( - $this->createMock( 'IDatabase' ), + $this->createMock( \Wikimedia\Rdbms\IDatabase::class ), 'error', 1234, 'SELECT 1', __METHOD__ ); $dbtrace = wfMessage( 'api-exception-trace', get_class( $dbex ), diff --git a/tests/phpunit/includes/api/ApiModuleManagerTest.php b/tests/phpunit/includes/api/ApiModuleManagerTest.php index be17bba2b3..b01b90e8ef 100644 --- a/tests/phpunit/includes/api/ApiModuleManagerTest.php +++ b/tests/phpunit/includes/api/ApiModuleManagerTest.php @@ -24,21 +24,21 @@ class ApiModuleManagerTest extends MediaWikiTestCase { 'plain class' => [ 'login', 'action', - 'ApiLogin', + ApiLogin::class, null, ], 'with factory' => [ 'login', 'action', - 'ApiLogin', + ApiLogin::class, [ $this, 'newApiLogin' ], ], 'with closure' => [ 'logout', 'action', - 'ApiLogout', + ApiLogout::class, function ( ApiMain $main, $action ) { return new ApiLogout( $main, $action ); }, @@ -66,8 +66,8 @@ class ApiModuleManagerTest extends MediaWikiTestCase { 'simple' => [ [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ], 'action', ], @@ -75,11 +75,11 @@ class ApiModuleManagerTest extends MediaWikiTestCase { 'with factories' => [ [ 'login' => [ - 'class' => 'ApiLogin', + 'class' => ApiLogin::class, 'factory' => [ $this, 'newApiLogin' ], ], 'logout' => [ - 'class' => 'ApiLogout', + 'class' => ApiLogout::class, 'factory' => function ( ApiMain $main, $action ) { return new ApiLogout( $main, $action ); }, @@ -107,14 +107,14 @@ class ApiModuleManagerTest extends MediaWikiTestCase { public function getModuleProvider() { $modules = [ - 'feedrecentchanges' => 'ApiFeedRecentChanges', - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], + 'feedrecentchanges' => ApiFeedRecentChanges::class, + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], 'login' => [ - 'class' => 'ApiLogin', + 'class' => ApiLogin::class, 'factory' => [ $this, 'newApiLogin' ], ], 'logout' => [ - 'class' => 'ApiLogout', + 'class' => ApiLogout::class, 'factory' => function ( ApiMain $main, $action ) { return new ApiLogout( $main, $action ); }, @@ -125,25 +125,25 @@ class ApiModuleManagerTest extends MediaWikiTestCase { 'legacy entry' => [ $modules, 'feedrecentchanges', - 'ApiFeedRecentChanges', + ApiFeedRecentChanges::class, ], 'just a class' => [ $modules, 'feedcontributions', - 'ApiFeedContributions', + ApiFeedContributions::class, ], 'with factory' => [ $modules, 'login', - 'ApiLogin', + ApiLogin::class, ], 'with closure' => [ $modules, 'logout', - 'ApiLogout', + ApiLogout::class, ], ]; } @@ -178,8 +178,8 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetModule_null() { $modules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $moduleManager = $this->getModuleManager(); @@ -194,13 +194,13 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetNames() { $fooModules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $barModules = [ - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], - 'feedrecentchanges' => [ 'class' => 'ApiFeedRecentChanges' ], + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], + 'feedrecentchanges' => [ 'class' => ApiFeedRecentChanges::class ], ]; $moduleManager = $this->getModuleManager(); @@ -220,13 +220,13 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetNamesWithClasses() { $fooModules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $barModules = [ - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], - 'feedrecentchanges' => [ 'class' => 'ApiFeedRecentChanges' ], + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], + 'feedrecentchanges' => [ 'class' => ApiFeedRecentChanges::class ], ]; $moduleManager = $this->getModuleManager(); @@ -238,8 +238,8 @@ class ApiModuleManagerTest extends MediaWikiTestCase { $allNamesWithClasses = $moduleManager->getNamesWithClasses(); $allModules = array_merge( $fooModules, [ - 'feedcontributions' => 'ApiFeedContributions', - 'feedrecentchanges' => 'ApiFeedRecentChanges', + 'feedcontributions' => ApiFeedContributions::class, + 'feedrecentchanges' => ApiFeedRecentChanges::class, ] ); $this->assertArrayEquals( $allModules, $allNamesWithClasses ); } @@ -249,13 +249,13 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetModuleGroup() { $fooModules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $barModules = [ - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], - 'feedrecentchanges' => [ 'class' => 'ApiFeedRecentChanges' ], + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], + 'feedrecentchanges' => [ 'class' => ApiFeedRecentChanges::class ], ]; $moduleManager = $this->getModuleManager(); @@ -272,13 +272,13 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetGroups() { $fooModules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $barModules = [ - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], - 'feedrecentchanges' => [ 'class' => 'ApiFeedRecentChanges' ], + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], + 'feedrecentchanges' => [ 'class' => ApiFeedRecentChanges::class ], ]; $moduleManager = $this->getModuleManager(); @@ -294,13 +294,13 @@ class ApiModuleManagerTest extends MediaWikiTestCase { */ public function testGetClassName() { $fooModules = [ - 'login' => 'ApiLogin', - 'logout' => 'ApiLogout', + 'login' => ApiLogin::class, + 'logout' => ApiLogout::class, ]; $barModules = [ - 'feedcontributions' => [ 'class' => 'ApiFeedContributions' ], - 'feedrecentchanges' => [ 'class' => 'ApiFeedRecentChanges' ], + 'feedcontributions' => [ 'class' => ApiFeedContributions::class ], + 'feedrecentchanges' => [ 'class' => ApiFeedRecentChanges::class ], ]; $moduleManager = $this->getModuleManager(); @@ -308,19 +308,19 @@ class ApiModuleManagerTest extends MediaWikiTestCase { $moduleManager->addModules( $barModules, 'bar' ); $this->assertEquals( - 'ApiLogin', + ApiLogin::class, $moduleManager->getClassName( 'login' ) ); $this->assertEquals( - 'ApiLogout', + ApiLogout::class, $moduleManager->getClassName( 'logout' ) ); $this->assertEquals( - 'ApiFeedContributions', + ApiFeedContributions::class, $moduleManager->getClassName( 'feedcontributions' ) ); $this->assertEquals( - 'ApiFeedRecentChanges', + ApiFeedRecentChanges::class, $moduleManager->getClassName( 'feedrecentchanges' ) ); $this->assertFalse( diff --git a/tests/phpunit/includes/api/ApiOpenSearchTest.php b/tests/phpunit/includes/api/ApiOpenSearchTest.php index cc993d5df8..209ca07b0d 100644 --- a/tests/phpunit/includes/api/ApiOpenSearchTest.php +++ b/tests/phpunit/includes/api/ApiOpenSearchTest.php @@ -36,7 +36,7 @@ class ApiOpenSearchTest extends MediaWikiTestCase { } private function replaceSearchEngineConfig() { - $config = $this->getMockBuilder( 'SearchEngineConfig' ) + $config = $this->getMockBuilder( SearchEngineConfig::class ) ->disableOriginalConstructor() ->getMock(); $this->setService( 'SearchEngineConfig', $config ); @@ -45,10 +45,10 @@ class ApiOpenSearchTest extends MediaWikiTestCase { } private function replaceSearchEngine() { - $engine = $this->getMockBuilder( 'SearchEngine' ) + $engine = $this->getMockBuilder( SearchEngine::class ) ->disableOriginalConstructor() ->getMock(); - $engineFactory = $this->getMockBuilder( 'SearchEngineFactory' ) + $engineFactory = $this->getMockBuilder( SearchEngineFactory::class ) ->disableOriginalConstructor() ->getMock(); $engineFactory->expects( $this->any() ) diff --git a/tests/phpunit/includes/api/ApiOptionsTest.php b/tests/phpunit/includes/api/ApiOptionsTest.php index 7e45f4da12..c0fecf06a1 100644 --- a/tests/phpunit/includes/api/ApiOptionsTest.php +++ b/tests/phpunit/includes/api/ApiOptionsTest.php @@ -22,7 +22,7 @@ class ApiOptionsTest extends MediaWikiLangTestCase { protected function setUp() { parent::setUp(); - $this->mUserMock = $this->getMockBuilder( 'User' ) + $this->mUserMock = $this->getMockBuilder( User::class ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/phpunit/includes/api/format/ApiFormatRawTest.php b/tests/phpunit/includes/api/format/ApiFormatRawTest.php index 0d3e63f98a..f64af6d3a8 100644 --- a/tests/phpunit/includes/api/format/ApiFormatRawTest.php +++ b/tests/phpunit/includes/api/format/ApiFormatRawTest.php @@ -14,7 +14,7 @@ class ApiFormatRawTest extends ApiFormatTestBase { */ public static function provideGeneralEncoding() { $options = [ - 'class' => 'ApiFormatRaw', + 'class' => ApiFormatRaw::class, 'factory' => function ( ApiMain $main ) { return new ApiFormatRaw( $main, new ApiFormatJson( $main, 'json' ) ); } @@ -105,7 +105,7 @@ class ApiFormatRawTest extends ApiFormatTestBase { '{"mime":"text/plain","text":"some text","error":"some error"}', [], [ - 'class' => 'ApiFormatRaw', + 'class' => ApiFormatRaw::class, 'factory' => function ( ApiMain $main ) use ( &$apiMain ) { $apiMain = $main; $printer = new ApiFormatRaw( $main, new ApiFormatJson( $main, 'json' ) ); diff --git a/tests/phpunit/includes/auth/AbstractAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractAuthenticationProviderTest.php index a3b0df529d..b271b701b6 100644 --- a/tests/phpunit/includes/auth/AbstractAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AbstractAuthenticationProviderTest.php @@ -13,7 +13,7 @@ class AbstractAuthenticationProviderTest extends \MediaWikiTestCase { $provider = $this->getMockForAbstractClass( AbstractAuthenticationProvider::class ); $providerPriv = TestingAccessWrapper::newFromObject( $provider ); - $obj = $this->getMockForAbstractClass( 'Psr\Log\LoggerInterface' ); + $obj = $this->getMockForAbstractClass( \Psr\Log\LoggerInterface::class ); $provider->setLogger( $obj ); $this->assertSame( $obj, $providerPriv->logger, 'setLogger' ); @@ -21,7 +21,7 @@ class AbstractAuthenticationProviderTest extends \MediaWikiTestCase { $provider->setManager( $obj ); $this->assertSame( $obj, $providerPriv->manager, 'setManager' ); - $obj = $this->getMockForAbstractClass( 'Config' ); + $obj = $this->getMockForAbstractClass( \Config::class ); $provider->setConfig( $obj ); $this->assertSame( $obj, $providerPriv->config, 'setConfig' ); diff --git a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php index 76d8ee933b..cb015df61b 100644 --- a/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AbstractPasswordPrimaryAuthenticationProviderTest.php @@ -33,7 +33,7 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $obj = $providerPriv->getPasswordFactory(); - $this->assertInstanceOf( 'PasswordFactory', $obj ); + $this->assertInstanceOf( \PasswordFactory::class, $obj ); $this->assertSame( $obj, $providerPriv->getPasswordFactory() ); } @@ -46,10 +46,10 @@ class AbstractPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCa $providerPriv = TestingAccessWrapper::newFromObject( $provider ); $obj = $providerPriv->getPassword( null ); - $this->assertInstanceOf( 'Password', $obj ); + $this->assertInstanceOf( \Password::class, $obj ); $obj = $providerPriv->getPassword( 'invalid' ); - $this->assertInstanceOf( 'Password', $obj ); + $this->assertInstanceOf( \Password::class, $obj ); } public function testGetNewPasswordExpiry() { diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index c18af8b346..b8f7b733b6 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -149,7 +149,7 @@ class AuthManagerTest extends \MediaWikiTestCase { if ( $canChangeUser !== null ) { $methods[] = 'canChangeUser'; } - $provider = $this->getMockBuilder( 'DummySessionProvider' ) + $provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( $methods ) ->getMock(); $provider->expects( $this->any() )->method( '__toString' ) @@ -968,7 +968,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $p->expects( $this->atMost( 1 ) )->method( 'postAuthentication' ) ->willReturnCallback( function ( $user, $response ) use ( $constraint, $p ) { if ( $user !== null ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( 'UTSysop', $user->getName() ); } $this->assertInstanceOf( AuthenticationResponse::class, $response ); @@ -1998,7 +1998,7 @@ class AuthManagerTest extends \MediaWikiTestCase { ->willReturnCallback( function ( $user, $creator, $response ) use ( $constraint, $p, $username ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); $this->assertSame( 'UTSysop', $creator->getName() ); $this->assertInstanceOf( AuthenticationResponse::class, $response ); @@ -2262,7 +2262,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Set up lots of mocks... $mock = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\PrimaryAuthenticationProvider", [] + \MediaWiki\Auth\PrimaryAuthenticationProvider::class, [] ); $mock->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( 'primary' ) ); @@ -2668,7 +2668,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnValue( \Status::newFatal( 'because' ) ) ); @@ -2690,7 +2690,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) ); $this->assertFalse( $cache->get( $backoffKey ), 'sanity check' ); $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->throwException( new \Exception( 'Excepted' ) ) ); @@ -2714,7 +2714,7 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails because the user already exists. $session->clear(); - $user = $this->getMockBuilder( 'User' ) + $user = $this->getMockBuilder( \User::class ) ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnCallback( function () use ( $username, &$user ) { @@ -3474,7 +3474,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $p->postCalled = false; $p->expects( $this->atMost( 1 ) )->method( 'postAccountLink' ) ->willReturnCallback( function ( $user, $response ) use ( $constraint, $p ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( 'UTSysop', $user->getName() ); $this->assertInstanceOf( AuthenticationResponse::class, $response ); $this->assertThat( $response->status, $constraint ); diff --git a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php index 82b0f8286a..57c3e7eb5d 100644 --- a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php @@ -20,7 +20,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ); } - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); @@ -51,7 +51,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserSaveSettings() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateExternalDB' ) ->with( $this->identicalTo( $user ) ); @@ -63,7 +63,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserGroupsChanged() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateExternalDBGroups' ) ->with( @@ -79,14 +79,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserLoggedIn() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->exactly( 2 ) )->method( 'updateUser' ) ->with( $this->identicalTo( $user ) ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); \Hooks::run( 'UserLoggedIn', [ $user ] ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'updateUser' ) ->will( $this->returnCallback( function ( &$user ) { @@ -107,14 +107,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnLocalUserCreated() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->exactly( 2 ) )->method( 'initUser' ) ->with( $this->identicalTo( $user ), $this->identicalTo( false ) ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); \Hooks::run( 'LocalUserCreated', [ $user, false ] ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'initUser' ) ->will( $this->returnCallback( function ( &$user ) { @@ -133,7 +133,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testGetUniqueId() { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertSame( @@ -149,7 +149,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { * @param bool $allowPasswordChange */ public function testGetAuthenticationRequests( $action, $response, $allowPasswordChange ) { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'allowPasswordChange' ) ->will( $this->returnValue( $allowPasswordChange ) ); @@ -178,7 +178,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->action = AuthManager::ACTION_LOGIN; $reqs = [ PasswordAuthenticationRequest::class => $req ]; - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'authenticate' ] ) ->getMock(); $plugin->expects( $this->never() )->method( 'authenticate' ); @@ -206,7 +206,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -220,7 +220,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -232,13 +232,13 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->setMethods( [ 'isLocked' ] ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( true ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'getUserInstance', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -252,7 +252,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -266,7 +266,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAuthentication( $reqs ) ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate', 'strict' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -280,7 +280,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( AuthenticationResponse::FAIL, $ret->status ); $this->assertSame( 'wrongpassword', $ret->message->getKey() ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'authenticate', 'strictUserAuth' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' ) @@ -296,7 +296,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( AuthenticationResponse::FAIL, $ret->status ); $this->assertSame( 'wrongpassword', $ret->message->getKey() ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'domainList', 'validDomain', 'setDomain', 'userExists', 'authenticate' ] ) ->getMock(); $plugin->expects( $this->any() )->method( 'domainList' ) @@ -321,7 +321,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testTestUserExists() { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -330,7 +330,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertTrue( $provider->testUserExists( 'foo' ) ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -341,7 +341,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testTestUserCanAuthenticate() { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -350,19 +350,19 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertFalse( $provider->testUserCanAuthenticate( 'foo' ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( true ) ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->once() )->method( 'getUserInstance' ) ->with( $this->callback( function ( $user ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertEquals( 'Foo', $user->getName() ); return true; } ) ) @@ -370,19 +370,19 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertFalse( $provider->testUserCanAuthenticate( 'foo' ) ); - $pluginUser = $this->getMockBuilder( 'AuthPluginUser' ) + $pluginUser = $this->getMockBuilder( \AuthPluginUser::class ) ->disableOriginalConstructor() ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( false ) ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->once() )->method( 'getUserInstance' ) ->with( $this->callback( function ( $user ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertEquals( 'Foo', $user->getName() ); return true; } ) ) @@ -392,7 +392,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderRevokeAccessForUser() { - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'userExists', 'setPassword' ] ) ->getMock(); $plugin->expects( $this->once() )->method( 'userExists' )->willReturn( true ); @@ -404,7 +404,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $provider->providerRevokeAccessForUser( 'foo' ); - $plugin = $this->getMockBuilder( 'AuthPlugin' ) + $plugin = $this->getMockBuilder( \AuthPlugin::class ) ->setMethods( [ 'domainList', 'userExists', 'setPassword' ] ) ->getMock(); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [ 'D1', 'D2', 'D3' ] ); @@ -433,7 +433,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderAllowsPropertyChange() { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'allowPropChange' ) ->will( $this->returnCallback( function ( $prop ) { @@ -453,7 +453,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { */ public function testProviderAllowsAuthenticationDataChange( $type, $allow, $expect ) { $domains = $type instanceof PasswordDomainAuthenticationRequest ? [ 'foo', 'bar' ] : []; - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( $domains ); $plugin->expects( $allow === null ? $this->never() : $this->once() ) ->method( 'allowPasswordChange' )->will( $this->returnValue( $allow ) ); @@ -502,7 +502,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderChangeAuthenticationData() { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->never() )->method( 'setPassword' ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); @@ -515,7 +515,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'setPassword' ) ->with( $this->callback( function ( $u ) { @@ -525,7 +525,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $provider->providerChangeAuthenticationData( $req ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'setPassword' ) ->with( $this->callback( function ( $u ) { @@ -541,7 +541,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( 'authmanager-authplugin-setpass-failed-message', $e->msg ); } - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' ) ->will( $this->returnValue( [ 'Domain1', 'Domain2' ] ) ); $plugin->expects( $this->any() )->method( 'validDomain' ) @@ -569,7 +569,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { * @param string $expect */ public function testAccountCreationType( $can, $expect ) { - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() ) ->method( 'canCreateAccounts' )->will( $this->returnValue( $can ) ); @@ -588,7 +588,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testTestForAccountCreation() { $user = \User::newFromName( 'foo' ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $this->assertEquals( @@ -606,7 +606,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->action = AuthManager::ACTION_CREATE; $reqs = [ PasswordAuthenticationRequest::class => $req ]; - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( false ) ); @@ -621,7 +621,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ); } - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -650,7 +650,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -670,7 +670,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->beginPrimaryAccountCreation( $user, $user, $reqs ) ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); @@ -689,7 +689,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $this->assertSame( AuthenticationResponse::FAIL, $ret->status ); $this->assertSame( 'authmanager-authplugin-create-fail', $ret->message->getKey() ); - $plugin = $this->createMock( 'AuthPlugin' ); + $plugin = $this->createMock( \AuthPlugin::class ); $plugin->expects( $this->any() )->method( 'canCreateAccounts' ) ->will( $this->returnValue( true ) ); $plugin->expects( $this->any() )->method( 'domainList' ) diff --git a/tests/phpunit/includes/auth/AuthenticationRequestTest.php b/tests/phpunit/includes/auth/AuthenticationRequestTest.php index 0e549a5ca6..1bc0f31f51 100644 --- a/tests/phpunit/includes/auth/AuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/AuthenticationRequestTest.php @@ -17,9 +17,9 @@ class AuthenticationRequestTest extends \MediaWikiTestCase { $ret = $mock->describeCredentials(); $this->assertInternalType( 'array', $ret ); $this->assertArrayHasKey( 'provider', $ret ); - $this->assertInstanceOf( 'Message', $ret['provider'] ); + $this->assertInstanceOf( \Message::class, $ret['provider'] ); $this->assertArrayHasKey( 'account', $ret ); - $this->assertInstanceOf( 'Message', $ret['account'] ); + $this->assertInstanceOf( \Message::class, $ret['account'] ); } public function testLoadRequestsFromSubmission() { diff --git a/tests/phpunit/includes/auth/AuthenticationRequestTestCase.php b/tests/phpunit/includes/auth/AuthenticationRequestTestCase.php index b5c8a36cd1..f483b9b6fd 100644 --- a/tests/phpunit/includes/auth/AuthenticationRequestTestCase.php +++ b/tests/phpunit/includes/auth/AuthenticationRequestTestCase.php @@ -19,11 +19,11 @@ abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase { $this->assertType( 'array', $data, "Field $field" ); $this->assertArrayHasKey( 'type', $data, "Field $field" ); $this->assertArrayHasKey( 'label', $data, "Field $field" ); - $this->assertInstanceOf( 'Message', $data['label'], "Field $field, label" ); + $this->assertInstanceOf( \Message::class, $data['label'], "Field $field, label" ); if ( $data['type'] !== 'null' ) { $this->assertArrayHasKey( 'help', $data, "Field $field" ); - $this->assertInstanceOf( 'Message', $data['help'], "Field $field, help" ); + $this->assertInstanceOf( \Message::class, $data['help'], "Field $field, help" ); } if ( isset( $data['optional'] ) ) { @@ -50,7 +50,7 @@ abstract class AuthenticationRequestTestCase extends \MediaWikiTestCase { $this->assertArrayHasKey( 'options', $data, "Field $field" ); $this->assertType( 'array', $data['options'], "Field $field, options" ); foreach ( $data['options'] as $val => $msg ) { - $this->assertInstanceOf( 'Message', $msg, "Field $field, option $val" ); + $this->assertInstanceOf( \Message::class, $msg, "Field $field, option $val" ); } break; case 'checkbox': diff --git a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php index 111c855445..4e44547bbf 100644 --- a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php @@ -135,12 +135,12 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase ); $status = $provider->testUserForCreation( $blockedUser, AuthManager::AUTOCREATE_SOURCE_SESSION ); - $this->assertInstanceOf( 'StatusValue', $status ); + $this->assertInstanceOf( \StatusValue::class, $status ); $this->assertFalse( $status->isOK() ); $this->assertTrue( $status->hasMessage( 'cantcreateaccount-text' ) ); $status = $provider->testUserForCreation( $blockedUser, false ); - $this->assertInstanceOf( 'StatusValue', $status ); + $this->assertInstanceOf( \StatusValue::class, $status ); $this->assertFalse( $status->isOK() ); $this->assertTrue( $status->hasMessage( 'cantcreateaccount-text' ) ); } @@ -176,12 +176,12 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase $this->assertEquals( AuthenticationResponse::FAIL, $ret->status ); $status = $provider->testUserForCreation( $newuser, AuthManager::AUTOCREATE_SOURCE_SESSION ); - $this->assertInstanceOf( 'StatusValue', $status ); + $this->assertInstanceOf( \StatusValue::class, $status ); $this->assertFalse( $status->isOK() ); $this->assertTrue( $status->hasMessage( 'cantcreateaccount-range-text' ) ); $status = $provider->testUserForCreation( $newuser, false ); - $this->assertInstanceOf( 'StatusValue', $status ); + $this->assertInstanceOf( \StatusValue::class, $status ); $this->assertFalse( $status->isOK() ); $this->assertTrue( $status->hasMessage( 'cantcreateaccount-range-text' ) ); } diff --git a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php index 3757069e34..dd027937cc 100644 --- a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php @@ -58,24 +58,24 @@ class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Fram public function testBeginSecondaryAccountCreation() { $authManager = new AuthManager( new \FauxRequest(), new \HashConfig() ); - $creator = $this->getMockBuilder( 'User' )->getMock(); - $userWithoutEmail = $this->getMockBuilder( 'User' )->getMock(); + $creator = $this->getMockBuilder( \User::class )->getMock(); + $userWithoutEmail = $this->getMockBuilder( \User::class )->getMock(); $userWithoutEmail->expects( $this->any() )->method( 'getEmail' )->willReturn( '' ); $userWithoutEmail->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf(); $userWithoutEmail->expects( $this->never() )->method( 'sendConfirmationMail' ); - $userWithEmailError = $this->getMockBuilder( 'User' )->getMock(); + $userWithEmailError = $this->getMockBuilder( \User::class )->getMock(); $userWithEmailError->expects( $this->any() )->method( 'getEmail' )->willReturn( 'foo@bar.baz' ); $userWithEmailError->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf(); $userWithEmailError->expects( $this->any() )->method( 'sendConfirmationMail' ) ->willReturn( \Status::newFatal( 'fail' ) ); - $userExpectsConfirmation = $this->getMockBuilder( 'User' )->getMock(); + $userExpectsConfirmation = $this->getMockBuilder( \User::class )->getMock(); $userExpectsConfirmation->expects( $this->any() )->method( 'getEmail' ) ->willReturn( 'foo@bar.baz' ); $userExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' ) ->willReturnSelf(); $userExpectsConfirmation->expects( $this->once() )->method( 'sendConfirmationMail' ) ->willReturn( \Status::newGood() ); - $userNotExpectsConfirmation = $this->getMockBuilder( 'User' )->getMock(); + $userNotExpectsConfirmation = $this->getMockBuilder( \User::class )->getMock(); $userNotExpectsConfirmation->expects( $this->any() )->method( 'getEmail' ) ->willReturn( 'foo@bar.baz' ); $userNotExpectsConfirmation->expects( $this->any() )->method( 'getInstanceForUpdate' ) diff --git a/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php index 0fdb08c0e5..38ccb8a3cb 100644 --- a/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php @@ -15,7 +15,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { * @return LegacyHookPreAuthenticationProvider */ protected function getProvider() { - $request = $this->getMockBuilder( 'FauxRequest' ) + $request = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' )->will( $this->returnValue( '127.0.0.42' ) ); @@ -101,7 +101,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { if ( $msgForLoginUserMigrated !== null ) { $h->will( $this->returnCallback( function ( $user, &$msg ) use ( $username, $msgForLoginUserMigrated ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); $msg = $msgForLoginUserMigrated; return false; @@ -111,7 +111,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { } else { $h->will( $this->returnCallback( function ( $user, &$msg ) use ( $username ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); return true; } @@ -122,7 +122,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { function ( $user, $pass, &$abort, &$msg ) use ( $username, $password, $abortForAbortLogin, $msgForAbortLogin ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); if ( $password !== null ) { $this->assertSame( $password, $pass ); @@ -137,7 +137,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { } else { $h2->will( $this->returnCallback( function ( $user, $pass, &$abort, &$msg ) use ( $username, $password ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $username, $user->getName() ); if ( $password !== null ) { $this->assertSame( $password, $pass ); @@ -160,7 +160,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { if ( $failMsg === null ) { $this->assertEquals( \StatusValue::newGood(), $status, 'should succeed' ); } else { - $this->assertInstanceOf( 'StatusValue', $status, 'should fail (type)' ); + $this->assertInstanceOf( \StatusValue::class, $status, 'should fail (type)' ); $this->assertFalse( $status->isOk(), 'should fail (ok)' ); $errors = $status->getErrors(); $this->assertEquals( $failMsg, $errors[0]['message'], 'should fail (message)' ); @@ -289,7 +289,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { ->will( $this->returnCallback( function ( $user, &$error, &$abortStatus ) use ( $msg, $status ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( 'User', $user->getName() ); $error = $msg; $abortStatus = $status; @@ -336,7 +336,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { $this->hook( 'AbortNewAccount', $this->never() ); $this->hook( 'AbortAutoAccount', $this->once() ) ->will( $this->returnCallback( function ( $user, &$abortError ) use ( $testUser, $error ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( \User::class, $user ); $this->assertSame( $testUser->getName(), $user->getName() ); $abortError = $error; return $error === null; @@ -349,7 +349,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { if ( $failMsg === null ) { $this->assertEquals( \StatusValue::newGood(), $status, 'should succeed' ); } else { - $this->assertInstanceOf( 'StatusValue', $status, 'should fail (type)' ); + $this->assertInstanceOf( \StatusValue::class, $status, 'should fail (type)' ); $this->assertFalse( $status->isOk(), 'should fail (ok)' ); $errors = $status->getErrors(); $this->assertEquals( $failMsg, $errors[0]['message'], 'should fail (message)' ); diff --git a/tests/phpunit/includes/auth/PasswordAuthenticationRequestTest.php b/tests/phpunit/includes/auth/PasswordAuthenticationRequestTest.php index 3387e7c9ac..1ef675b6e6 100644 --- a/tests/phpunit/includes/auth/PasswordAuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/PasswordAuthenticationRequestTest.php @@ -129,10 +129,10 @@ class PasswordAuthenticationRequestTest extends AuthenticationRequestTestCase { $ret = $req->describeCredentials(); $this->assertInternalType( 'array', $ret ); $this->assertArrayHasKey( 'provider', $ret ); - $this->assertInstanceOf( 'Message', $ret['provider'] ); + $this->assertInstanceOf( \Message::class, $ret['provider'] ); $this->assertSame( 'authmanager-provider-password', $ret['provider']->getKey() ); $this->assertArrayHasKey( 'account', $ret ); - $this->assertInstanceOf( 'Message', $ret['account'] ); + $this->assertInstanceOf( \Message::class, $ret['account'] ); $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() ); } } diff --git a/tests/phpunit/includes/auth/PasswordDomainAuthenticationRequestTest.php b/tests/phpunit/includes/auth/PasswordDomainAuthenticationRequestTest.php index f746515b09..36be4243ec 100644 --- a/tests/phpunit/includes/auth/PasswordDomainAuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/PasswordDomainAuthenticationRequestTest.php @@ -149,10 +149,10 @@ class PasswordDomainAuthenticationRequestTest extends AuthenticationRequestTestC $ret = $req->describeCredentials(); $this->assertInternalType( 'array', $ret ); $this->assertArrayHasKey( 'provider', $ret ); - $this->assertInstanceOf( 'Message', $ret['provider'] ); + $this->assertInstanceOf( \Message::class, $ret['provider'] ); $this->assertSame( 'authmanager-provider-password-domain', $ret['provider']->getKey() ); $this->assertArrayHasKey( 'account', $ret ); - $this->assertInstanceOf( 'Message', $ret['account'] ); + $this->assertInstanceOf( \Message::class, $ret['account'] ); $this->assertSame( 'authmanager-account-password-domain', $ret['account']->getKey() ); $this->assertSame( [ 'UTSysop', 'd2' ], $ret['account']->getParams() ); } diff --git a/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php b/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php index 05c5165b44..ab4a174eb9 100644 --- a/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/TemporaryPasswordAuthenticationRequestTest.php @@ -70,10 +70,10 @@ class TemporaryPasswordAuthenticationRequestTest extends AuthenticationRequestTe $ret = $req->describeCredentials(); $this->assertInternalType( 'array', $ret ); $this->assertArrayHasKey( 'provider', $ret ); - $this->assertInstanceOf( 'Message', $ret['provider'] ); + $this->assertInstanceOf( \Message::class, $ret['provider'] ); $this->assertSame( 'authmanager-provider-temporarypassword', $ret['provider']->getKey() ); $this->assertArrayHasKey( 'account', $ret ); - $this->assertInstanceOf( 'Message', $ret['account'] ); + $this->assertInstanceOf( \Message::class, $ret['account'] ); $this->assertSame( [ 'UTSysop' ], $ret['account']->getParams() ); } } diff --git a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php index 58982de220..d03b15156c 100644 --- a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php @@ -121,7 +121,7 @@ class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { $user = \User::newFromName( 'RandomUser' ); $creator = \User::newFromName( $creatorname ); if ( $hook ) { - $mock = $this->getMockBuilder( 'stdClass' ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'onExemptFromAccountCreationThrottle' ] ) ->getMock(); $mock->expects( $this->any() )->method( 'onExemptFromAccountCreationThrottle' ) diff --git a/tests/phpunit/includes/cache/LocalisationCacheTest.php b/tests/phpunit/includes/cache/LocalisationCacheTest.php index 5eed01cb2d..42957b6084 100644 --- a/tests/phpunit/includes/cache/LocalisationCacheTest.php +++ b/tests/phpunit/includes/cache/LocalisationCacheTest.php @@ -19,7 +19,7 @@ class LocalisationCacheTest extends MediaWikiTestCase { */ protected function getMockLocalisationCache() { global $IP; - $lc = $this->getMockBuilder( 'LocalisationCache' ) + $lc = $this->getMockBuilder( \LocalisationCache::class ) ->setConstructorArgs( [ [ 'store' => 'detect' ] ] ) ->setMethods( [ 'getMessagesDirs' ] ) ->getMock(); diff --git a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php index e44de099d5..ca3ac1b651 100644 --- a/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php +++ b/tests/phpunit/includes/changes/CategoryMembershipChangeTest.php @@ -48,7 +48,7 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase { public function setUp() { parent::setUp(); self::$notifyCallCounter = 0; - self::$mockRecentChange = self::getMock( 'RecentChange' ); + self::$mockRecentChange = self::getMock( RecentChange::class ); $this->setContentLang( 'qqx' ); } diff --git a/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php b/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php index acac26f04c..2355f7683d 100644 --- a/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php +++ b/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php @@ -168,7 +168,7 @@ class ChangesListStringOptionsFilterGroupTest extends MediaWikiTestCase { } protected function getSpecialPage() { - return $this->getMockBuilder( 'ChangesListSpecialPage' ) + return $this->getMockBuilder( ChangesListSpecialPage::class ) ->setConstructorArgs( [ 'ChangesListSpecialPage', '', @@ -183,8 +183,8 @@ class ChangesListStringOptionsFilterGroupTest extends MediaWikiTestCase { * @dataProvider provideModifyQuery */ protected function modifyQueryHelper( $groupDefinition, $input ) { - $ctx = $this->createMock( 'IContextSource' ); - $dbr = $this->createMock( 'IDatabase' ); + $ctx = $this->createMock( IContextSource::class ); + $dbr = $this->createMock( Wikimedia\Rdbms\IDatabase::class ); $tables = $fields = $conds = $query_options = $join_conds = []; $group = new ChangesListStringOptionsFilterGroup( $groupDefinition ); diff --git a/tests/phpunit/includes/changes/RCCacheEntryFactoryTest.php b/tests/phpunit/includes/changes/RCCacheEntryFactoryTest.php index 97b4c0887c..ac81b28c68 100644 --- a/tests/phpunit/includes/changes/RCCacheEntryFactoryTest.php +++ b/tests/phpunit/includes/changes/RCCacheEntryFactoryTest.php @@ -57,7 +57,7 @@ class RCCacheEntryFactoryTest extends MediaWikiLangTestCase { ); $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false ); - $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry ); + $this->assertInstanceOf( RCCacheEntry::class, $cacheEntry ); $this->assertEquals( false, $cacheEntry->watched, 'watched' ); $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' ); @@ -92,7 +92,7 @@ class RCCacheEntryFactoryTest extends MediaWikiLangTestCase { ); $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false ); - $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry ); + $this->assertInstanceOf( RCCacheEntry::class, $cacheEntry ); $this->assertEquals( false, $cacheEntry->watched, 'watched' ); $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' ); @@ -126,7 +126,7 @@ class RCCacheEntryFactoryTest extends MediaWikiLangTestCase { ); $cacheEntry = $cacheEntryFactory->newFromRecentChange( $recentChange, false ); - $this->assertInstanceOf( 'RCCacheEntry', $cacheEntry ); + $this->assertInstanceOf( RCCacheEntry::class, $cacheEntry ); $this->assertEquals( false, $cacheEntry->watched, 'watched' ); $this->assertEquals( '21:21', $cacheEntry->timestamp, 'timestamp' ); diff --git a/tests/phpunit/includes/composer/ComposerVersionNormalizerTest.php b/tests/phpunit/includes/composer/ComposerVersionNormalizerTest.php index a4cc446342..9ade89248b 100644 --- a/tests/phpunit/includes/composer/ComposerVersionNormalizerTest.php +++ b/tests/phpunit/includes/composer/ComposerVersionNormalizerTest.php @@ -17,7 +17,7 @@ class ComposerVersionNormalizerTest extends PHPUnit_Framework_TestCase { public function testGivenNonString_normalizeThrowsInvalidArgumentException( $nonString ) { $normalizer = new ComposerVersionNormalizer(); - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); $normalizer->normalizeSuffix( $nonString ); } diff --git a/tests/phpunit/includes/config/ConfigFactoryTest.php b/tests/phpunit/includes/config/ConfigFactoryTest.php index c0e51d7e2d..ea747afac1 100644 --- a/tests/phpunit/includes/config/ConfigFactoryTest.php +++ b/tests/phpunit/includes/config/ConfigFactoryTest.php @@ -18,7 +18,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { */ public function testRegisterInvalid() { $factory = new ConfigFactory(); - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); $factory->register( 'invalid', 'Invalid callback' ); } @@ -87,7 +87,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { $this->assertNotSame( $bar, $newBar, 'don\'t salvage if callbacks differ' ); // the new factory doesn't have quux defined, so the quux instance should not be salvaged - $this->setExpectedException( 'ConfigException' ); + $this->setExpectedException( ConfigException::class ); $newFactory->makeConfig( 'quux' ); } @@ -110,7 +110,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { $factory->register( 'unittest', 'GlobalVarConfig::newInstance' ); $conf = $factory->makeConfig( 'unittest' ); - $this->assertInstanceOf( 'Config', $conf ); + $this->assertInstanceOf( Config::class, $conf ); $this->assertSame( $conf, $factory->makeConfig( 'unittest' ) ); } @@ -131,7 +131,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { $factory = new ConfigFactory(); $factory->register( '*', 'GlobalVarConfig::newInstance' ); $conf = $factory->makeConfig( 'unittest' ); - $this->assertInstanceOf( 'Config', $conf ); + $this->assertInstanceOf( Config::class, $conf ); } /** @@ -139,7 +139,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { */ public function testMakeConfigWithNoBuilders() { $factory = new ConfigFactory(); - $this->setExpectedException( 'ConfigException' ); + $this->setExpectedException( ConfigException::class ); $factory->makeConfig( 'nobuilderregistered' ); } @@ -151,7 +151,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { $factory->register( 'unittest', function () { return true; // Not a Config object } ); - $this->setExpectedException( 'UnexpectedValueException' ); + $this->setExpectedException( UnexpectedValueException::class ); $factory->makeConfig( 'unittest' ); } @@ -162,7 +162,7 @@ class ConfigFactoryTest extends MediaWikiTestCase { // NOTE: the global config factory returned here has been overwritten // for operation in test mode. It may not reflect LocalSettings. $factory = MediaWikiServices::getInstance()->getConfigFactory(); - $this->assertInstanceOf( 'Config', $factory->makeConfig( 'main' ) ); + $this->assertInstanceOf( Config::class, $factory->makeConfig( 'main' ) ); } } diff --git a/tests/phpunit/includes/config/GlobalVarConfigTest.php b/tests/phpunit/includes/config/GlobalVarConfigTest.php index a6b220d6f6..db5f73d41e 100644 --- a/tests/phpunit/includes/config/GlobalVarConfigTest.php +++ b/tests/phpunit/includes/config/GlobalVarConfigTest.php @@ -7,7 +7,7 @@ class GlobalVarConfigTest extends MediaWikiTestCase { */ public function testNewInstance() { $config = GlobalVarConfig::newInstance(); - $this->assertInstanceOf( 'GlobalVarConfig', $config ); + $this->assertInstanceOf( GlobalVarConfig::class, $config ); $this->maybeStashGlobal( 'wgBaz' ); $GLOBALS['wgBaz'] = 'somevalue'; // Check prefix is set to 'wg' @@ -24,7 +24,7 @@ class GlobalVarConfigTest extends MediaWikiTestCase { $this->maybeStashGlobal( $var ); $GLOBALS[$var] = $rand; $config = new GlobalVarConfig( $prefix ); - $this->assertInstanceOf( 'GlobalVarConfig', $config ); + $this->assertInstanceOf( GlobalVarConfig::class, $config ); $this->assertEquals( $rand, $config->get( 'GlobalVarConfigTest' ) ); } @@ -83,7 +83,7 @@ class GlobalVarConfigTest extends MediaWikiTestCase { public function testGet( $name, $prefix, $expected ) { $config = new GlobalVarConfig( $prefix ); if ( $expected === false ) { - $this->setExpectedException( 'ConfigException', 'GlobalVarConfig::get: undefined option:' ); + $this->setExpectedException( ConfigException::class, 'GlobalVarConfig::get: undefined option:' ); } $this->assertEquals( $config->get( $name ), $expected ); } diff --git a/tests/phpunit/includes/config/HashConfigTest.php b/tests/phpunit/includes/config/HashConfigTest.php index 19b412d2c6..bac8311cd4 100644 --- a/tests/phpunit/includes/config/HashConfigTest.php +++ b/tests/phpunit/includes/config/HashConfigTest.php @@ -7,7 +7,7 @@ class HashConfigTest extends MediaWikiTestCase { */ public function testNewInstance() { $conf = HashConfig::newInstance(); - $this->assertInstanceOf( 'HashConfig', $conf ); + $this->assertInstanceOf( HashConfig::class, $conf ); } /** @@ -15,7 +15,7 @@ class HashConfigTest extends MediaWikiTestCase { */ public function testConstructor() { $conf = new HashConfig(); - $this->assertInstanceOf( 'HashConfig', $conf ); + $this->assertInstanceOf( HashConfig::class, $conf ); // Test passing arguments to the constructor $conf2 = new HashConfig( [ @@ -32,7 +32,7 @@ class HashConfigTest extends MediaWikiTestCase { 'one' => '1', ] ); $this->assertEquals( '1', $conf->get( 'one' ) ); - $this->setExpectedException( 'ConfigException', 'HashConfig::get: undefined option' ); + $this->setExpectedException( ConfigException::class, 'HashConfig::get: undefined option' ); $conf->get( 'two' ); } diff --git a/tests/phpunit/includes/config/MultiConfigTest.php b/tests/phpunit/includes/config/MultiConfigTest.php index d1eb5102c1..fc2839513b 100644 --- a/tests/phpunit/includes/config/MultiConfigTest.php +++ b/tests/phpunit/includes/config/MultiConfigTest.php @@ -17,7 +17,7 @@ class MultiConfigTest extends MediaWikiTestCase { $this->assertEquals( 'bar', $multi->get( 'foo' ) ); $this->assertEquals( 'foo', $multi->get( 'bar' ) ); - $this->setExpectedException( 'ConfigException', 'MultiConfig::get: undefined option:' ); + $this->setExpectedException( ConfigException::class, 'MultiConfig::get: undefined option:' ); $multi->get( 'notset' ); } diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index 786788bf1a..309b7b1115 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -22,12 +22,12 @@ class ContentHandlerTest extends MediaWikiTestCase { 12312 => 'testing', ], 'wgContentHandlers' => [ - CONTENT_MODEL_WIKITEXT => 'WikitextContentHandler', - CONTENT_MODEL_JAVASCRIPT => 'JavaScriptContentHandler', - CONTENT_MODEL_JSON => 'JsonContentHandler', - CONTENT_MODEL_CSS => 'CssContentHandler', - CONTENT_MODEL_TEXT => 'TextContentHandler', - 'testing' => 'DummyContentHandlerForTesting', + CONTENT_MODEL_WIKITEXT => WikitextContentHandler::class, + CONTENT_MODEL_JAVASCRIPT => JavaScriptContentHandler::class, + CONTENT_MODEL_JSON => JsonContentHandler::class, + CONTENT_MODEL_CSS => CssContentHandler::class, + CONTENT_MODEL_TEXT => TextContentHandler::class, + 'testing' => DummyContentHandlerForTesting::class, 'testing-callbacks' => function ( $modelId ) { return new DummyContentHandlerForTesting( $modelId ); } @@ -394,13 +394,13 @@ class ContentHandlerTest extends MediaWikiTestCase { public function provideGetModelForID() { return [ - [ CONTENT_MODEL_WIKITEXT, 'WikitextContentHandler' ], - [ CONTENT_MODEL_JAVASCRIPT, 'JavaScriptContentHandler' ], - [ CONTENT_MODEL_JSON, 'JsonContentHandler' ], - [ CONTENT_MODEL_CSS, 'CssContentHandler' ], - [ CONTENT_MODEL_TEXT, 'TextContentHandler' ], - [ 'testing', 'DummyContentHandlerForTesting' ], - [ 'testing-callbacks', 'DummyContentHandlerForTesting' ], + [ CONTENT_MODEL_WIKITEXT, WikitextContentHandler::class ], + [ CONTENT_MODEL_JAVASCRIPT, JavaScriptContentHandler::class ], + [ CONTENT_MODEL_JSON, JsonContentHandler::class ], + [ CONTENT_MODEL_CSS, CssContentHandler::class ], + [ CONTENT_MODEL_TEXT, TextContentHandler::class ], + [ 'testing', DummyContentHandlerForTesting::class ], + [ 'testing-callbacks', DummyContentHandlerForTesting::class ], ]; } @@ -432,7 +432,7 @@ class ContentHandlerTest extends MediaWikiTestCase { } private function newSearchEngine() { - $searchEngine = $this->getMockBuilder( 'SearchEngine' ) + $searchEngine = $this->getMockBuilder( SearchEngine::class ) ->getMock(); $searchEngine->expects( $this->any() ) @@ -448,7 +448,7 @@ class ContentHandlerTest extends MediaWikiTestCase { * @covers ContentHandler::getDataForSearchIndex */ public function testDataIndexFields() { - $mockEngine = $this->createMock( 'SearchEngine' ); + $mockEngine = $this->createMock( SearchEngine::class ); $title = Title::newFromText( 'Not_Main_Page', NS_MAIN ); $page = new WikiPage( $title ); diff --git a/tests/phpunit/includes/content/CssContentHandlerTest.php b/tests/phpunit/includes/content/CssContentHandlerTest.php index 8f178de261..7ca1afce8e 100644 --- a/tests/phpunit/includes/content/CssContentHandlerTest.php +++ b/tests/phpunit/includes/content/CssContentHandlerTest.php @@ -13,7 +13,7 @@ class CssContentHandlerTest extends MediaWikiLangTestCase { ] ); $ch = new CssContentHandler(); $content = $ch->makeRedirectContent( Title::newFromText( $title ) ); - $this->assertInstanceOf( 'CssContent', $content ); + $this->assertInstanceOf( CssContent::class, $content ); $this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_CSS ) ); } diff --git a/tests/phpunit/includes/content/FileContentHandlerTest.php b/tests/phpunit/includes/content/FileContentHandlerTest.php index ad9d41958c..9149fc4f57 100644 --- a/tests/phpunit/includes/content/FileContentHandlerTest.php +++ b/tests/phpunit/includes/content/FileContentHandlerTest.php @@ -18,13 +18,13 @@ class FileContentHandlerTest extends MediaWikiLangTestCase { } public function testIndexMapping() { - $mockEngine = $this->createMock( 'SearchEngine' ); + $mockEngine = $this->createMock( SearchEngine::class ); $mockEngine->expects( $this->atLeastOnce() ) ->method( 'makeSearchFieldMapping' ) ->willReturnCallback( function ( $name, $type ) { $mockField = - $this->getMockBuilder( 'SearchIndexFieldDefinition' ) + $this->getMockBuilder( SearchIndexFieldDefinition::class ) ->setMethods( [ 'getMapping' ] ) ->setConstructorArgs( [ $name, $type ] ) ->getMock(); @@ -43,7 +43,7 @@ class FileContentHandlerTest extends MediaWikiLangTestCase { 'file_text' => 1, ]; foreach ( $map as $name => $field ) { - $this->assertInstanceOf( 'SearchIndexField', $field ); + $this->assertInstanceOf( SearchIndexField::class, $field ); $this->assertEquals( $name, $field->getName() ); unset( $expect[$name] ); } diff --git a/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php b/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php index 080ec96558..b5e3ab4a12 100644 --- a/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php +++ b/tests/phpunit/includes/content/JavaScriptContentHandlerTest.php @@ -13,7 +13,7 @@ class JavaScriptContentHandlerTest extends MediaWikiLangTestCase { ] ); $ch = new JavaScriptContentHandler(); $content = $ch->makeRedirectContent( Title::newFromText( $title ) ); - $this->assertInstanceOf( 'JavaScriptContent', $content ); + $this->assertInstanceOf( JavaScriptContent::class, $content ); $this->assertEquals( $expected, $content->serialize( CONTENT_FORMAT_JAVASCRIPT ) ); } diff --git a/tests/phpunit/includes/content/JsonContentTest.php b/tests/phpunit/includes/content/JsonContentTest.php index de8e371ebf..7cddbad26d 100644 --- a/tests/phpunit/includes/content/JsonContentTest.php +++ b/tests/phpunit/includes/content/JsonContentTest.php @@ -82,18 +82,18 @@ class JsonContentTest extends MediaWikiLangTestCase { } private function getMockTitle() { - return $this->getMockBuilder( 'Title' ) + return $this->getMockBuilder( Title::class ) ->disableOriginalConstructor() ->getMock(); } private function getMockUser() { - return $this->getMockBuilder( 'User' ) + return $this->getMockBuilder( User::class ) ->disableOriginalConstructor() ->getMock(); } private function getMockParserOptions() { - return $this->getMockBuilder( 'ParserOptions' ) + return $this->getMockBuilder( ParserOptions::class ) ->disableOriginalConstructor() ->getMock(); } @@ -146,7 +146,7 @@ class JsonContentTest extends MediaWikiLangTestCase { public function testFillParserOutput( $data, $expected ) { $obj = new JsonContent( FormatJson::encode( $data ) ); $parserOutput = $obj->getParserOutput( $this->getMockTitle(), null, null, true ); - $this->assertInstanceOf( 'ParserOutput', $parserOutput ); + $this->assertInstanceOf( ParserOutput::class, $parserOutput ); $this->assertEquals( $expected, $parserOutput->getText() ); } } diff --git a/tests/phpunit/includes/content/TextContentHandlerTest.php b/tests/phpunit/includes/content/TextContentHandlerTest.php index a85215bea4..6d0a3d5ce8 100644 --- a/tests/phpunit/includes/content/TextContentHandlerTest.php +++ b/tests/phpunit/includes/content/TextContentHandlerTest.php @@ -19,13 +19,13 @@ class TextContentHandlerTest extends MediaWikiLangTestCase { public function testFieldsForIndex() { $handler = new TextContentHandler(); - $mockEngine = $this->createMock( 'SearchEngine' ); + $mockEngine = $this->createMock( SearchEngine::class ); $mockEngine->expects( $this->atLeastOnce() ) ->method( 'makeSearchFieldMapping' ) ->willReturnCallback( function ( $name, $type ) { $mockField = - $this->getMockBuilder( 'SearchIndexFieldDefinition' ) + $this->getMockBuilder( SearchIndexFieldDefinition::class ) ->setConstructorArgs( [ $name, $type ] ) ->getMock(); $mockField->expects( $this->atLeastOnce() )->method( 'getMapping' )->willReturn( [ @@ -42,7 +42,7 @@ class TextContentHandlerTest extends MediaWikiLangTestCase { $fields = $handler->getFieldsForSearchIndex( $mockEngine ); $mappedFields = []; foreach ( $fields as $name => $field ) { - $this->assertInstanceOf( 'SearchIndexField', $field ); + $this->assertInstanceOf( SearchIndexField::class, $field ); /** * @var $field SearchIndexField */ diff --git a/tests/phpunit/includes/content/TextContentTest.php b/tests/phpunit/includes/content/TextContentTest.php index 1601493352..b5480911df 100644 --- a/tests/phpunit/includes/content/TextContentTest.php +++ b/tests/phpunit/includes/content/TextContentTest.php @@ -454,7 +454,7 @@ class TextContentTest extends MediaWikiLangTestCase { if ( $expectedNative === false ) { $this->assertFalse( $converted, "conversion to $model was expected to fail!" ); } else { - $this->assertInstanceOf( 'Content', $converted ); + $this->assertInstanceOf( Content::class, $converted ); $this->assertEquals( $expectedNative, $converted->getNativeData() ); } } diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php index dfc07c90f1..59984d85e9 100644 --- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php +++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php @@ -339,7 +339,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase { * @covers WikitextContentHandler::getDataForSearchIndex */ public function testDataIndexFieldsFile() { - $mockEngine = $this->createMock( 'SearchEngine' ); + $mockEngine = $this->createMock( SearchEngine::class ); $title = Title::newFromText( 'Somefile.jpg', NS_FILE ); $page = new WikiPage( $title ); diff --git a/tests/phpunit/includes/content/WikitextContentTest.php b/tests/phpunit/includes/content/WikitextContentTest.php index d0996e3cfc..e04f562429 100644 --- a/tests/phpunit/includes/content/WikitextContentTest.php +++ b/tests/phpunit/includes/content/WikitextContentTest.php @@ -40,7 +40,7 @@ more stuff [ "WikitextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", [ - 'LinksUpdate' => [ + LinksUpdate::class => [ 'mRecursive' => true, 'mLinks' => [] ] @@ -49,7 +49,7 @@ more stuff [ "WikitextContentTest_testGetSecondaryDataUpdates_2", CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n", [ - 'LinksUpdate' => [ + LinksUpdate::class => [ 'mRecursive' => true, 'mLinks' => [ [ 'World_test_21344' => 0 ] @@ -446,11 +446,11 @@ just a test" return [ [ "WikitextContentTest_testGetSecondaryDataUpdates_1", CONTENT_MODEL_WIKITEXT, "hello ''world''\n", - [ 'LinksDeletionUpdate' => [] ] + [ LinksDeletionUpdate::class => [] ] ], [ "WikitextContentTest_testGetSecondaryDataUpdates_2", CONTENT_MODEL_WIKITEXT, "hello [[world test 21344]]\n", - [ 'LinksDeletionUpdate' => [] ] + [ LinksDeletionUpdate::class => [] ] ], // @todo more...? ]; diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index f0a3606fc2..369aa83c7b 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -3,6 +3,7 @@ use Wikimedia\Rdbms\Blob; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\DatabaseSqlite; +use Wikimedia\Rdbms\ResultWrapper; class DatabaseSqliteMock extends DatabaseSqlite { private $lastQuery; @@ -397,7 +398,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $db = DatabaseSqlite::newStandaloneInstance( ':memory:' ); $databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ ); - $this->assertInstanceOf( 'ResultWrapper', $databaseCreation, "Database creation" ); + $this->assertInstanceOf( ResultWrapper::class, $databaseCreation, "Database creation" ); $insertion = $db->insert( 'a', [ 'a_1' => 10 ], __METHOD__ ); $this->assertTrue( $insertion, "Insertion worked" ); @@ -490,7 +491,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $db = DatabaseSqlite::newStandaloneInstance( ':memory:' ); $databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ ); - $this->assertInstanceOf( 'ResultWrapper', $databaseCreation, "Failed to create table a" ); + $this->assertInstanceOf( ResultWrapper::class, $databaseCreation, "Failed to create table a" ); $res = $db->select( 'a', '*' ); $this->assertEquals( 0, $db->numFields( $res ), "expects to get 0 fields for an empty table" ); $insertion = $db->insert( 'a', [ 'a_1' => 10 ], __METHOD__ ); diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index e52dac6908..fa1cfc98ee 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -25,7 +25,9 @@ use Wikimedia\Rdbms\LBFactorySimple; use Wikimedia\Rdbms\LBFactoryMulti; +use Wikimedia\Rdbms\LoadBalancer; use Wikimedia\Rdbms\ChronologyProtector; +use Wikimedia\Rdbms\DatabaseMysqli; use Wikimedia\Rdbms\MySQLMasterPos; use Wikimedia\Rdbms\DatabaseDomain; @@ -41,7 +43,7 @@ class LBFactoryTest extends MediaWikiTestCase { * @dataProvider getLBFactoryClassProvider */ public function testGetLBFactoryClass( $expected, $deprecated ) { - $mockDB = $this->getMockBuilder( 'DatabaseMysqli' ) + $mockDB = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->getMock(); @@ -129,7 +131,7 @@ class LBFactoryTest extends MediaWikiTestCase { $factory = new LBFactorySimple( [ 'servers' => $servers, - 'loadMonitorClass' => 'LoadMonitorNull' + 'loadMonitorClass' => LoadMonitorNull::class ] ); $lb = $factory->getMainLB(); @@ -174,7 +176,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'test-db1' => $wgDBserver, 'test-db2' => $wgDBserver ], - 'loadMonitorClass' => 'LoadMonitorNull' + 'loadMonitorClass' => LoadMonitorNull::class ] ); $lb = $factory->getMainLB(); @@ -199,14 +201,14 @@ class LBFactoryTest extends MediaWikiTestCase { $now = microtime( true ); // Master DB 1 - $mockDB1 = $this->getMockBuilder( 'DatabaseMysqli' ) + $mockDB1 = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->getMock(); $mockDB1->method( 'writesOrCallbacksPending' )->willReturn( true ); $mockDB1->method( 'lastDoneWrites' )->willReturn( $now ); $mockDB1->method( 'getMasterPos' )->willReturn( $m1Pos ); // Load balancer for master DB 1 - $lb1 = $this->getMockBuilder( 'LoadBalancer' ) + $lb1 = $this->getMockBuilder( LoadBalancer::class ) ->disableOriginalConstructor() ->getMock(); $lb1->method( 'getConnection' )->willReturn( $mockDB1 ); @@ -224,14 +226,14 @@ class LBFactoryTest extends MediaWikiTestCase { $lb1->method( 'getMasterPos' )->willReturn( $m1Pos ); $lb1->method( 'getServerName' )->with( 0 )->willReturn( 'master1' ); // Master DB 2 - $mockDB2 = $this->getMockBuilder( 'DatabaseMysqli' ) + $mockDB2 = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->getMock(); $mockDB2->method( 'writesOrCallbacksPending' )->willReturn( true ); $mockDB2->method( 'lastDoneWrites' )->willReturn( $now ); $mockDB2->method( 'getMasterPos' )->willReturn( $m2Pos ); // Load balancer for master DB 2 - $lb2 = $this->getMockBuilder( 'LoadBalancer' ) + $lb2 = $this->getMockBuilder( LoadBalancer::class ) ->disableOriginalConstructor() ->getMock(); $lb2->method( 'getConnection' )->willReturn( $mockDB2 ); @@ -277,7 +279,7 @@ class LBFactoryTest extends MediaWikiTestCase { // (b) Second HTTP request // Load balancer for master DB 1 - $lb1 = $this->getMockBuilder( 'LoadBalancer' ) + $lb1 = $this->getMockBuilder( LoadBalancer::class ) ->disableOriginalConstructor() ->getMock(); $lb1->method( 'getServerCount' )->willReturn( 2 ); @@ -285,7 +287,7 @@ class LBFactoryTest extends MediaWikiTestCase { $lb1->expects( $this->once() ) ->method( 'waitFor' )->with( $this->equalTo( $m1Pos ) ); // Load balancer for master DB 2 - $lb2 = $this->getMockBuilder( 'LoadBalancer' ) + $lb2 = $this->getMockBuilder( LoadBalancer::class ) ->disableOriginalConstructor() ->getMock(); $lb2->method( 'getServerCount' )->willReturn( 2 ); @@ -337,7 +339,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'hostsByName' => [ 'test-db1' => $wgDBserver, ], - 'loadMonitorClass' => 'LoadMonitorNull', + 'loadMonitorClass' => LoadMonitorNull::class, 'localDomain' => new DatabaseDomain( $wgDBname, null, $wgDBprefix ) ] ); } @@ -501,7 +503,7 @@ class LBFactoryTest extends MediaWikiTestCase { } catch ( \Wikimedia\Rdbms\DBConnectionError $e ) { // expected } - $this->assertInstanceOf( '\Wikimedia\Rdbms\DBConnectionError', $e ); + $this->assertInstanceOf( \Wikimedia\Rdbms\DBConnectionError::class, $e ); $this->assertFalse( $db->isOpen() ); } else { \MediaWiki\suppressWarnings(); diff --git a/tests/phpunit/includes/db/LoadBalancerTest.php b/tests/phpunit/includes/db/LoadBalancerTest.php index 54aa2acbdf..fe7b710a1f 100644 --- a/tests/phpunit/includes/db/LoadBalancerTest.php +++ b/tests/phpunit/includes/db/LoadBalancerTest.php @@ -111,7 +111,7 @@ class LoadBalancerTest extends MediaWikiTestCase { $lb = new LoadBalancer( [ 'servers' => $servers, 'localDomain' => new DatabaseDomain( $wgDBname, null, $this->dbPrefix() ), - 'loadMonitorClass' => 'LoadMonitorNull' + 'loadMonitorClass' => LoadMonitorNull::class ] ); $dbw = $lb->getConnection( DB_MASTER ); diff --git a/tests/phpunit/includes/debug/MWDebugTest.php b/tests/phpunit/includes/debug/MWDebugTest.php index 25cfd3cb8b..372f732335 100644 --- a/tests/phpunit/includes/debug/MWDebugTest.php +++ b/tests/phpunit/includes/debug/MWDebugTest.php @@ -99,7 +99,7 @@ class MWDebugTest extends MediaWikiTestCase { MWDebug::appendDebugInfoToApiResult( $context, $result ); - $this->assertInstanceOf( 'ApiResult', $result ); + $this->assertInstanceOf( ApiResult::class, $result ); $data = $result->getResultData(); $expectedKeys = [ 'mwVersion', 'phpEngine', 'phpVersion', 'gitRevision', 'gitBranch', @@ -123,7 +123,7 @@ class MWDebugTest extends MediaWikiTestCase { * @return FauxRequest */ private function newApiRequest( array $params, $requestUrl ) { - $request = $this->getMockBuilder( 'FauxRequest' ) + $request = $this->getMockBuilder( FauxRequest::class ) ->setMethods( [ 'getRequestURL' ] ) ->setConstructorArgs( [ $params diff --git a/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php b/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php index a69b0bfbb4..14e2e27de8 100644 --- a/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php +++ b/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php @@ -164,7 +164,7 @@ class KafkaHandlerTest extends MediaWikiTestCase { [ $this->anything(), $this->anything(), [ 'lines' ] ] ] ); - $formatter = $this->createMock( 'Monolog\Formatter\FormatterInterface' ); + $formatter = $this->createMock( \Monolog\Formatter\FormatterInterface::class ); $formatter->expects( $this->any() ) ->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); @@ -195,7 +195,7 @@ class KafkaHandlerTest extends MediaWikiTestCase { ->method( 'send' ) ->will( $this->returnValue( true ) ); - $formatter = $this->createMock( 'Monolog\Formatter\FormatterInterface' ); + $formatter = $this->createMock( \Monolog\Formatter\FormatterInterface::class ); $formatter->expects( $this->any() ) ->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); diff --git a/tests/phpunit/includes/diff/ArrayDiffFormatterTest.php b/tests/phpunit/includes/diff/ArrayDiffFormatterTest.php index 106b86afaa..8d94404cd4 100644 --- a/tests/phpunit/includes/diff/ArrayDiffFormatterTest.php +++ b/tests/phpunit/includes/diff/ArrayDiffFormatterTest.php @@ -20,7 +20,7 @@ class ArrayDiffFormatterTest extends MediaWikiTestCase { } private function getMockDiff( $edits ) { - $diff = $this->getMockBuilder( 'Diff' ) + $diff = $this->getMockBuilder( Diff::class ) ->disableOriginalConstructor() ->getMock(); $diff->expects( $this->any() ) @@ -30,7 +30,7 @@ class ArrayDiffFormatterTest extends MediaWikiTestCase { } private function getMockDiffOp( $type = null, $orig = [], $closing = [] ) { - $diffOp = $this->getMockBuilder( 'DiffOp' ) + $diffOp = $this->getMockBuilder( DiffOp::class ) ->disableOriginalConstructor() ->getMock(); $diffOp->expects( $this->any() ) diff --git a/tests/phpunit/includes/exception/BadTitleErrorTest.php b/tests/phpunit/includes/exception/BadTitleErrorTest.php index e6a1812584..dcdb1cd198 100644 --- a/tests/phpunit/includes/exception/BadTitleErrorTest.php +++ b/tests/phpunit/includes/exception/BadTitleErrorTest.php @@ -16,7 +16,7 @@ class BadTitleErrorTest extends MediaWikiTestCase { } private function getMockWgOut() { - $mock = $this->getMockBuilder( 'OutputPage' ) + $mock = $this->getMockBuilder( OutputPage::class ) ->disableOriginalConstructor() ->getMock(); $mock->expects( $this->once() ) diff --git a/tests/phpunit/includes/exception/ErrorPageErrorTest.php b/tests/phpunit/includes/exception/ErrorPageErrorTest.php index e72865f6be..49d454e8d9 100644 --- a/tests/phpunit/includes/exception/ErrorPageErrorTest.php +++ b/tests/phpunit/includes/exception/ErrorPageErrorTest.php @@ -7,7 +7,7 @@ class ErrorPageErrorTest extends MediaWikiTestCase { private function getMockMessage() { - $mockMessage = $this->getMockBuilder( 'Message' ) + $mockMessage = $this->getMockBuilder( Message::class ) ->disableOriginalConstructor() ->getMock(); $mockMessage->expects( $this->once() ) @@ -34,7 +34,7 @@ class ErrorPageErrorTest extends MediaWikiTestCase { $title = 'Foo'; $params = [ 'Baz' ]; - $mock = $this->getMockBuilder( 'OutputPage' ) + $mock = $this->getMockBuilder( OutputPage::class ) ->disableOriginalConstructor() ->getMock(); $mock->expects( $this->once() ) diff --git a/tests/phpunit/includes/exception/MWExceptionTest.php b/tests/phpunit/includes/exception/MWExceptionTest.php index 6c5b3b1eae..b16055490c 100644 --- a/tests/phpunit/includes/exception/MWExceptionTest.php +++ b/tests/phpunit/includes/exception/MWExceptionTest.php @@ -44,7 +44,7 @@ class MWExceptionTest extends MediaWikiTestCase { } private function getMockLanguage() { - return $this->getMockBuilder( 'Language' ) + return $this->getMockBuilder( Language::class ) ->disableOriginalConstructor() ->getMock(); } @@ -111,8 +111,8 @@ class MWExceptionTest extends MediaWikiTestCase { public static function provideExceptionClasses() { return [ - [ 'Exception' ], - [ 'MWException' ], + [ Exception::class ], + [ MWException::class ], ]; } @@ -147,7 +147,7 @@ class MWExceptionTest extends MediaWikiTestCase { */ public static function provideJsonSerializedKeys() { $testCases = []; - foreach ( [ 'Exception', 'MWException' ] as $exClass ) { + foreach ( [ Exception::class, MWException::class ] as $exClass ) { $exTests = [ [ 'string', $exClass, 'id' ], [ 'string', $exClass, 'file' ], diff --git a/tests/phpunit/includes/exception/ThrottledErrorTest.php b/tests/phpunit/includes/exception/ThrottledErrorTest.php index 23bb1e8601..15f08966dc 100644 --- a/tests/phpunit/includes/exception/ThrottledErrorTest.php +++ b/tests/phpunit/includes/exception/ThrottledErrorTest.php @@ -17,7 +17,7 @@ class ThrottledErrorTest extends MediaWikiTestCase { } private function getMockWgOut() { - $mock = $this->getMockBuilder( 'OutputPage' ) + $mock = $this->getMockBuilder( OutputPage::class ) ->disableOriginalConstructor() ->getMock(); $mock->expects( $this->once() ) diff --git a/tests/phpunit/includes/filebackend/FileBackendTest.php b/tests/phpunit/includes/filebackend/FileBackendTest.php index ddcf19bde6..31ad1bad5c 100644 --- a/tests/phpunit/includes/filebackend/FileBackendTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendTest.php @@ -101,7 +101,7 @@ class FileBackendTest extends MediaWikiTestCase { 'backends' => [ [ 'name' => 'localmultitesting1', - 'class' => 'FSFileBackend', + 'class' => FSFileBackend::class, 'containerPaths' => [ 'unittest-cont1' => "{$tmpDir}/localtestingmulti1-cont1", 'unittest-cont2' => "{$tmpDir}/localtestingmulti1-cont2" ], @@ -109,7 +109,7 @@ class FileBackendTest extends MediaWikiTestCase { ], [ 'name' => 'localmultitesting2', - 'class' => 'FSFileBackend', + 'class' => FSFileBackend::class, 'containerPaths' => [ 'unittest-cont1' => "{$tmpDir}/localtestingmulti2-cont1", 'unittest-cont2' => "{$tmpDir}/localtestingmulti2-cont2" ], @@ -2411,7 +2411,7 @@ class FileBackendTest extends MediaWikiTestCase { $status = Status::newGood(); $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status ); - $this->assertInstanceOf( 'ScopedLock', $sl, + $this->assertInstanceOf( ScopedLock::class, $sl, "Scoped locking of files succeeded ($backendName)." ); $this->assertEquals( [], $status->getErrors(), "Scoped locking of files succeeded ($backendName)." ); @@ -2436,7 +2436,7 @@ class FileBackendTest extends MediaWikiTestCase { $be = TestingAccessWrapper::newFromObject( new MemoryFileBackend( [ 'name' => 'testing', - 'class' => 'MemoryFileBackend', + 'class' => MemoryFileBackend::class, 'wikiId' => 'meow', 'mimeCallback' => $mimeCallback ] @@ -2471,13 +2471,13 @@ class FileBackendTest extends MediaWikiTestCase { 'backends' => [ [ // backend 0 'name' => 'multitesting0', - 'class' => 'MemoryFileBackend', + 'class' => MemoryFileBackend::class, 'isMultiMaster' => false, 'readAffinity' => true ], [ // backend 1 'name' => 'multitesting1', - 'class' => 'MemoryFileBackend', + 'class' => MemoryFileBackend::class, 'isMultiMaster' => true ] ] @@ -2521,12 +2521,12 @@ class FileBackendTest extends MediaWikiTestCase { 'backends' => [ [ // backend 0 'name' => 'multitesting0', - 'class' => 'MemoryFileBackend', + 'class' => MemoryFileBackend::class, 'isMultiMaster' => false ], [ // backend 1 'name' => 'multitesting1', - 'class' => 'MemoryFileBackend', + 'class' => MemoryFileBackend::class, 'isMultiMaster' => true ] ], diff --git a/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php b/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php index b57af25a49..35eca28f7e 100644 --- a/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php +++ b/tests/phpunit/includes/filebackend/SwiftFileBackendTest.php @@ -22,7 +22,7 @@ class SwiftFileBackendTest extends MediaWikiTestCase { $this->backend = TestingAccessWrapper::newFromObject( new SwiftFileBackend( [ 'name' => 'local-swift-testing', - 'class' => 'SwiftFileBackend', + 'class' => SwiftFileBackend::class, 'wikiId' => 'unit-testing', 'lockManager' => LockManagerGroup::singleton()->get( 'fsLockManager' ), 'swiftAuthUrl' => 'http://127.0.0.1:8080/auth', // unused diff --git a/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php b/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php index 0d00fbc284..4c9855b074 100644 --- a/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php @@ -112,19 +112,19 @@ class FileBackendDBRepoWrapperTest extends MediaWikiTestCase { } protected function getMocks() { - $dbMock = $this->getMockBuilder( 'DatabaseMysqli' ) + $dbMock = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class ) ->disableOriginalClone() ->disableOriginalConstructor() ->getMock(); - $backendMock = $this->getMockBuilder( 'FSFileBackend' ) + $backendMock = $this->getMockBuilder( FSFileBackend::class ) ->setConstructorArgs( [ [ 'name' => $this->backendName, 'wikiId' => wfWikiID() ] ] ) ->getMock(); - $wrapperMock = $this->getMockBuilder( 'FileBackendDBRepoWrapper' ) + $wrapperMock = $this->getMockBuilder( FileBackendDBRepoWrapper::class ) ->setMethods( [ 'getDB' ] ) ->setConstructorArgs( [ [ 'backend' => $backendMock, diff --git a/tests/phpunit/includes/filerepo/FileRepoTest.php b/tests/phpunit/includes/filerepo/FileRepoTest.php index d1e6dc39ad..0d3e679aa8 100644 --- a/tests/phpunit/includes/filerepo/FileRepoTest.php +++ b/tests/phpunit/includes/filerepo/FileRepoTest.php @@ -50,6 +50,6 @@ class FileRepoTest extends MediaWikiTestCase { 'containerPaths' => [] ] ) ] ); - $this->assertInstanceOf( 'FileRepo', $f ); + $this->assertInstanceOf( FileRepo::class, $f ); } } diff --git a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php index 205df9cdcd..9beea5b630 100644 --- a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php +++ b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php @@ -28,7 +28,7 @@ class MigrateFileRepoLayoutTest extends MediaWikiTestCase { ] ] ); - $dbMock = $this->getMockBuilder( 'DatabaseMysqli' ) + $dbMock = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class ) ->disableOriginalConstructor() ->getMock(); @@ -44,7 +44,7 @@ class MigrateFileRepoLayoutTest extends MediaWikiTestCase { new FakeResultWrapper( [] ) // filearchive ) ); - $repoMock = $this->getMockBuilder( 'LocalRepo' ) + $repoMock = $this->getMockBuilder( LocalRepo::class ) ->setMethods( [ 'getMasterDB' ] ) ->setConstructorArgs( [ [ 'name' => 'migratefilerepolayouttest', @@ -57,7 +57,7 @@ class MigrateFileRepoLayoutTest extends MediaWikiTestCase { ->method( 'getMasterDB' ) ->will( $this->returnValue( $dbMock ) ); - $this->migratorMock = $this->getMockBuilder( 'MigrateFileRepoLayout' ) + $this->migratorMock = $this->getMockBuilder( MigrateFileRepoLayout::class ) ->setMethods( [ 'getRepo' ] )->getMock(); $this->migratorMock ->expects( $this->any() ) diff --git a/tests/phpunit/includes/filerepo/RepoGroupTest.php b/tests/phpunit/includes/filerepo/RepoGroupTest.php index 6f04c669a9..5a343f6529 100644 --- a/tests/phpunit/includes/filerepo/RepoGroupTest.php +++ b/tests/phpunit/includes/filerepo/RepoGroupTest.php @@ -19,7 +19,7 @@ class RepoGroupTest extends MediaWikiTestCase { function testForEachForeignRepo() { $this->setUpForeignRepo(); - $fakeCallback = $this->createMock( 'RepoGroupTestHelper' ); + $fakeCallback = $this->createMock( RepoGroupTestHelper::class ); $fakeCallback->expects( $this->once() )->method( 'callback' ); RepoGroup::singleton()->forEachForeignRepo( [ $fakeCallback, 'callback' ], [ [] ] ); @@ -29,7 +29,7 @@ class RepoGroupTest extends MediaWikiTestCase { $this->setMwGlobals( 'wgForeignFileRepos', [] ); RepoGroup::destroySingleton(); FileBackendGroup::destroySingleton(); - $fakeCallback = $this->createMock( 'RepoGroupTestHelper' ); + $fakeCallback = $this->createMock( RepoGroupTestHelper::class ); $fakeCallback->expects( $this->never() )->method( 'callback' ); RepoGroup::singleton()->forEachForeignRepo( [ $fakeCallback, 'callback' ], [ [] ] ); @@ -38,7 +38,7 @@ class RepoGroupTest extends MediaWikiTestCase { private function setUpForeignRepo() { global $wgUploadDirectory; $this->setMwGlobals( 'wgForeignFileRepos', [ [ - 'class' => 'ForeignAPIRepo', + 'class' => ForeignAPIRepo::class, 'name' => 'wikimediacommons', 'backend' => 'wikimediacommons-backend', 'apibase' => 'https://commons.wikimedia.org/w/api.php', diff --git a/tests/phpunit/includes/filerepo/file/FileTest.php b/tests/phpunit/includes/filerepo/file/FileTest.php index 62e102652d..3f4e46b5b0 100644 --- a/tests/phpunit/includes/filerepo/file/FileTest.php +++ b/tests/phpunit/includes/filerepo/file/FileTest.php @@ -38,7 +38,7 @@ class FileTest extends MediaWikiMediaTestCase { $this->setMwGlobals( 'wgThumbnailBuckets', $data['buckets'] ); $this->setMwGlobals( 'wgThumbnailMinimumBucketDistance', $data['minimumBucketDistance'] ); - $fileMock = $this->getMockBuilder( 'File' ) + $fileMock = $this->getMockBuilder( File::class ) ->setConstructorArgs( [ 'fileMock', false ] ) ->setMethods( [ 'getWidth' ] ) ->getMockForAbstractClass(); @@ -137,11 +137,11 @@ class FileTest extends MediaWikiMediaTestCase { * @covers File::getThumbnailSource */ public function testGetThumbnailSource( $data ) { - $backendMock = $this->getMockBuilder( 'FSFileBackend' ) + $backendMock = $this->getMockBuilder( FSFileBackend::class ) ->setConstructorArgs( [ [ 'name' => 'backendMock', 'wikiId' => wfWikiID() ] ] ) ->getMock(); - $repoMock = $this->getMockBuilder( 'FileRepo' ) + $repoMock = $this->getMockBuilder( FileRepo::class ) ->setConstructorArgs( [ [ 'name' => 'repoMock', 'backend' => $backendMock ] ] ) ->setMethods( [ 'fileExists', 'getLocalReference' ] ) ->getMock(); @@ -156,13 +156,13 @@ class FileTest extends MediaWikiMediaTestCase { ->method( 'getLocalReference' ) ->will( $this->returnValue( $fsFile ) ); - $handlerMock = $this->getMockBuilder( 'BitmapHandler' ) + $handlerMock = $this->getMockBuilder( BitmapHandler::class ) ->setMethods( [ 'supportsBucketing' ] )->getMock(); $handlerMock->expects( $this->any() ) ->method( 'supportsBucketing' ) ->will( $this->returnValue( $data['supportsBucketing'] ) ); - $fileMock = $this->getMockBuilder( 'File' ) + $fileMock = $this->getMockBuilder( File::class ) ->setConstructorArgs( [ 'fileMock', $repoMock ] ) ->setMethods( [ 'getThumbnailBucket', 'getLocalRefPath', 'getHandler' ] ) ->getMockForAbstractClass(); @@ -248,22 +248,22 @@ class FileTest extends MediaWikiMediaTestCase { public function testGenerateBucketsIfNeeded( $data ) { $this->setMwGlobals( 'wgThumbnailBuckets', $data['buckets'] ); - $backendMock = $this->getMockBuilder( 'FSFileBackend' ) + $backendMock = $this->getMockBuilder( FSFileBackend::class ) ->setConstructorArgs( [ [ 'name' => 'backendMock', 'wikiId' => wfWikiID() ] ] ) ->getMock(); - $repoMock = $this->getMockBuilder( 'FileRepo' ) + $repoMock = $this->getMockBuilder( FileRepo::class ) ->setConstructorArgs( [ [ 'name' => 'repoMock', 'backend' => $backendMock ] ] ) ->setMethods( [ 'fileExists', 'getLocalReference' ] ) ->getMock(); - $fileMock = $this->getMockBuilder( 'File' ) + $fileMock = $this->getMockBuilder( File::class ) ->setConstructorArgs( [ 'fileMock', $repoMock ] ) ->setMethods( [ 'getWidth', 'getBucketThumbPath', 'makeTransformTmpFile', 'generateAndSaveThumb', 'getHandler' ] ) ->getMockForAbstractClass(); - $handlerMock = $this->getMockBuilder( 'JpegHandler' ) + $handlerMock = $this->getMockBuilder( JpegHandler::class ) ->setMethods( [ 'supportsBucketing' ] )->getMock(); $handlerMock->expects( $this->any() ) ->method( 'supportsBucketing' ) @@ -273,7 +273,7 @@ class FileTest extends MediaWikiMediaTestCase { ->method( 'getHandler' ) ->will( $this->returnValue( $handlerMock ) ); - $reflectionMethod = new ReflectionMethod( 'File', 'generateBucketsIfNeeded' ); + $reflectionMethod = new ReflectionMethod( File::class, 'generateBucketsIfNeeded' ); $reflectionMethod->setAccessible( true ); $fileMock->expects( $this->any() ) diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php index ffaa2c32bf..e25e6064db 100644 --- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php +++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php @@ -176,7 +176,7 @@ class LocalFileTest extends MediaWikiTestCase { $file = wfLocalFile( "File:Some_file_that_probably_doesn't exist.png" ); $this->assertThat( $file, - $this->isInstanceOf( 'LocalFile' ), + $this->isInstanceOf( LocalFile::class ), 'wfLocalFile() returns LocalFile for valid Titles' ); } diff --git a/tests/phpunit/includes/htmlform/HTMLCheckMatrixTest.php b/tests/phpunit/includes/htmlform/HTMLCheckMatrixTest.php index c1aa1d7109..e7922fd2bd 100644 --- a/tests/phpunit/includes/htmlform/HTMLCheckMatrixTest.php +++ b/tests/phpunit/includes/htmlform/HTMLCheckMatrixTest.php @@ -15,7 +15,7 @@ class HTMLCheckMatrixTest extends MediaWikiTestCase { try { new HTMLCheckMatrix( [] ); } catch ( MWException $e ) { - $this->assertInstanceOf( 'HTMLFormFieldRequiredOptionsException', $e ); + $this->assertInstanceOf( HTMLFormFieldRequiredOptionsException::class, $e ); return; } diff --git a/tests/phpunit/includes/interwiki/ClassicInterwikiLookupTest.php b/tests/phpunit/includes/interwiki/ClassicInterwikiLookupTest.php index fd3b0b856a..7fb2cd4959 100644 --- a/tests/phpunit/includes/interwiki/ClassicInterwikiLookupTest.php +++ b/tests/phpunit/includes/interwiki/ClassicInterwikiLookupTest.php @@ -68,7 +68,7 @@ class ClassicInterwikiLookupTest extends MediaWikiTestCase { $this->assertFalse( $lookup->fetch( 'xyz' ), 'unknown prefix' ); $interwiki = $lookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( $interwiki, $lookup->fetch( 'de' ), 'in-process caching' ); $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); @@ -169,13 +169,13 @@ class ClassicInterwikiLookupTest extends MediaWikiTestCase { $this->assertTrue( $lookup->isValidInterwiki( 'zz' ), 'known prefix is valid' ); $interwiki = $lookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); $this->assertSame( true, $interwiki->isLocal(), 'isLocal' ); $interwiki = $lookup->fetch( 'zz' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( 'http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL' ); $this->assertSame( false, $interwiki->isLocal(), 'isLocal' ); @@ -220,13 +220,13 @@ class ClassicInterwikiLookupTest extends MediaWikiTestCase { $this->assertTrue( $lookup->isValidInterwiki( 'zz' ), 'known prefix is valid' ); $interwiki = $lookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); $this->assertSame( true, $interwiki->isLocal(), 'isLocal' ); $interwiki = $lookup->fetch( 'zz' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( 'http://zzwiki.org/wiki/', $interwiki->getURL(), 'getURL' ); $this->assertSame( false, $interwiki->isLocal(), 'isLocal' ); diff --git a/tests/phpunit/includes/interwiki/InterwikiTest.php b/tests/phpunit/includes/interwiki/InterwikiTest.php index 22b1304b7a..0d41c520db 100644 --- a/tests/phpunit/includes/interwiki/InterwikiTest.php +++ b/tests/phpunit/includes/interwiki/InterwikiTest.php @@ -106,7 +106,7 @@ class InterwikiTest extends MediaWikiTestCase { $this->assertFalse( $interwikiLookup->fetch( 'xyz' ), 'unknown prefix' ); $interwiki = $interwikiLookup->fetch( 'de' ); - $this->assertInstanceOf( 'Interwiki', $interwiki ); + $this->assertInstanceOf( Interwiki::class, $interwiki ); $this->assertSame( $interwiki, $interwikiLookup->fetch( 'de' ), 'in-process caching' ); $this->assertSame( 'http://de.wikipedia.org/wiki/', $interwiki->getURL(), 'getURL' ); diff --git a/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php b/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php index edba75ce2e..d5a267e5b4 100644 --- a/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php +++ b/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php @@ -17,7 +17,7 @@ class JobQueueMemoryTest extends PHPUnit_Framework_TestCase { */ private function newJobQueue() { return JobQueue::factory( [ - 'class' => 'JobQueueMemory', + 'class' => JobQueueMemory::class, 'wiki' => wfWikiID(), 'type' => 'null', ] ); @@ -54,7 +54,7 @@ class JobQueueMemoryTest extends PHPUnit_Framework_TestCase { public function testJobFromSpecInternal() { $queue = $this->newJobQueue(); $job = $queue->jobFromSpecInternal( $this->newJobSpecification() ); - $this->assertInstanceOf( 'Job', $job ); + $this->assertInstanceOf( Job::class, $job ); $this->assertSame( 'null', $job->getType() ); $this->assertArrayHasKey( 'customParameter', $job->getParams() ); $this->assertSame( 'Custom title', $job->getTitle()->getText() ); diff --git a/tests/phpunit/includes/jobqueue/JobQueueTest.php b/tests/phpunit/includes/jobqueue/JobQueueTest.php index bd21dc8a3e..0625edd8b5 100644 --- a/tests/phpunit/includes/jobqueue/JobQueueTest.php +++ b/tests/phpunit/includes/jobqueue/JobQueueTest.php @@ -28,7 +28,7 @@ class JobQueueTest extends MediaWikiTestCase { } $baseConfig = $wgJobTypeConf[$name]; } else { - $baseConfig = [ 'class' => 'JobQueueDBSingle' ]; + $baseConfig = [ 'class' => JobQueueDBSingle::class ]; } $baseConfig['type'] = 'null'; $baseConfig['wiki'] = wfWikiID(); @@ -234,7 +234,7 @@ class JobQueueTest extends MediaWikiTestCase { $j = $queue->pop(); // Make sure ack() of the twin did not delete the sibling data - $this->assertType( 'NullJob', $j ); + $this->assertType( NullJob::class, $j ); } /** diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php index 395d12c5d9..0cab702439 100644 --- a/tests/phpunit/includes/jobqueue/JobTest.php +++ b/tests/phpunit/includes/jobqueue/JobTest.php @@ -18,7 +18,7 @@ class JobTest extends MediaWikiTestCase { } public function provideTestToString() { - $mockToStringObj = $this->getMockBuilder( 'stdClass' ) + $mockToStringObj = $this->getMockBuilder( stdClass::class ) ->setMethods( [ '__toString' ] )->getMock(); $mockToStringObj->expects( $this->any() ) ->method( '__toString' ) @@ -86,7 +86,7 @@ class JobTest extends MediaWikiTestCase { public function getMockJob( $params ) { $mock = $this->getMockForAbstractClass( - 'Job', + Job::class, [ 'someCommand', new Title(), $params ], 'SomeJob' ); diff --git a/tests/phpunit/includes/json/FormatJsonTest.php b/tests/phpunit/includes/json/FormatJsonTest.php index d252c80732..a4ab879ffb 100644 --- a/tests/phpunit/includes/json/FormatJsonTest.php +++ b/tests/phpunit/includes/json/FormatJsonTest.php @@ -159,12 +159,12 @@ class FormatJsonTest extends MediaWikiTestCase { $this->assertJson( $json ); $st = FormatJson::parse( $json ); - $this->assertInstanceOf( 'Status', $st ); + $this->assertInstanceOf( Status::class, $st ); $this->assertTrue( $st->isGood() ); $this->assertEquals( $expected, $st->getValue() ); $st = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); - $this->assertInstanceOf( 'Status', $st ); + $this->assertInstanceOf( Status::class, $st ); $this->assertTrue( $st->isGood() ); $this->assertEquals( $value, $st->getValue() ); } @@ -230,7 +230,7 @@ class FormatJsonTest extends MediaWikiTestCase { } $st = FormatJson::parse( $value, FormatJson::TRY_FIXING ); - $this->assertInstanceOf( 'Status', $st ); + $this->assertInstanceOf( Status::class, $st ); if ( $expected === false ) { $this->assertFalse( $st->isOK(), 'Expected isOK() == false' ); } else { @@ -256,7 +256,7 @@ class FormatJsonTest extends MediaWikiTestCase { */ public function testParseErrors( $value ) { $st = FormatJson::parse( $value ); - $this->assertInstanceOf( 'Status', $st ); + $this->assertInstanceOf( Status::class, $st ); $this->assertFalse( $st->isOK() ); } @@ -313,7 +313,7 @@ class FormatJsonTest extends MediaWikiTestCase { */ public function testParseStripComments( $json, $expect ) { $st = FormatJson::parse( $json, FormatJson::STRIP_COMMENTS ); - $this->assertInstanceOf( 'Status', $st ); + $this->assertInstanceOf( Status::class, $st ); $this->assertTrue( $st->isGood() ); $this->assertEquals( $expect, $st->getValue() ); } diff --git a/tests/phpunit/includes/libs/DeferredStringifierTest.php b/tests/phpunit/includes/libs/DeferredStringifierTest.php index 19dc53cb4c..c9958403f9 100644 --- a/tests/phpunit/includes/libs/DeferredStringifierTest.php +++ b/tests/phpunit/includes/libs/DeferredStringifierTest.php @@ -11,7 +11,7 @@ class DeferredStringifierTest extends PHPUnit_Framework_TestCase { * @dataProvider provideToString */ public function testToString( $params, $expected ) { - $class = new ReflectionClass( 'DeferredStringifier' ); + $class = new ReflectionClass( DeferredStringifier::class ); $ds = $class->newInstanceArgs( $params ); $this->assertEquals( $expected, (string)$ds ); } diff --git a/tests/phpunit/includes/libs/MemoizedCallableTest.php b/tests/phpunit/includes/libs/MemoizedCallableTest.php index ba8af9352e..d09171ce8e 100644 --- a/tests/phpunit/includes/libs/MemoizedCallableTest.php +++ b/tests/phpunit/includes/libs/MemoizedCallableTest.php @@ -33,7 +33,7 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { * way as the original underlying callable. */ public function testReturnValuePassedThrough() { - $mock = $this->getMockBuilder( 'stdClass' ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'reverse' ] )->getMock(); $mock->expects( $this->any() ) ->method( 'reverse' ) @@ -50,7 +50,7 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { * @requires function apc_store/apcu_store */ public function testCallableMemoized() { - $observer = $this->getMockBuilder( 'stdClass' ) + $observer = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'computeSomething' ] )->getMock(); $observer->expects( $this->once() ) ->method( 'computeSomething' ) diff --git a/tests/phpunit/includes/libs/ObjectFactoryTest.php b/tests/phpunit/includes/libs/ObjectFactoryTest.php index 03814da636..18d7d05642 100644 --- a/tests/phpunit/includes/libs/ObjectFactoryTest.php +++ b/tests/phpunit/includes/libs/ObjectFactoryTest.php @@ -27,7 +27,7 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { */ public function testClosureExpansionDisabled() { $obj = ObjectFactory::getObjectFromSpec( [ - 'class' => 'ObjectFactoryTestFixture', + 'class' => ObjectFactoryTestFixture::class, 'args' => [ function () { return 'wrapped'; @@ -54,7 +54,7 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { */ public function testClosureExpansionEnabled() { $obj = ObjectFactory::getObjectFromSpec( [ - 'class' => 'ObjectFactoryTestFixture', + 'class' => ObjectFactoryTestFixture::class, 'args' => [ function () { return 'wrapped'; @@ -75,7 +75,7 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { $this->assertSame( 'wrapped', $obj->setterArgs[0] ); $obj = ObjectFactory::getObjectFromSpec( [ - 'class' => 'ObjectFactoryTestFixture', + 'class' => ObjectFactoryTestFixture::class, 'args' => [ function () { return 'unwrapped'; }, ], @@ -123,7 +123,7 @@ class ObjectFactoryTest extends PHPUnit_Framework_TestCase { */ public function testGetObjectFromClass( $args ) { $obj = ObjectFactory::getObjectFromSpec( [ - 'class' => 'ObjectFactoryTestFixture', + 'class' => ObjectFactoryTestFixture::class, 'args' => $args, ] ); $this->assertSame( $args, $obj->args ); diff --git a/tests/phpunit/includes/libs/XhprofTest.php b/tests/phpunit/includes/libs/XhprofTest.php index c9123b8889..e2723b9dc9 100644 --- a/tests/phpunit/includes/libs/XhprofTest.php +++ b/tests/phpunit/includes/libs/XhprofTest.php @@ -31,7 +31,7 @@ class XhprofTest extends PHPUnit_Framework_TestCase { * @covers Xhprof::enable */ public function testEnable() { - $xhprof = new ReflectionClass( 'Xhprof' ); + $xhprof = new ReflectionClass( Xhprof::class ); $enabled = $xhprof->getProperty( 'enabled' ); $enabled->setAccessible( true ); $enabled->setValue( true ); diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index 7053fc18ba..a2c3bdcdbb 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -621,7 +621,7 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { $this->assertEquals( count( $ids ), $calls, "Values cached" ); // Mock the BagOStuff to assure only one getMulti() call given process caching - $localBag = $this->getMockBuilder( 'HashBagOStuff' ) + $localBag = $this->getMockBuilder( HashBagOStuff::class ) ->setMethods( [ 'getMulti' ] )->getMock(); $localBag->expects( $this->exactly( 1 ) )->method( 'getMulti' )->willReturn( [ WANObjectCache::VALUE_KEY_PREFIX . 'k1' => 'val-id1', @@ -1474,7 +1474,7 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { } public function testMcRouterSupport() { - $localBag = $this->getMockBuilder( 'EmptyBagOStuff' ) + $localBag = $this->getMockBuilder( EmptyBagOStuff::class ) ->setMethods( [ 'set', 'delete' ] )->getMock(); $localBag->expects( $this->never() )->method( 'set' ); $localBag->expects( $this->never() )->method( 'delete' ); diff --git a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php index 5e59cfdb78..a23a2a0096 100644 --- a/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DatabaseMysqlBaseTest.php @@ -27,6 +27,7 @@ use Wikimedia\Rdbms\TransactionProfiler; use Wikimedia\Rdbms\DatabaseDomain; use Wikimedia\Rdbms\MySQLMasterPos; use Wikimedia\Rdbms\DatabaseMysqlBase; +use Wikimedia\Rdbms\DatabaseMysqli; use Wikimedia\Rdbms\Database; /** @@ -176,7 +177,7 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { } private function getMockForViews() { - $db = $this->getMockBuilder( 'DatabaseMysqli' ) + $db = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->setMethods( [ 'fetchRow', 'query' ] ) ->getMock(); @@ -325,7 +326,7 @@ class DatabaseMysqlBaseTest extends PHPUnit_Framework_TestCase { * @covers Wikimedia\Rdbms\DatabaseMysqlBase::getLagFromPtHeartbeat */ public function testPtHeartbeat( $lag ) { - $db = $this->getMockBuilder( 'DatabaseMysqli' ) + $db = $this->getMockBuilder( DatabaseMysqli::class ) ->disableOriginalConstructor() ->setMethods( [ 'getLagDetectionMethod', 'getHeartbeatData', 'getMasterServerInfo' ] ) diff --git a/tests/phpunit/includes/logging/LogFormatterTest.php b/tests/phpunit/includes/logging/LogFormatterTest.php index 012b0a3aa5..e523a31e81 100644 --- a/tests/phpunit/includes/logging/LogFormatterTest.php +++ b/tests/phpunit/includes/logging/LogFormatterTest.php @@ -53,8 +53,8 @@ class LogFormatterTest extends MediaWikiLangTestCase { $this->setMwGlobals( [ 'wgLogTypes' => [ 'phpunit' ], - 'wgLogActionsHandlers' => [ 'phpunit/test' => 'LogFormatter', - 'phpunit/param' => 'LogFormatter' ], + 'wgLogActionsHandlers' => [ 'phpunit/test' => LogFormatter::class, + 'phpunit/param' => LogFormatter::class ], 'wgUser' => User::newFromName( 'Testuser' ), ] ); diff --git a/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php index 8317e91bb2..eee2981c18 100644 --- a/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php +++ b/tests/phpunit/includes/logging/NewUsersLogFormatterTest.php @@ -11,11 +11,11 @@ class NewUsersLogFormatterTest extends LogFormatterTestCase { // Register LogHandler, see $wgNewUserLog in Setup.php $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', [ - 'newusers/newusers' => 'NewUsersLogFormatter', - 'newusers/create' => 'NewUsersLogFormatter', - 'newusers/create2' => 'NewUsersLogFormatter', - 'newusers/byemail' => 'NewUsersLogFormatter', - 'newusers/autocreate' => 'NewUsersLogFormatter', + 'newusers/newusers' => NewUsersLogFormatter::class, + 'newusers/create' => NewUsersLogFormatter::class, + 'newusers/create2' => NewUsersLogFormatter::class, + 'newusers/byemail' => NewUsersLogFormatter::class, + 'newusers/autocreate' => NewUsersLogFormatter::class, ] ); } diff --git a/tests/phpunit/includes/logging/PageLangLogFormatterTest.php b/tests/phpunit/includes/logging/PageLangLogFormatterTest.php index 081901567e..33fd68f6c3 100644 --- a/tests/phpunit/includes/logging/PageLangLogFormatterTest.php +++ b/tests/phpunit/includes/logging/PageLangLogFormatterTest.php @@ -12,7 +12,7 @@ class PageLangLogFormatterTest extends LogFormatterTestCase { $this->setMwGlobals( 'wgHooks', [] ); // Register LogHandler, see $wgPageLanguageUseDB in Setup.php $this->mergeMwGlobalArrayValue( 'wgLogActionsHandlers', [ - 'pagelang/pagelang' => 'PageLangLogFormatter', + 'pagelang/pagelang' => PageLangLogFormatter::class, ] ); } diff --git a/tests/phpunit/includes/mail/MailAddressTest.php b/tests/phpunit/includes/mail/MailAddressTest.php index c837d26f5b..d0bd698084 100644 --- a/tests/phpunit/includes/mail/MailAddressTest.php +++ b/tests/phpunit/includes/mail/MailAddressTest.php @@ -7,7 +7,7 @@ class MailAddressTest extends MediaWikiTestCase { */ public function testConstructor() { $ma = new MailAddress( 'foo@bar.baz', 'UserName', 'Real name' ); - $this->assertInstanceOf( 'MailAddress', $ma ); + $this->assertInstanceOf( MailAddress::class, $ma ); } /** @@ -17,7 +17,7 @@ class MailAddressTest extends MediaWikiTestCase { if ( wfIsWindows() ) { $this->markTestSkipped( 'This test only works on non-Windows platforms' ); } - $user = $this->createMock( 'User' ); + $user = $this->createMock( User::class ); $user->expects( $this->any() )->method( 'getName' )->will( $this->returnValue( 'UserName' ) ); @@ -29,7 +29,7 @@ class MailAddressTest extends MediaWikiTestCase { ); $ma = MailAddress::newFromUser( $user ); - $this->assertInstanceOf( 'MailAddress', $ma ); + $this->assertInstanceOf( MailAddress::class, $ma ); $this->setMwGlobals( 'wgEnotifUseRealName', true ); $this->assertEquals( 'Real name ', $ma->toString() ); $this->setMwGlobals( 'wgEnotifUseRealName', false ); diff --git a/tests/phpunit/includes/media/BitmapScalingTest.php b/tests/phpunit/includes/media/BitmapScalingTest.php index 92a927f8ec..fb96f7dbc1 100644 --- a/tests/phpunit/includes/media/BitmapScalingTest.php +++ b/tests/phpunit/includes/media/BitmapScalingTest.php @@ -124,7 +124,7 @@ class BitmapScalingTest extends MediaWikiTestCase { $file = new FakeDimensionFile( [ 4000, 4000 ] ); $handler = new BitmapHandler; $params = [ 'width' => '3700' ]; // Still bigger than max size. - $this->assertEquals( 'TransformTooBigImageAreaError', + $this->assertEquals( TransformTooBigImageAreaError::class, get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); } @@ -136,7 +136,7 @@ class BitmapScalingTest extends MediaWikiTestCase { $file->mustRender = true; $handler = new BitmapHandler; $params = [ 'width' => '5000' ]; // Still bigger than max size. - $this->assertEquals( 'TransformTooBigImageAreaError', + $this->assertEquals( TransformTooBigImageAreaError::class, get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) ); } diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index 16ae1937b3..0987bd0ac5 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -44,7 +44,7 @@ class FormatMetadataTest extends MediaWikiMediaTestCase { */ public function testResolveMultivalueValue( $input, $output ) { $formatMetadata = new FormatMetadata(); - $class = new ReflectionClass( 'FormatMetadata' ); + $class = new ReflectionClass( FormatMetadata::class ); $method = $class->getMethod( 'resolveMultivalueValue' ); $method->setAccessible( true ); $actualInput = $method->invoke( $formatMetadata, $input ); diff --git a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php index 7eb55820e5..432754b602 100644 --- a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php +++ b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php @@ -90,7 +90,7 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase { * @covers MemcachedBagOStuff::validateKeyEncoding */ public function testValidateKeyEncodingThrowsException( $key ) { - $this->setExpectedException( 'Exception' ); + $this->setExpectedException( Exception::class ); $this->cache->validateKeyEncoding( $key ); } diff --git a/tests/phpunit/includes/objectcache/ObjectCacheTest.php b/tests/phpunit/includes/objectcache/ObjectCacheTest.php index f8ce24ec55..4318852867 100644 --- a/tests/phpunit/includes/objectcache/ObjectCacheTest.php +++ b/tests/phpunit/includes/objectcache/ObjectCacheTest.php @@ -16,13 +16,13 @@ class ObjectCacheTest extends MediaWikiTestCase { private function setCacheConfig( $arr = [] ) { $defaults = [ - CACHE_NONE => [ 'class' => 'EmptyBagOStuff' ], - CACHE_DB => [ 'class' => 'SqlBagOStuff' ], + CACHE_NONE => [ 'class' => EmptyBagOStuff::class ], + CACHE_DB => [ 'class' => SqlBagOStuff::class ], CACHE_ANYTHING => [ 'factory' => 'ObjectCache::newAnything' ], // Mock ACCEL with 'hash' as being installed. // This makes tests deterministic regardless of APC. - CACHE_ACCEL => [ 'class' => 'HashBagOStuff' ], - 'hash' => [ 'class' => 'HashBagOStuff' ], + CACHE_ACCEL => [ 'class' => HashBagOStuff::class ], + 'hash' => [ 'class' => HashBagOStuff::class ], ]; $this->setMwGlobals( 'wgObjectCaches', $arr + $defaults ); } @@ -70,7 +70,7 @@ class ObjectCacheTest extends MediaWikiTestCase { $this->setCacheConfig( [ // Mock APC not being installed (T160519, T147161) - CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ] + CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ] ] ); $this->assertInstanceOf( @@ -91,7 +91,7 @@ class ObjectCacheTest extends MediaWikiTestCase { $this->setCacheConfig( [ // Mock APC not being installed (T160519, T147161) - CACHE_ACCEL => [ 'class' => 'EmptyBagOStuff' ] + CACHE_ACCEL => [ 'class' => EmptyBagOStuff::class ] ] ); $this->assertInstanceOf( diff --git a/tests/phpunit/includes/objectcache/RESTBagOStuffTest.php b/tests/phpunit/includes/objectcache/RESTBagOStuffTest.php index 4ef4aabb92..66754fc93f 100644 --- a/tests/phpunit/includes/objectcache/RESTBagOStuffTest.php +++ b/tests/phpunit/includes/objectcache/RESTBagOStuffTest.php @@ -18,7 +18,7 @@ class RESTBagOStuffTest extends MediaWikiTestCase { public function setUp() { parent::setUp(); $this->client = - $this->getMockBuilder( 'MultiHttpClient' ) + $this->getMockBuilder( MultiHttpClient::class ) ->setConstructorArgs( [ [] ] ) ->setMethods( [ 'run' ] ) ->getMock(); diff --git a/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php b/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php index ea58e4a12d..6e8c9cee80 100644 --- a/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php +++ b/tests/phpunit/includes/objectcache/RedisBagOStuffTest.php @@ -14,7 +14,7 @@ class RedisBagOStuffTest extends PHPUnit_Framework_TestCase { protected function setUp() { parent::setUp(); - $cache = $this->getMockBuilder( 'RedisBagOStuff' ) + $cache = $this->getMockBuilder( RedisBagOStuff::class ) ->disableOriginalConstructor() ->getMock(); $this->cache = TestingAccessWrapper::newFromObject( $cache ); diff --git a/tests/phpunit/includes/page/WikiPageContentHandlerDbTest.php b/tests/phpunit/includes/page/WikiPageContentHandlerDbTest.php index bfda3dca35..2d7d6cc3aa 100644 --- a/tests/phpunit/includes/page/WikiPageContentHandlerDbTest.php +++ b/tests/phpunit/includes/page/WikiPageContentHandlerDbTest.php @@ -36,7 +36,7 @@ class WikiPageContentHandlerDbTest extends WikiPageDbTestBase { ); $page = new WikiPage( $page->getTitle() ); - $this->assertEquals( 'JavaScriptContentHandler', get_class( $page->getContentHandler() ) ); + $this->assertEquals( JavaScriptContentHandler::class, get_class( $page->getContentHandler() ) ); } } diff --git a/tests/phpunit/includes/page/WikiPageDbTestBase.php b/tests/phpunit/includes/page/WikiPageDbTestBase.php index 9a70e61a86..b7fe47e53d 100644 --- a/tests/phpunit/includes/page/WikiPageDbTestBase.php +++ b/tests/phpunit/includes/page/WikiPageDbTestBase.php @@ -341,7 +341,7 @@ abstract class WikiPageDbTestBase extends MediaWikiLangTestCase { # sanity check, because this test seems to fail for no reason for some people. $c = $page->getContent(); - $this->assertEquals( 'WikitextContent', get_class( $c ) ); + $this->assertEquals( WikitextContent::class, get_class( $c ) ); # now, test the actual redirect $t = $page->getRedirectTarget(); @@ -1065,15 +1065,15 @@ more stuff public function testWikiPageFactory() { $title = Title::makeTitle( NS_FILE, 'Someimage.png' ); $page = WikiPage::factory( $title ); - $this->assertEquals( 'WikiFilePage', get_class( $page ) ); + $this->assertEquals( WikiFilePage::class, get_class( $page ) ); $title = Title::makeTitle( NS_CATEGORY, 'SomeCategory' ); $page = WikiPage::factory( $title ); - $this->assertEquals( 'WikiCategoryPage', get_class( $page ) ); + $this->assertEquals( WikiCategoryPage::class, get_class( $page ) ); $title = Title::makeTitle( NS_MAIN, 'SomePage' ); $page = WikiPage::factory( $title ); - $this->assertEquals( 'WikiPage', get_class( $page ) ); + $this->assertEquals( WikiPage::class, get_class( $page ) ); } /** diff --git a/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php b/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php index 4721ce6fd8..72390ac856 100644 --- a/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php +++ b/tests/phpunit/includes/pager/RangeChronologicalPagerTest.php @@ -14,7 +14,7 @@ class RangeChronologicalPagerTest extends MediaWikiLangTestCase { * @dataProvider getDateCondProvider */ public function testGetDateCond( $inputYear, $inputMonth, $inputDay, $expected ) { - $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' ); + $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class ); $this->assertEquals( $expected, wfTimestamp( TS_MW, $pager->getDateCond( $inputYear, $inputMonth, $inputDay ) ) @@ -42,7 +42,7 @@ class RangeChronologicalPagerTest extends MediaWikiLangTestCase { * @dataProvider getDateRangeCondProvider */ public function testGetDateRangeCond( $start, $end, $expected ) { - $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' ); + $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class ); $this->assertArrayEquals( $expected, $pager->getDateRangeCond( $start, $end ) ); } @@ -84,7 +84,7 @@ class RangeChronologicalPagerTest extends MediaWikiLangTestCase { * @dataProvider getDateRangeCondInvalidProvider */ public function testGetDateRangeCondInvalid( $start, $end ) { - $pager = $this->getMockForAbstractClass( 'RangeChronologicalPager' ); + $pager = $this->getMockForAbstractClass( RangeChronologicalPager::class ); $this->assertEquals( null, $pager->getDateRangeCond( $start, $end ) ); } diff --git a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php index eb163d3834..3910ab648a 100644 --- a/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php +++ b/tests/phpunit/includes/pager/ReverseChronologicalPagerTest.php @@ -13,7 +13,7 @@ class ReverseChronologicalPagerTest extends MediaWikiLangTestCase { * @covers ReverseChronologicalPager::getDateCond */ public function testGetDateCond() { - $pager = $this->getMockForAbstractClass( 'ReverseChronologicalPager' ); + $pager = $this->getMockForAbstractClass( ReverseChronologicalPager::class ); $timestamp = MWTimestamp::getInstance(); $db = wfGetDB( DB_MASTER ); diff --git a/tests/phpunit/includes/parser/PreprocessorTest.php b/tests/phpunit/includes/parser/PreprocessorTest.php index ab138996a2..c415b58642 100644 --- a/tests/phpunit/includes/parser/PreprocessorTest.php +++ b/tests/phpunit/includes/parser/PreprocessorTest.php @@ -37,8 +37,8 @@ class PreprocessorTest extends MediaWikiTestCase { protected $mPreprocessors; protected static $classNames = [ - 'Preprocessor_DOM', - 'Preprocessor_Hash' + Preprocessor_DOM::class, + Preprocessor_Hash::class ]; protected function setUp() { diff --git a/tests/phpunit/includes/password/BcryptPasswordTest.php b/tests/phpunit/includes/password/BcryptPasswordTest.php index 167341036d..952f541750 100644 --- a/tests/phpunit/includes/password/BcryptPasswordTest.php +++ b/tests/phpunit/includes/password/BcryptPasswordTest.php @@ -10,7 +10,7 @@ class BcryptPasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'bcrypt' => [ - 'class' => 'BcryptPassword', + 'class' => BcryptPassword::class, 'cost' => 9, ] ]; } diff --git a/tests/phpunit/includes/password/EncryptedPasswordTest.php b/tests/phpunit/includes/password/EncryptedPasswordTest.php index 7ed971100c..6dfdea6994 100644 --- a/tests/phpunit/includes/password/EncryptedPasswordTest.php +++ b/tests/phpunit/includes/password/EncryptedPasswordTest.php @@ -9,7 +9,7 @@ class EncryptedPasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'both' => [ - 'class' => 'EncryptedPassword', + 'class' => EncryptedPassword::class, 'underlying' => 'pbkdf2', 'secrets' => [ md5( 'secret1' ), @@ -18,7 +18,7 @@ class EncryptedPasswordTest extends PasswordTestCase { 'cipher' => 'aes-256-cbc', ], 'secret1' => [ - 'class' => 'EncryptedPassword', + 'class' => EncryptedPassword::class, 'underlying' => 'pbkdf2', 'secrets' => [ md5( 'secret1' ), @@ -26,7 +26,7 @@ class EncryptedPasswordTest extends PasswordTestCase { 'cipher' => 'aes-256-cbc', ], 'secret2' => [ - 'class' => 'EncryptedPassword', + 'class' => EncryptedPassword::class, 'underlying' => 'pbkdf2', 'secrets' => [ md5( 'secret2' ), @@ -34,7 +34,7 @@ class EncryptedPasswordTest extends PasswordTestCase { 'cipher' => 'aes-256-cbc', ], 'pbkdf2' => [ - 'class' => 'Pbkdf2Password', + 'class' => Pbkdf2Password::class, 'algo' => 'sha256', 'cost' => '10', 'length' => '64', diff --git a/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php b/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php index cee4fbb083..6a965a0387 100644 --- a/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php +++ b/tests/phpunit/includes/password/LayeredParameterizedPasswordTest.php @@ -8,7 +8,7 @@ class LayeredParameterizedPasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'testLargeLayeredTop' => [ - 'class' => 'LayeredParameterizedPassword', + 'class' => LayeredParameterizedPassword::class, 'types' => [ 'testLargeLayeredBottom', 'testLargeLayeredBottom', @@ -18,13 +18,13 @@ class LayeredParameterizedPasswordTest extends PasswordTestCase { ], ], 'testLargeLayeredBottom' => [ - 'class' => 'Pbkdf2Password', + 'class' => Pbkdf2Password::class, 'algo' => 'sha512', 'cost' => 1024, 'length' => 512, ], 'testLargeLayeredFinal' => [ - 'class' => 'BcryptPassword', + 'class' => BcryptPassword::class, 'cost' => 5, ] ]; diff --git a/tests/phpunit/includes/password/MWOldPasswordTest.php b/tests/phpunit/includes/password/MWOldPasswordTest.php index 51e739cae7..50100826f1 100644 --- a/tests/phpunit/includes/password/MWOldPasswordTest.php +++ b/tests/phpunit/includes/password/MWOldPasswordTest.php @@ -8,7 +8,7 @@ class MWOldPasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'A' => [ - 'class' => 'MWOldPassword', + 'class' => MWOldPassword::class, ] ]; } diff --git a/tests/phpunit/includes/password/MWSaltedPasswordTest.php b/tests/phpunit/includes/password/MWSaltedPasswordTest.php index 53a6ad138b..5616868dad 100644 --- a/tests/phpunit/includes/password/MWSaltedPasswordTest.php +++ b/tests/phpunit/includes/password/MWSaltedPasswordTest.php @@ -8,7 +8,7 @@ class MWSaltedPasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'B' => [ - 'class' => 'MWSaltedPassword', + 'class' => MWSaltedPassword::class, ] ]; } diff --git a/tests/phpunit/includes/password/PasswordFactoryTest.php b/tests/phpunit/includes/password/PasswordFactoryTest.php index 5d585f3221..01b0de2c25 100644 --- a/tests/phpunit/includes/password/PasswordFactoryTest.php +++ b/tests/phpunit/includes/password/PasswordFactoryTest.php @@ -6,14 +6,14 @@ class PasswordFactoryTest extends MediaWikiTestCase { public function testRegister() { $pf = new PasswordFactory; - $pf->register( 'foo', [ 'class' => 'InvalidPassword' ] ); + $pf->register( 'foo', [ 'class' => InvalidPassword::class ] ); $this->assertArrayHasKey( 'foo', $pf->getTypes() ); } public function testSetDefaultType() { $pf = new PasswordFactory; - $pf->register( '1', [ 'class' => 'InvalidPassword' ] ); - $pf->register( '2', [ 'class' => 'InvalidPassword' ] ); + $pf->register( '1', [ 'class' => InvalidPassword::class ] ); + $pf->register( '2', [ 'class' => InvalidPassword::class ] ); $pf->setDefaultType( '1' ); $this->assertSame( '1', $pf->getDefaultType() ); $pf->setDefaultType( '2' ); @@ -31,7 +31,7 @@ class PasswordFactoryTest extends MediaWikiTestCase { public function testInit() { $config = new HashConfig( [ 'PasswordConfig' => [ - 'foo' => [ 'class' => 'InvalidPassword' ], + 'foo' => [ 'class' => InvalidPassword::class ], ], 'PasswordDefault' => 'foo' ] ); @@ -43,7 +43,7 @@ class PasswordFactoryTest extends MediaWikiTestCase { public function testNewFromCiphertext() { $pf = new PasswordFactory; - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pw = $pf->newFromCiphertext( ':B:salt:d529e941509eb9e9b9cfaeae1fe7ca23' ); $this->assertInstanceOf( MWSaltedPassword::class, $pw ); } @@ -58,13 +58,13 @@ class PasswordFactoryTest extends MediaWikiTestCase { */ public function testNewFromCiphertextErrors( $hash ) { $pf = new PasswordFactory; - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pf->newFromCiphertext( $hash ); } public function testNewFromType() { $pf = new PasswordFactory; - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pw = $pf->newFromType( 'B' ); $this->assertInstanceOf( MWSaltedPassword::class, $pw ); } @@ -74,26 +74,26 @@ class PasswordFactoryTest extends MediaWikiTestCase { */ public function testNewFromTypeError() { $pf = new PasswordFactory; - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pf->newFromType( 'bogus' ); } public function testNewFromPlaintext() { $pf = new PasswordFactory; - $pf->register( 'A', [ 'class' => 'MWOldPassword' ] ); - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'A', [ 'class' => MWOldPassword::class ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pf->setDefaultType( 'A' ); - $this->assertInstanceOf( 'InvalidPassword', $pf->newFromPlaintext( null ) ); - $this->assertInstanceOf( 'MWOldPassword', $pf->newFromPlaintext( 'password' ) ); - $this->assertInstanceOf( 'MWSaltedPassword', + $this->assertInstanceOf( InvalidPassword::class, $pf->newFromPlaintext( null ) ); + $this->assertInstanceOf( MWOldPassword::class, $pf->newFromPlaintext( 'password' ) ); + $this->assertInstanceOf( MWSaltedPassword::class, $pf->newFromPlaintext( 'password', $pf->newFromType( 'B' ) ) ); } public function testNeedsUpdate() { $pf = new PasswordFactory; - $pf->register( 'A', [ 'class' => 'MWOldPassword' ] ); - $pf->register( 'B', [ 'class' => 'MWSaltedPassword' ] ); + $pf->register( 'A', [ 'class' => MWOldPassword::class ] ); + $pf->register( 'B', [ 'class' => MWSaltedPassword::class ] ); $pf->setDefaultType( 'A' ); $this->assertFalse( $pf->needsUpdate( $pf->newFromType( 'A' ) ) ); @@ -105,6 +105,6 @@ class PasswordFactoryTest extends MediaWikiTestCase { } public function testNewInvalidPassword() { - $this->assertInstanceOf( 'InvalidPassword', PasswordFactory::newInvalidPassword() ); + $this->assertInstanceOf( InvalidPassword::class, PasswordFactory::newInvalidPassword() ); } } diff --git a/tests/phpunit/includes/password/PasswordTest.php b/tests/phpunit/includes/password/PasswordTest.php index d0177d0d4a..65c9199310 100644 --- a/tests/phpunit/includes/password/PasswordTest.php +++ b/tests/phpunit/includes/password/PasswordTest.php @@ -36,6 +36,6 @@ class PasswordTest extends MediaWikiTestCase { $passwordFactory = new PasswordFactory(); $invalid = $passwordFactory->newFromPlaintext( null ); - $this->assertInstanceOf( 'InvalidPassword', $invalid ); + $this->assertInstanceOf( InvalidPassword::class, $invalid ); } } diff --git a/tests/phpunit/includes/password/Pbkdf2PasswordFallbackTest.php b/tests/phpunit/includes/password/Pbkdf2PasswordFallbackTest.php index 605d1905c6..cf851c8113 100644 --- a/tests/phpunit/includes/password/Pbkdf2PasswordFallbackTest.php +++ b/tests/phpunit/includes/password/Pbkdf2PasswordFallbackTest.php @@ -9,7 +9,7 @@ class Pbkdf2PasswordFallbackTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'pbkdf2' => [ - 'class' => 'Pbkdf2Password', + 'class' => Pbkdf2Password::class, 'algo' => 'sha256', 'cost' => '10000', 'length' => '128', diff --git a/tests/phpunit/includes/password/Pbkdf2PasswordTest.php b/tests/phpunit/includes/password/Pbkdf2PasswordTest.php index ff069cd94b..7e97ab1af9 100644 --- a/tests/phpunit/includes/password/Pbkdf2PasswordTest.php +++ b/tests/phpunit/includes/password/Pbkdf2PasswordTest.php @@ -10,7 +10,7 @@ class Pbkdf2PasswordTest extends PasswordTestCase { protected function getTypeConfigs() { return [ 'pbkdf2' => [ - 'class' => 'Pbkdf2Password', + 'class' => Pbkdf2Password::class, 'algo' => 'sha256', 'cost' => '10000', 'length' => '128', diff --git a/tests/phpunit/includes/poolcounter/PoolCounterTest.php b/tests/phpunit/includes/poolcounter/PoolCounterTest.php index 6caf3e5450..f7f2013cb4 100644 --- a/tests/phpunit/includes/poolcounter/PoolCounterTest.php +++ b/tests/phpunit/includes/poolcounter/PoolCounterTest.php @@ -21,13 +21,13 @@ class PoolCounterTest extends MediaWikiTestCase { 'maxqueue' => 100, ]; - $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) + $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class ) ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'someKey' ] ) // don't mock anything - the proper syntax would be setMethods(null), but due // to a PHPUnit bug that does not work with getMockForAbstractClass() ->setMethods( [ 'idontexist' ] ) ->getMockForAbstractClass(); - $this->assertInstanceOf( 'PoolCounter', $poolCounter ); + $this->assertInstanceOf( PoolCounter::class, $poolCounter ); } public function testConstructWithSlots() { @@ -39,15 +39,15 @@ class PoolCounterTest extends MediaWikiTestCase { 'maxqueue' => 100, ]; - $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) + $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class ) ->setConstructorArgs( [ $poolCounterConfig, 'testCounter', 'key' ] ) ->setMethods( [ 'idontexist' ] ) // don't mock anything ->getMockForAbstractClass(); - $this->assertInstanceOf( 'PoolCounter', $poolCounter ); + $this->assertInstanceOf( PoolCounter::class, $poolCounter ); } public function testHashKeyIntoSlots() { - $poolCounter = $this->getMockBuilder( 'PoolCounterAbstractMock' ) + $poolCounter = $this->getMockBuilder( PoolCounterAbstractMock::class ) // don't mock anything - the proper syntax would be setMethods(null), but due // to a PHPUnit bug that does not work with getMockForAbstractClass() ->setMethods( [ 'idontexist' ] ) diff --git a/tests/phpunit/includes/rcfeed/RCFeedIntegrationTest.php b/tests/phpunit/includes/rcfeed/RCFeedIntegrationTest.php index 3e9c567ec8..fdf01525d4 100644 --- a/tests/phpunit/includes/rcfeed/RCFeedIntegrationTest.php +++ b/tests/phpunit/includes/rcfeed/RCFeedIntegrationTest.php @@ -27,8 +27,8 @@ class RCFeedIntegrationTest extends MediaWikiTestCase { * @covers MachineReadableRCFeedFormatter::getLine */ public function testNotify() { - $feed = $this->getMockBuilder( 'RCFeedEngine' ) - ->setConstructorArgs( [ [ 'formatter' => 'JSONRCFeedFormatter' ] ] ) + $feed = $this->getMockBuilder( RCFeedEngine::class ) + ->setConstructorArgs( [ [ 'formatter' => JSONRCFeedFormatter::class ] ] ) ->setMethods( [ 'send' ] ) ->getMock(); @@ -71,7 +71,7 @@ class RCFeedIntegrationTest extends MediaWikiTestCase { 'wgRCFeeds' => [ 'myfeed' => [ 'uri' => 'test://localhost:1234', - 'formatter' => 'JSONRCFeedFormatter', + 'formatter' => JSONRCFeedFormatter::class, ], ], 'wgRCEngines' => [ diff --git a/tests/phpunit/includes/registration/ExtensionProcessorTest.php b/tests/phpunit/includes/registration/ExtensionProcessorTest.php index acf4710ffd..4282652e12 100644 --- a/tests/phpunit/includes/registration/ExtensionProcessorTest.php +++ b/tests/phpunit/includes/registration/ExtensionProcessorTest.php @@ -332,7 +332,7 @@ class ExtensionProcessorTest extends MediaWikiTestCase { public function testExtractCredits() { $processor = new ExtensionProcessor(); $processor->extractInfo( $this->dir, self::$default, 1 ); - $this->setExpectedException( 'Exception' ); + $this->setExpectedException( Exception::class ); $processor->extractInfo( $this->dir, self::$default, 1 ); } diff --git a/tests/phpunit/includes/registration/ExtensionRegistryTest.php b/tests/phpunit/includes/registration/ExtensionRegistryTest.php index 5916b4510b..a6f69b64d9 100644 --- a/tests/phpunit/includes/registration/ExtensionRegistryTest.php +++ b/tests/phpunit/includes/registration/ExtensionRegistryTest.php @@ -28,7 +28,7 @@ class ExtensionRegistryTest extends MediaWikiTestCase { 'autoloaderPaths' => [] ]; $registry = new ExtensionRegistry(); - $class = new ReflectionClass( 'ExtensionRegistry' ); + $class = new ReflectionClass( ExtensionRegistry::class ); $method = $class->getMethod( 'exportExtractedData' ); $method->setAccessible( true ); $method->invokeArgs( $registry, [ $info ] ); diff --git a/tests/phpunit/includes/registration/VersionCheckerTest.php b/tests/phpunit/includes/registration/VersionCheckerTest.php index 15d0c2b663..6f0de160f5 100644 --- a/tests/phpunit/includes/registration/VersionCheckerTest.php +++ b/tests/phpunit/includes/registration/VersionCheckerTest.php @@ -111,7 +111,7 @@ class VersionCheckerTest extends PHPUnit_Framework_TestCase { ], ] ); - $this->setExpectedException( 'UnexpectedValueException' ); + $this->setExpectedException( UnexpectedValueException::class ); $checker->checkArray( [ 'FakeExtension' => [ 'FakeDependency' => 'not really valid', diff --git a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php index 7521e880fb..c00432efe8 100644 --- a/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php +++ b/tests/phpunit/includes/resourceloader/MessageBlobStoreTest.php @@ -14,7 +14,7 @@ class MessageBlobStoreTest extends PHPUnit_Framework_TestCase { parent::setUp(); // MediaWiki tests defaults $wgMainWANCache to CACHE_NONE. // Use hash instead so that caching is observed - $this->wanCache = $this->getMockBuilder( 'WANObjectCache' ) + $this->wanCache = $this->getMockBuilder( WANObjectCache::class ) ->setConstructorArgs( [ [ 'cache' => new HashBagOStuff(), 'pool' => 'test', @@ -32,7 +32,7 @@ class MessageBlobStoreTest extends PHPUnit_Framework_TestCase { } protected function makeBlobStore( $methods = null, $rl = null ) { - $blobStore = $this->getMockBuilder( 'MessageBlobStore' ) + $blobStore = $this->getMockBuilder( MessageBlobStore::class ) ->setConstructorArgs( [ $rl ] ) ->setMethods( $methods ) ->getMock(); diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php index e5b338ed97..3f5704d6f4 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php @@ -59,7 +59,7 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase { return [ [ [ - 'class' => 'ResourceLoaderImageModule', + 'class' => ResourceLoaderImageModule::class, 'prefix' => 'oo-ui-icon', 'variants' => self::$commonImageVariants, 'images' => self::$commonImageData, @@ -100,7 +100,7 @@ class ResourceLoaderImageModuleTest extends ResourceLoaderTestCase { ], [ [ - 'class' => 'ResourceLoaderImageModule', + 'class' => ResourceLoaderImageModule::class, 'selectorWithoutVariant' => '.mw-ui-icon-{name}:after, .mw-ui-icon-{name}:before', 'selectorWithVariant' => '.mw-ui-icon-{name}-{variant}:after, .mw-ui-icon-{name}-{variant}:before', @@ -239,7 +239,7 @@ TEXT } private function getImageMock( ResourceLoaderContext $context, $dataUriReturnValue ) { - $image = $this->getMockBuilder( 'ResourceLoaderImage' ) + $image = $this->getMockBuilder( ResourceLoaderImage::class ) ->disableOriginalConstructor() ->getMock(); $image->method( 'getDataUri' ) diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php index 7c7f1cf5c4..0ea4e2bd63 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderModuleTest.php @@ -149,9 +149,9 @@ class ResourceLoaderModuleTest extends ResourceLoaderTestCase { * @covers ResourceLoaderModule::expandRelativePaths */ public function testPlaceholderize() { - $getRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'getRelativePaths' ); + $getRelativePaths = new ReflectionMethod( ResourceLoaderModule::class, 'getRelativePaths' ); $getRelativePaths->setAccessible( true ); - $expandRelativePaths = new ReflectionMethod( 'ResourceLoaderModule', 'expandRelativePaths' ); + $expandRelativePaths = new ReflectionMethod( ResourceLoaderModule::class, 'expandRelativePaths' ); $expandRelativePaths->setAccessible( true ); $this->setMwGlobals( [ diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php index 491fff6b1c..ea220f1148 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderOOUIImageModuleTest.php @@ -10,7 +10,7 @@ class ResourceLoaderOOUIImageModuleTest extends ResourceLoaderTestCase { */ public function testNonDefaultSkin() { $module = new ResourceLoaderOOUIImageModule( [ - 'class' => 'ResourceLoaderOOUIImageModule', + 'class' => ResourceLoaderOOUIImageModule::class, 'name' => 'icons', 'rootPath' => 'tests/phpunit/data/resourceloader/oouiimagemodule', ] ); @@ -22,7 +22,7 @@ class ResourceLoaderOOUIImageModuleTest extends ResourceLoaderTestCase { function () { } ); - $r = new ReflectionMethod( 'ExtensionRegistry', 'exportExtractedData' ); + $r = new ReflectionMethod( ExtensionRegistry::class, 'exportExtractedData' ); $r->setAccessible( true ); $r->invoke( ExtensionRegistry::getInstance(), [ 'globals' => [], diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php index 03a609b664..564f50bc35 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderStartUpModuleTest.php @@ -56,7 +56,7 @@ mw.loader.register( [ 'msg' => 'Version falls back gracefully if getVersionHash throws', 'modules' => [ 'test.fail' => ( - ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ( $mock = $this->getMockBuilder( ResourceLoaderTestModule::class ) ->setMethods( [ 'getVersionHash' ] )->getMock() ) && $mock->method( 'getVersionHash' )->will( $this->throwException( new Exception ) @@ -81,7 +81,7 @@ mw.loader.state( { 'msg' => 'Use version from getVersionHash', 'modules' => [ 'test.version' => ( - ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ( $mock = $this->getMockBuilder( ResourceLoaderTestModule::class ) ->setMethods( [ 'getVersionHash' ] )->getMock() ) && $mock->method( 'getVersionHash' )->willReturn( '1234567' ) ) ? $mock : $mock @@ -101,7 +101,7 @@ mw.loader.register( [ 'msg' => 'Re-hash version from getVersionHash if too long', 'modules' => [ 'test.version' => ( - ( $mock = $this->getMockBuilder( 'ResourceLoaderTestModule' ) + ( $mock = $this->getMockBuilder( ResourceLoaderTestModule::class ) ->setMethods( [ 'getVersionHash' ] )->getMock() ) && $mock->method( 'getVersionHash' )->willReturn( '12345678' ) ) ? $mock : $mock diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php index f45f8aee15..0bc558ad62 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderTest.php @@ -86,7 +86,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { */ public function testRegisterInvalidName() { $resourceLoader = new EmptyResourceLoader(); - $this->setExpectedException( 'MWException', "name 'test!invalid' is invalid" ); + $this->setExpectedException( MWException::class, "name 'test!invalid' is invalid" ); $resourceLoader->register( 'test!invalid', new ResourceLoaderTestModule() ); } @@ -95,7 +95,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { */ public function testRegisterInvalidType() { $resourceLoader = new EmptyResourceLoader(); - $this->setExpectedException( 'MWException', 'ResourceLoader module info type error' ); + $this->setExpectedException( MWException::class, 'ResourceLoader module info type error' ); $resourceLoader->register( 'test', new stdClass() ); } @@ -336,7 +336,9 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { */ public function testAddSourceDupe() { $rl = new ResourceLoader; - $this->setExpectedException( 'MWException', 'ResourceLoader duplicate source addition error' ); + $this->setExpectedException( + MWException::class, 'ResourceLoader duplicate source addition error' + ); $rl->addSource( 'foo', 'https://example.org/w/load.php' ); $rl->addSource( 'foo', 'https://example.com/w/load.php' ); } @@ -346,7 +348,7 @@ class ResourceLoaderTest extends ResourceLoaderTestCase { */ public function testAddSourceInvalid() { $rl = new ResourceLoader; - $this->setExpectedException( 'MWException', 'with no "loadScript" key' ); + $this->setExpectedException( MWException::class, 'with no "loadScript" key' ); $rl->addSource( 'foo', [ 'x' => 'https://example.org/w/load.php' ] ); } @@ -446,7 +448,7 @@ mw.example(); ResourceLoader::clearCache(); $this->setMwGlobals( 'wgResourceLoaderDebug', true ); - $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' ); + $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class ); $this->assertEquals( $case['expected'], $rl->makeLoaderImplementScript( @@ -465,8 +467,8 @@ mw.example(); * @covers ResourceLoader::makeLoaderImplementScript */ public function testMakeLoaderImplementScriptInvalid() { - $this->setExpectedException( 'MWException', 'Invalid scripts error' ); - $rl = TestingAccessWrapper::newFromClass( 'ResourceLoader' ); + $this->setExpectedException( MWException::class, 'Invalid scripts error' ); + $rl = TestingAccessWrapper::newFromClass( ResourceLoader::class ); $rl->makeLoaderImplementScript( 'test', // name 123, // scripts @@ -753,7 +755,7 @@ mw.example(); 'foo' => self::getSimpleModuleMock( 'foo();' ), 'ferry' => self::getFailFerryMock(), 'bar' => self::getSimpleModuleMock( 'bar();' ), - 'startup' => [ 'class' => 'ResourceLoaderStartUpModule' ], + 'startup' => [ 'class' => ResourceLoaderStartUpModule::class ], ] ); $context = $this->getResourceLoaderContext( [ diff --git a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php index 78eec6a6f7..0aa37d23d3 100644 --- a/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php +++ b/tests/phpunit/includes/resourceloader/ResourceLoaderWikiModuleTest.php @@ -12,7 +12,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { */ public function testConstructor( $params ) { $module = new ResourceLoaderWikiModule( $params ); - $this->assertInstanceOf( 'ResourceLoaderWikiModule', $module ); + $this->assertInstanceOf( ResourceLoaderWikiModule::class, $module ); } public static function provideConstructor() { @@ -97,7 +97,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { * @dataProvider provideIsKnownEmpty */ public function testIsKnownEmpty( $titleInfo, $group, $expected ) { - $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( ResourceLoaderWikiModule::class ) ->setMethods( [ 'getTitleInfo', 'getGroup' ] ) ->getMock(); $module->expects( $this->any() ) @@ -106,7 +106,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { $module->expects( $this->any() ) ->method( 'getGroup' ) ->will( $this->returnValue( $group ) ); - $context = $this->getMockBuilder( 'ResourceLoaderContext' ) + $context = $this->getMockBuilder( ResourceLoaderContext::class ) ->disableOriginalConstructor() ->getMock(); $this->assertEquals( $expected, $module->isKnownEmpty( $context ) ); @@ -157,14 +157,14 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { ]; $expected = $titleInfo; - $module = $this->getMockBuilder( 'TestResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( TestResourceLoaderWikiModule::class ) ->setMethods( [ 'getPages' ] ) ->getMock(); $module->method( 'getPages' )->willReturn( $pages ); // Can't mock static methods $module::$returnFetchTitleInfo = $titleInfo; - $context = $this->getMockBuilder( 'ResourceLoaderContext' ) + $context = $this->getMockBuilder( ResourceLoaderContext::class ) ->disableOriginalConstructor() ->getMock(); @@ -192,7 +192,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { ]; $expected = $titleInfo; - $module = $this->getMockBuilder( 'TestResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( TestResourceLoaderWikiModule::class ) ->setMethods( [ 'getPages' ] ) ->getMock(); $module->method( 'getPages' )->willReturn( $pages ); @@ -231,7 +231,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { $titleInfo = []; // Set up objects - $module = $this->getMockBuilder( 'TestResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( TestResourceLoaderWikiModule::class ) ->setMethods( [ 'getPages' ] ) ->getMock(); $module->method( 'getPages' )->willReturn( $pages ); $module::$returnFetchTitleInfo = $titleInfo; @@ -299,7 +299,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { */ public function testGetContent( $expected, $title ) { $context = $this->getResourceLoaderContext( [], new EmptyResourceLoader ); - $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( ResourceLoaderWikiModule::class ) ->setMethods( [ 'getContentObj' ] ) ->getMock(); $module->expects( $this->any() ) ->method( 'getContentObj' )->willReturn( null ); @@ -331,7 +331,7 @@ class ResourceLoaderWikiModuleTest extends ResourceLoaderTestCase { public function testGetContentForRedirects() { // Set up context and module object $context = $this->getResourceLoaderContext( [], new EmptyResourceLoader ); - $module = $this->getMockBuilder( 'ResourceLoaderWikiModule' ) + $module = $this->getMockBuilder( ResourceLoaderWikiModule::class ) ->setMethods( [ 'getPages', 'getContentObj' ] ) ->getMock(); $module->expects( $this->any() ) diff --git a/tests/phpunit/includes/search/SearchEnginePrefixTest.php b/tests/phpunit/includes/search/SearchEnginePrefixTest.php index 4c5bab3fcc..3f59295ab6 100644 --- a/tests/phpunit/includes/search/SearchEnginePrefixTest.php +++ b/tests/phpunit/includes/search/SearchEnginePrefixTest.php @@ -63,8 +63,8 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase { $this->search = MediaWikiServices::getInstance()->newSearchEngine(); $this->search->setNamespaces( [] ); - $this->originalHandlers = TestingAccessWrapper::newFromClass( 'Hooks' )->handlers; - TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = []; + $this->originalHandlers = TestingAccessWrapper::newFromClass( Hooks::class )->handlers; + TestingAccessWrapper::newFromClass( Hooks::class )->handlers = []; SpecialPageFactory::resetList(); } @@ -72,7 +72,7 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase { public function tearDown() { parent::tearDown(); - TestingAccessWrapper::newFromClass( 'Hooks' )->handlers = $this->originalHandlers; + TestingAccessWrapper::newFromClass( Hooks::class )->handlers = $this->originalHandlers; SpecialPageFactory::resetList(); } @@ -337,7 +337,7 @@ class SearchEnginePrefixTest extends MediaWikiLangTestCase { * @covers PrefixSearch::searchBackend */ public function testSearchBackend( array $case ) { - $search = $stub = $this->getMockBuilder( 'SearchEngine' ) + $search = $stub = $this->getMockBuilder( SearchEngine::class ) ->setMethods( [ 'completionSearchBackend' ] )->getMock(); $return = SearchSuggestionSet::fromStrings( $case['provision'] ); diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 9711eabb31..e8077769e1 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -220,12 +220,12 @@ class SearchEngineTest extends MediaWikiLangTestCase { /** * @var $mockEngine SearchEngine */ - $mockEngine = $this->getMockBuilder( 'SearchEngine' ) + $mockEngine = $this->getMockBuilder( SearchEngine::class ) ->setMethods( [ 'makeSearchFieldMapping' ] )->getMock(); $mockFieldBuilder = function ( $name, $type ) { $mockField = - $this->getMockBuilder( 'SearchIndexFieldDefinition' )->setConstructorArgs( [ + $this->getMockBuilder( SearchIndexFieldDefinition::class )->setConstructorArgs( [ $name, $type ] )->getMock(); @@ -258,7 +258,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { $fields = $mockEngine->getSearchIndexFields(); $this->assertArrayHasKey( 'language', $fields ); $this->assertArrayHasKey( 'category', $fields ); - $this->assertInstanceOf( 'SearchIndexField', $fields['testField'] ); + $this->assertInstanceOf( SearchIndexField::class, $fields['testField'] ); $mapping = $fields['testField']->getMapping( $mockEngine ); $this->assertArrayHasKey( 'testData', $mapping ); @@ -287,7 +287,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { } public function addAugmentors( &$setAugmentors, &$rowAugmentors ) { - $setAugmentor = $this->createMock( 'ResultSetAugmentor' ); + $setAugmentor = $this->createMock( ResultSetAugmentor::class ); $setAugmentor->expects( $this->once() ) ->method( 'augmentAll' ) ->willReturnCallback( function ( SearchResultSet $resultSet ) { @@ -301,7 +301,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { } ); $setAugmentors['testSet'] = $setAugmentor; - $rowAugmentor = $this->createMock( 'ResultAugmentor' ); + $rowAugmentor = $this->createMock( ResultAugmentor::class ); $rowAugmentor->expects( $this->exactly( 2 ) ) ->method( 'augment' ) ->willReturnCallback( function ( SearchResult $result ) { diff --git a/tests/phpunit/includes/services/ServiceContainerTest.php b/tests/phpunit/includes/services/ServiceContainerTest.php index f4f56504e2..768ed9106f 100644 --- a/tests/phpunit/includes/services/ServiceContainerTest.php +++ b/tests/phpunit/includes/services/ServiceContainerTest.php @@ -71,7 +71,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { $name = 'TestService92834576'; - $this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' ); + $this->setExpectedException( MediaWiki\Services\NoSuchServiceException::class ); $services->getService( $name ); } @@ -113,7 +113,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { $name = 'TestService92834576'; - $this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' ); + $this->setExpectedException( MediaWiki\Services\NoSuchServiceException::class ); $services->peekService( $name ); } @@ -143,7 +143,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { return $theService; } ); - $this->setExpectedException( 'MediaWiki\Services\ServiceAlreadyDefinedException' ); + $this->setExpectedException( MediaWiki\Services\ServiceAlreadyDefinedException::class ); $services->defineService( $name, function () use ( $theService ) { return $theService; @@ -240,7 +240,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { ]; // loading the same file twice should fail, because - $this->setExpectedException( 'MediaWiki\Services\ServiceAlreadyDefinedException' ); + $this->setExpectedException( MediaWiki\Services\ServiceAlreadyDefinedException::class ); $services->loadWiringFiles( $wiringFiles ); } @@ -298,7 +298,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { $theService = new stdClass(); $name = 'TestService92834576'; - $this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' ); + $this->setExpectedException( MediaWiki\Services\NoSuchServiceException::class ); $services->redefineService( $name, function () use ( $theService ) { return $theService; @@ -318,7 +318,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { // create the service, so it can no longer be redefined $services->getService( $name ); - $this->setExpectedException( 'MediaWiki\Services\CannotReplaceActiveServiceException' ); + $this->setExpectedException( MediaWiki\Services\CannotReplaceActiveServiceException::class ); $services->redefineService( $name, function () use ( $theService ) { return $theService; @@ -328,7 +328,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { public function testDisableService() { $services = $this->newServiceContainer( [ 'Foo' ] ); - $destructible = $this->getMockBuilder( 'MediaWiki\Services\DestructibleService' ) + $destructible = $this->getMockBuilder( MediaWiki\Services\DestructibleService::class ) ->getMock(); $destructible->expects( $this->once() ) ->method( 'destroy' ); @@ -367,7 +367,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { $this->assertContains( 'Bar', $services->getServiceNames() ); $this->assertContains( 'Qux', $services->getServiceNames() ); - $this->setExpectedException( 'MediaWiki\Services\ServiceDisabledException' ); + $this->setExpectedException( MediaWiki\Services\ServiceDisabledException::class ); $services->getService( 'Qux' ); } @@ -377,7 +377,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { $theService = new stdClass(); $name = 'TestService92834576'; - $this->setExpectedException( 'MediaWiki\Services\NoSuchServiceException' ); + $this->setExpectedException( MediaWiki\Services\NoSuchServiceException::class ); $services->redefineService( $name, function () use ( $theService ) { return $theService; @@ -387,7 +387,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { public function testDestroy() { $services = $this->newServiceContainer(); - $destructible = $this->getMockBuilder( 'MediaWiki\Services\DestructibleService' ) + $destructible = $this->getMockBuilder( MediaWiki\Services\DestructibleService::class ) ->getMock(); $destructible->expects( $this->once() ) ->method( 'destroy' ); @@ -406,7 +406,7 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { // destroy the container $services->destroy(); - $this->setExpectedException( 'MediaWiki\Services\ContainerDisabledException' ); + $this->setExpectedException( MediaWiki\Services\ContainerDisabledException::class ); $services->getService( 'Bar' ); } diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php index 90550d2b2b..476799406f 100644 --- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php +++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php @@ -184,7 +184,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { public function testNewSessionInfoForRequest() { $provider = $this->getProvider(); $user = static::getTestSysop()->getUser(); - $request = $this->getMockBuilder( 'FauxRequest' ) + $request = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '127.0.0.1' ) ); @@ -212,7 +212,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { $provider->setLogger( $logger ); $user = static::getTestSysop()->getUser(); - $request = $this->getMockBuilder( 'FauxRequest' ) + $request = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '127.0.0.1' ) ); @@ -264,7 +264,7 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { ], $logger->getBuffer() ); $logger->clearBuffer(); - $request2 = $this->getMockBuilder( 'FauxRequest' ) + $request2 = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'getIP' ] )->getMock(); $request2->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '10.0.0.1' ) ); diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index a47fd9a18b..c1df365aac 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -157,7 +157,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { ); $msg = $provider->whyNoSession(); - $this->assertInstanceOf( 'Message', $msg ); + $this->assertInstanceOf( \Message::class, $msg ); $this->assertSame( 'sessionprovider-nocookies', $msg->getKey() ); } @@ -415,7 +415,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { ); TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; - $mock = $this->getMockBuilder( 'stdClass' ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'onUserSetCookies' ] ) ->getMock(); $mock->expects( $this->never() )->method( 'onUserSetCookies' ); @@ -563,14 +563,14 @@ class CookieSessionProviderTest extends MediaWikiTestCase { } protected function getSentRequest() { - $sentResponse = $this->getMockBuilder( 'FauxResponse' ) + $sentResponse = $this->getMockBuilder( \FauxResponse::class ) ->setMethods( [ 'headersSent', 'setCookie', 'header' ] )->getMock(); $sentResponse->expects( $this->any() )->method( 'headersSent' ) ->will( $this->returnValue( true ) ); $sentResponse->expects( $this->never() )->method( 'setCookie' ); $sentResponse->expects( $this->never() )->method( 'header' ); - $sentRequest = $this->getMockBuilder( 'FauxRequest' ) + $sentRequest = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'response' ] )->getMock(); $sentRequest->expects( $this->any() )->method( 'response' ) ->will( $this->returnValue( $sentResponse ) ); @@ -608,7 +608,7 @@ class CookieSessionProviderTest extends MediaWikiTestCase { TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; // Anonymous user - $mock = $this->getMockBuilder( 'stdClass' ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'onUserSetCookies' ] )->getMock(); $mock->expects( $this->never() )->method( 'onUserSetCookies' ); $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] ); diff --git a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php index 086fa28bde..6dd32fcdaf 100644 --- a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php +++ b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php @@ -91,7 +91,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { $this->assertFalse( $provider->canChangeUser() ); $msg = $provider->whyNoSession(); - $this->assertInstanceOf( 'Message', $msg ); + $this->assertInstanceOf( \Message::class, $msg ); $this->assertSame( 'sessionprovider-nocookies', $msg->getKey() ); } @@ -158,7 +158,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { } protected function getSentRequest() { - $sentResponse = $this->getMockBuilder( 'FauxResponse' ) + $sentResponse = $this->getMockBuilder( \FauxResponse::class ) ->setMethods( [ 'headersSent', 'setCookie', 'header' ] ) ->getMock(); $sentResponse->expects( $this->any() )->method( 'headersSent' ) @@ -166,7 +166,7 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { $sentResponse->expects( $this->never() )->method( 'setCookie' ); $sentResponse->expects( $this->never() )->method( 'header' ); - $sentRequest = $this->getMockBuilder( 'FauxRequest' ) + $sentRequest = $this->getMockBuilder( \FauxRequest::class ) ->setMethods( [ 'response' ] )->getMock(); $sentRequest->expects( $this->any() )->method( 'response' ) ->will( $this->returnValue( $sentResponse ) ); diff --git a/tests/phpunit/includes/session/MetadataMergeExceptionTest.php b/tests/phpunit/includes/session/MetadataMergeExceptionTest.php index 0981f026a1..8cb4302a4e 100644 --- a/tests/phpunit/includes/session/MetadataMergeExceptionTest.php +++ b/tests/phpunit/includes/session/MetadataMergeExceptionTest.php @@ -14,7 +14,7 @@ class MetadataMergeExceptionTest extends MediaWikiTestCase { $data = [ 'foo' => 'bar' ]; $ex = new MetadataMergeException(); - $this->assertInstanceOf( 'UnexpectedValueException', $ex ); + $this->assertInstanceOf( \UnexpectedValueException::class, $ex ); $this->assertSame( [], $ex->getContext() ); $ex2 = new MetadataMergeException( 'Message', 42, $ex, $data ); diff --git a/tests/phpunit/includes/session/PHPSessionHandlerTest.php b/tests/phpunit/includes/session/PHPSessionHandlerTest.php index 0a2e84e11a..54a31b53bd 100644 --- a/tests/phpunit/includes/session/PHPSessionHandlerTest.php +++ b/tests/phpunit/includes/session/PHPSessionHandlerTest.php @@ -109,7 +109,7 @@ class PHPSessionHandlerTest extends MediaWikiTestCase { $reset[] = $this->getResetter( $rProp ); $this->setMwGlobals( [ - 'wgSessionProviders' => [ [ 'class' => 'DummySessionProvider' ] ], + 'wgSessionProviders' => [ [ 'class' => \DummySessionProvider::class ] ], 'wgObjectCacheSessionExpiry' => 2, ] ); diff --git a/tests/phpunit/includes/session/SessionBackendTest.php b/tests/phpunit/includes/session/SessionBackendTest.php index e0d1c307ab..88f58cf06b 100644 --- a/tests/phpunit/includes/session/SessionBackendTest.php +++ b/tests/phpunit/includes/session/SessionBackendTest.php @@ -142,7 +142,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertSame( self::SESSIONID, $backend->getId() ); $this->assertSame( $id, $backend->getSessionId() ); $this->assertSame( $this->provider, $backend->getProvider() ); - $this->assertInstanceOf( 'User', $backend->getUser() ); + $this->assertInstanceOf( User::class, $backend->getUser() ); $this->assertSame( 'UTSysop', $backend->getUser()->getName() ); $this->assertSame( $info->wasPersisted(), $backend->isPersistent() ); $this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() ); @@ -164,7 +164,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertSame( self::SESSIONID, $backend->getId() ); $this->assertSame( $id, $backend->getSessionId() ); $this->assertSame( $this->provider, $backend->getProvider() ); - $this->assertInstanceOf( 'User', $backend->getUser() ); + $this->assertInstanceOf( User::class, $backend->getUser() ); $this->assertTrue( $backend->getUser()->isAnon() ); $this->assertSame( $info->wasPersisted(), $backend->isPersistent() ); $this->assertSame( $info->wasRemembered(), $backend->shouldRememberUser() ); @@ -258,7 +258,7 @@ class SessionBackendTest extends MediaWikiTestCase { public function testResetId() { $id = session_id(); - $builder = $this->getMockBuilder( 'DummySessionProvider' ) + $builder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistsSessionId', 'sessionIdWasReset' ] ); $this->provider = $builder->getMock(); @@ -294,7 +294,7 @@ class SessionBackendTest extends MediaWikiTestCase { } public function testPersist() { - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->once() )->method( 'persistSession' ); $backend = $this->getBackend(); @@ -314,7 +314,7 @@ class SessionBackendTest extends MediaWikiTestCase { } public function testUnpersist() { - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'unpersistSession' ] )->getMock(); $this->provider->expects( $this->once() )->method( 'unpersistSession' ); $backend = $this->getBackend(); @@ -367,7 +367,7 @@ class SessionBackendTest extends MediaWikiTestCase { public function testSetUser() { $user = static::getTestSysop()->getUser(); - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'canChangeUser' ] )->getMock(); $this->provider->expects( $this->any() )->method( 'canChangeUser' ) ->will( $this->returnValue( false ) ); @@ -498,7 +498,7 @@ class SessionBackendTest extends MediaWikiTestCase { ->setMethods( [ 'onSessionMetadata' ] )->getMock(); $neverHook->expects( $this->never() )->method( 'onSessionMetadata' ); - $builder = $this->getMockBuilder( 'DummySessionProvider' ) + $builder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistSession', 'unpersistSession' ] ); $neverProvider = $builder->getMock(); @@ -746,7 +746,7 @@ class SessionBackendTest extends MediaWikiTestCase { $testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ]; // Not persistent - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->never() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; @@ -772,7 +772,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertNotEquals( 0, $wrap->expires ); // Persistent - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->atLeastOnce() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; @@ -799,7 +799,7 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertNotEquals( 0, $wrap->expires ); // Not persistent, not expiring - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->never() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; @@ -940,7 +940,7 @@ class SessionBackendTest extends MediaWikiTestCase { } public function testGetAllowedUserRights() { - $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + $this->provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'getAllowedUserRights' ] ) ->getMock(); $this->provider->expects( $this->any() )->method( 'getAllowedUserRights' ) diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index 9eb46bc381..6c989f3cda 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -23,7 +23,7 @@ class SessionManagerTest extends MediaWikiTestCase { 'SessionCacheType' => 'testSessionStore', 'ObjectCacheSessionExpiry' => 100, 'SessionProviders' => [ - [ 'class' => 'DummySessionProvider' ], + [ 'class' => \DummySessionProvider::class ], ] ] ); $this->logger = new \TestLogger( false, function ( $m ) { @@ -138,7 +138,7 @@ class SessionManagerTest extends MediaWikiTestCase { $id2 = ''; $idEmpty = 'empty-session-------------------'; - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'provideSessionInfo', 'newSessionInfo', '__toString', 'describe', 'unpersistSession' ] ); @@ -397,7 +397,7 @@ class SessionManagerTest extends MediaWikiTestCase { // Failure to create an empty session $manager = $this->getManager(); - $provider = $this->getMockBuilder( 'DummySessionProvider' ) + $provider = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'provideSessionInfo', 'newSessionInfo', '__toString' ] ) ->getMock(); $provider->expects( $this->any() )->method( 'provideSessionInfo' ) @@ -422,7 +422,7 @@ class SessionManagerTest extends MediaWikiTestCase { $pmanager = TestingAccessWrapper::newFromObject( $manager ); $request = new \FauxRequest(); - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'provideSessionInfo', 'newSessionInfo', '__toString' ] ); $expectId = null; @@ -646,7 +646,7 @@ class SessionManagerTest extends MediaWikiTestCase { $user = User::newFromName( 'UTSysop' ); $manager = $this->getManager(); - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'invalidateSessionsForUser', '__toString' ] ); $provider1 = $providerBuilder->getMock(); @@ -674,7 +674,7 @@ class SessionManagerTest extends MediaWikiTestCase { public function testGetVaryHeaders() { $manager = $this->getManager(); - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'getVaryHeaders', '__toString' ] ); $provider1 = $providerBuilder->getMock(); @@ -718,7 +718,7 @@ class SessionManagerTest extends MediaWikiTestCase { public function testGetVaryCookies() { $manager = $this->getManager(); - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'getVaryCookies', '__toString' ] ); $provider1 = $providerBuilder->getMock(); @@ -751,7 +751,7 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = TestingAccessWrapper::newFromObject( $realManager ); $this->config->set( 'SessionProviders', [ - [ 'class' => 'DummySessionProvider' ], + [ 'class' => \DummySessionProvider::class ], ] ); $providers = $manager->getProviders(); $this->assertArrayHasKey( 'DummySessionProvider', $providers ); @@ -761,8 +761,8 @@ class SessionManagerTest extends MediaWikiTestCase { $this->assertSame( $realManager, $provider->getManager() ); $this->config->set( 'SessionProviders', [ - [ 'class' => 'DummySessionProvider' ], - [ 'class' => 'DummySessionProvider' ], + [ 'class' => \DummySessionProvider::class ], + [ 'class' => \DummySessionProvider::class ], ] ); $manager->sessionProviders = null; try { @@ -780,7 +780,7 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = TestingAccessWrapper::newFromObject( $this->getManager() ); $manager->setLogger( new \Psr\Log\NullLogger() ); - $mock = $this->getMockBuilder( 'stdClass' ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'shutdown' ] )->getMock(); $mock->expects( $this->once() )->method( 'shutdown' ); @@ -871,7 +871,7 @@ class SessionManagerTest extends MediaWikiTestCase { public function testPreventSessionsForUser() { $manager = $this->getManager(); - $providerBuilder = $this->getMockBuilder( 'DummySessionProvider' ) + $providerBuilder = $this->getMockBuilder( \DummySessionProvider::class ) ->setMethods( [ 'preventSessionsForUser', '__toString' ] ); $provider1 = $providerBuilder->getMock(); diff --git a/tests/phpunit/includes/session/UserInfoTest.php b/tests/phpunit/includes/session/UserInfoTest.php index c38edd694a..4d79a9567a 100644 --- a/tests/phpunit/includes/session/UserInfoTest.php +++ b/tests/phpunit/includes/session/UserInfoTest.php @@ -41,7 +41,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo->getId() ); $this->assertSame( $user->getName(), $userinfo->getName() ); $this->assertSame( $user->getToken( true ), $userinfo->getToken() ); - $this->assertInstanceOf( 'User', $userinfo->getUser() ); + $this->assertInstanceOf( User::class, $userinfo->getUser() ); $userinfo2 = $userinfo->verified(); $this->assertNotSame( $userinfo2, $userinfo ); $this->assertSame( "<-:{$user->getId()}:{$user->getName()}>", (string)$userinfo ); @@ -51,7 +51,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo2->getId() ); $this->assertSame( $user->getName(), $userinfo2->getName() ); $this->assertSame( $user->getToken( true ), $userinfo2->getToken() ); - $this->assertInstanceOf( 'User', $userinfo2->getUser() ); + $this->assertInstanceOf( User::class, $userinfo2->getUser() ); $this->assertSame( $userinfo2, $userinfo2->verified() ); $this->assertSame( "<+:{$user->getId()}:{$user->getName()}>", (string)$userinfo2 ); @@ -76,7 +76,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo->getId() ); $this->assertSame( $user->getName(), $userinfo->getName() ); $this->assertSame( $user->getToken( true ), $userinfo->getToken() ); - $this->assertInstanceOf( 'User', $userinfo->getUser() ); + $this->assertInstanceOf( User::class, $userinfo->getUser() ); $userinfo2 = $userinfo->verified(); $this->assertNotSame( $userinfo2, $userinfo ); $this->assertSame( "<-:{$user->getId()}:{$user->getName()}>", (string)$userinfo ); @@ -86,7 +86,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo2->getId() ); $this->assertSame( $user->getName(), $userinfo2->getName() ); $this->assertSame( $user->getToken( true ), $userinfo2->getToken() ); - $this->assertInstanceOf( 'User', $userinfo2->getUser() ); + $this->assertInstanceOf( User::class, $userinfo2->getUser() ); $this->assertSame( $userinfo2, $userinfo2->verified() ); $this->assertSame( "<+:{$user->getId()}:{$user->getName()}>", (string)$userinfo2 ); @@ -103,7 +103,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo->getId() ); $this->assertSame( $user->getName(), $userinfo->getName() ); $this->assertSame( '', $userinfo->getToken() ); - $this->assertInstanceOf( 'User', $userinfo->getUser() ); + $this->assertInstanceOf( User::class, $userinfo->getUser() ); $userinfo2 = $userinfo->verified(); $this->assertNotSame( $userinfo2, $userinfo ); $this->assertSame( "<-:{$user->getId()}:{$user->getName()}>", (string)$userinfo ); @@ -113,7 +113,7 @@ class UserInfoTest extends MediaWikiTestCase { $this->assertSame( $user->getId(), $userinfo2->getId() ); $this->assertSame( $user->getName(), $userinfo2->getName() ); $this->assertSame( '', $userinfo2->getToken() ); - $this->assertInstanceOf( 'User', $userinfo2->getUser() ); + $this->assertInstanceOf( User::class, $userinfo2->getUser() ); $this->assertSame( $userinfo2, $userinfo2->verified() ); $this->assertSame( "<+:{$user->getId()}:{$user->getName()}>", (string)$userinfo2 ); diff --git a/tests/phpunit/includes/site/CachingSiteStoreTest.php b/tests/phpunit/includes/site/CachingSiteStoreTest.php index adf95e6cde..0fdcf6dab2 100644 --- a/tests/phpunit/includes/site/CachingSiteStoreTest.php +++ b/tests/phpunit/includes/site/CachingSiteStoreTest.php @@ -42,13 +42,13 @@ class CachingSiteStoreTest extends MediaWikiTestCase { $sites = $store->getSites(); - $this->assertInstanceOf( 'SiteList', $sites ); + $this->assertInstanceOf( SiteList::class, $sites ); /** * @var Site $site */ foreach ( $sites as $site ) { - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); } foreach ( $testSites as $site ) { @@ -79,11 +79,11 @@ class CachingSiteStoreTest extends MediaWikiTestCase { $this->assertTrue( $store->saveSites( $sites ) ); $site = $store->getSite( 'ertrywuutr' ); - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); $this->assertEquals( 'en', $site->getLanguageCode() ); $site = $store->getSite( 'sdfhxujgkfpth' ); - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); $this->assertEquals( 'nl', $site->getLanguageCode() ); } @@ -91,7 +91,7 @@ class CachingSiteStoreTest extends MediaWikiTestCase { * @covers CachingSiteStore::reset */ public function testReset() { - $dbSiteStore = $this->getMockBuilder( 'SiteStore' ) + $dbSiteStore = $this->getMockBuilder( SiteStore::class ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/phpunit/includes/site/DBSiteStoreTest.php b/tests/phpunit/includes/site/DBSiteStoreTest.php index ae85f8a1a2..7c16f6c51f 100644 --- a/tests/phpunit/includes/site/DBSiteStoreTest.php +++ b/tests/phpunit/includes/site/DBSiteStoreTest.php @@ -51,13 +51,13 @@ class DBSiteStoreTest extends MediaWikiTestCase { $sites = $store->getSites(); - $this->assertInstanceOf( 'SiteList', $sites ); + $this->assertInstanceOf( SiteList::class, $sites ); /** * @var Site $site */ foreach ( $sites as $site ) { - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); } foreach ( $expectedSites as $site ) { @@ -88,13 +88,13 @@ class DBSiteStoreTest extends MediaWikiTestCase { $this->assertTrue( $store->saveSites( $sites ) ); $site = $store->getSite( 'ertrywuutr' ); - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); $this->assertEquals( 'en', $site->getLanguageCode() ); $this->assertTrue( is_int( $site->getInternalId() ) ); $this->assertTrue( $site->getInternalId() >= 0 ); $site = $store->getSite( 'sdfhxujgkfpth' ); - $this->assertInstanceOf( 'Site', $site ); + $this->assertInstanceOf( Site::class, $site ); $this->assertEquals( 'nl', $site->getLanguageCode() ); $this->assertTrue( is_int( $site->getInternalId() ) ); $this->assertTrue( $site->getInternalId() >= 0 ); diff --git a/tests/phpunit/includes/site/FileBasedSiteLookupTest.php b/tests/phpunit/includes/site/FileBasedSiteLookupTest.php index ed6fbfeede..05aa6d393a 100644 --- a/tests/phpunit/includes/site/FileBasedSiteLookupTest.php +++ b/tests/phpunit/includes/site/FileBasedSiteLookupTest.php @@ -66,7 +66,7 @@ class FileBasedSiteLookupTest extends PHPUnit_Framework_TestCase { } private function getSiteLookup( SiteList $sites ) { - $siteLookup = $this->getMockBuilder( 'SiteLookup' ) + $siteLookup = $this->getMockBuilder( SiteLookup::class ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/phpunit/includes/site/SiteExporterTest.php b/tests/phpunit/includes/site/SiteExporterTest.php index 09cdea7a08..3a41b5fc69 100644 --- a/tests/phpunit/includes/site/SiteExporterTest.php +++ b/tests/phpunit/includes/site/SiteExporterTest.php @@ -34,7 +34,7 @@ class SiteExporterTest extends PHPUnit_Framework_TestCase { use MediaWikiCoversValidator; public function testConstructor_InvalidArgument() { - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); new SiteExporter( 'Foo' ); } @@ -77,7 +77,7 @@ class SiteExporterTest extends PHPUnit_Framework_TestCase { } private function newSiteStore( SiteList $sites ) { - $store = $this->getMockBuilder( 'SiteStore' )->getMock(); + $store = $this->getMockBuilder( SiteStore::class )->getMock(); $store->expects( $this->once() ) ->method( 'saveSites' ) diff --git a/tests/phpunit/includes/site/SiteImporterTest.php b/tests/phpunit/includes/site/SiteImporterTest.php index 8a43bf8020..373dcc2912 100644 --- a/tests/phpunit/includes/site/SiteImporterTest.php +++ b/tests/phpunit/includes/site/SiteImporterTest.php @@ -34,7 +34,7 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { use MediaWikiCoversValidator; private function newSiteImporter( array $expectedSites, $errorCount ) { - $store = $this->getMockBuilder( 'SiteStore' )->getMock(); + $store = $this->getMockBuilder( SiteStore::class )->getMock(); $store->expects( $this->once() ) ->method( 'saveSites' ) @@ -46,7 +46,7 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { ->method( 'getSites' ) ->will( $this->returnValue( new SiteList() ) ); - $errorHandler = $this->getMockBuilder( 'Psr\Log\LoggerInterface' )->getMock(); + $errorHandler = $this->getMockBuilder( Psr\Log\LoggerInterface::class )->getMock(); $errorHandler->expects( $this->exactly( $errorCount ) ) ->method( 'error' ); @@ -148,9 +148,9 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { } public function testImportFromXML_malformed() { - $this->setExpectedException( 'Exception' ); + $this->setExpectedException( Exception::class ); - $store = $this->getMockBuilder( 'SiteStore' )->getMock(); + $store = $this->getMockBuilder( SiteStore::class )->getMock(); $importer = new SiteImporter( $store ); $importer->importFromXML( 'THIS IS NOT XML' ); } diff --git a/tests/phpunit/includes/site/SiteTest.php b/tests/phpunit/includes/site/SiteTest.php index 59f046b2ef..ac5f956e7a 100644 --- a/tests/phpunit/includes/site/SiteTest.php +++ b/tests/phpunit/includes/site/SiteTest.php @@ -283,12 +283,12 @@ class SiteTest extends MediaWikiTestCase { * @covers Site::unserialize */ public function testSerialization( Site $site ) { - $this->assertInstanceOf( 'Serializable', $site ); + $this->assertInstanceOf( Serializable::class, $site ); $serialization = serialize( $site ); $newInstance = unserialize( $serialization ); - $this->assertInstanceOf( 'Site', $newInstance ); + $this->assertInstanceOf( Site::class, $newInstance ); $this->assertEquals( $serialization, serialize( $newInstance ) ); } diff --git a/tests/phpunit/includes/site/SitesCacheFileBuilderTest.php b/tests/phpunit/includes/site/SitesCacheFileBuilderTest.php index 6514beb01f..c411ed8799 100644 --- a/tests/phpunit/includes/site/SitesCacheFileBuilderTest.php +++ b/tests/phpunit/includes/site/SitesCacheFileBuilderTest.php @@ -100,7 +100,7 @@ class SitesCacheFileBuilderTest extends PHPUnit_Framework_TestCase { } private function getSiteLookup( SiteList $sites ) { - $siteLookup = $this->getMockBuilder( 'SiteLookup' ) + $siteLookup = $this->getMockBuilder( SiteLookup::class ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/phpunit/includes/skins/SkinFactoryTest.php b/tests/phpunit/includes/skins/SkinFactoryTest.php index 0944ea2c0c..4289fd9188 100644 --- a/tests/phpunit/includes/skins/SkinFactoryTest.php +++ b/tests/phpunit/includes/skins/SkinFactoryTest.php @@ -11,7 +11,7 @@ class SkinFactoryTest extends MediaWikiTestCase { return new SkinFallback(); } ); $this->assertTrue( true ); // No exception thrown - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); $factory->register( 'invalid', 'Invalid', 'Invalid callback' ); } @@ -20,7 +20,7 @@ class SkinFactoryTest extends MediaWikiTestCase { */ public function testMakeSkinWithNoBuilders() { $factory = new SkinFactory(); - $this->setExpectedException( 'SkinException' ); + $this->setExpectedException( SkinException::class ); $factory->makeSkin( 'nobuilderregistered' ); } @@ -32,7 +32,7 @@ class SkinFactoryTest extends MediaWikiTestCase { $factory->register( 'unittest', 'Unittest', function () { return true; // Not a Skin object } ); - $this->setExpectedException( 'UnexpectedValueException' ); + $this->setExpectedException( UnexpectedValueException::class ); $factory->makeSkin( 'unittest' ); } @@ -46,8 +46,8 @@ class SkinFactoryTest extends MediaWikiTestCase { } ); $skin = $factory->makeSkin( 'testfallback' ); - $this->assertInstanceOf( 'Skin', $skin ); - $this->assertInstanceOf( 'SkinFallback', $skin ); + $this->assertInstanceOf( Skin::class, $skin ); + $this->assertInstanceOf( SkinFallback::class, $skin ); $this->assertEquals( 'fallback', $skin->getSkinName() ); } diff --git a/tests/phpunit/includes/skins/SkinTemplateTest.php b/tests/phpunit/includes/skins/SkinTemplateTest.php index e8260ac2ee..5b3fbfac89 100644 --- a/tests/phpunit/includes/skins/SkinTemplateTest.php +++ b/tests/phpunit/includes/skins/SkinTemplateTest.php @@ -13,7 +13,7 @@ class SkinTemplateTest extends MediaWikiTestCase { * @dataProvider makeListItemProvider */ public function testMakeListItem( $expected, $key, $item, $options, $message ) { - $template = $this->getMockForAbstractClass( 'BaseTemplate' ); + $template = $this->getMockForAbstractClass( BaseTemplate::class ); $this->assertEquals( $expected, diff --git a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php b/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php index f79f6e48c5..9ac546dc51 100644 --- a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php +++ b/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php @@ -83,7 +83,7 @@ class SpecialPageFactoryTest extends MediaWikiTestCase { SpecialPageFactory::resetList(); $page = SpecialPageFactory::getPage( 'testdummy' ); - $this->assertInstanceOf( 'SpecialPage', $page ); + $this->assertInstanceOf( SpecialPage::class, $page ); $page2 = SpecialPageFactory::getPage( 'testdummy' ); $this->assertEquals( $shouldReuseInstance, $page2 === $page, "Should re-use instance:" ); @@ -93,7 +93,7 @@ class SpecialPageFactoryTest extends MediaWikiTestCase { * @covers SpecialPageFactory::getNames */ public function testGetNames() { - $this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => 'SpecialAllPages' ] ); + $this->mergeMwGlobalArrayValue( 'wgSpecialPages', [ 'testdummy' => SpecialAllPages::class ] ); SpecialPageFactory::resetList(); $names = SpecialPageFactory::getNames(); diff --git a/tests/phpunit/includes/specialpage/SpecialPageTest.php b/tests/phpunit/includes/specialpage/SpecialPageTest.php index c665f3cf13..2ad397299b 100644 --- a/tests/phpunit/includes/specialpage/SpecialPageTest.php +++ b/tests/phpunit/includes/specialpage/SpecialPageTest.php @@ -67,7 +67,7 @@ class SpecialPageTest extends MediaWikiTestCase { $specialPage->getContext()->setUser( $user ); $specialPage->getContext()->setLanguage( Language::factory( 'en' ) ); - $this->setExpectedException( 'UserNotLoggedIn', $expected ); + $this->setExpectedException( UserNotLoggedIn::class, $expected ); // $specialPage->requireLogin( [ $reason [, $title ] ] ) call_user_func_array( diff --git a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php index 1208a20ce0..1d87a3a926 100644 --- a/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php +++ b/tests/phpunit/includes/specials/QueryAllSpecialPagesTest.php @@ -20,7 +20,7 @@ class QueryAllSpecialPagesTest extends MediaWikiTestCase { /** List query pages that can not be tested automatically */ protected $manualTest = [ - 'LinkSearchPage' + LinkSearchPage::class ]; /** @@ -30,7 +30,7 @@ class QueryAllSpecialPagesTest extends MediaWikiTestCase { * https://bugs.mysql.com/bug.php?id=10327 */ protected $reopensTempTable = [ - 'BrokenRedirects', + BrokenRedirects::class, ]; /** diff --git a/tests/phpunit/includes/specials/SpecialEditWatchlistTest.php b/tests/phpunit/includes/specials/SpecialEditWatchlistTest.php index ab3ac55324..05a63dbc49 100644 --- a/tests/phpunit/includes/specials/SpecialEditWatchlistTest.php +++ b/tests/phpunit/includes/specials/SpecialEditWatchlistTest.php @@ -19,7 +19,7 @@ class SpecialEditWatchlistTest extends SpecialPageTestBase { } public function testNotLoggedIn_throwsException() { - $this->setExpectedException( 'UserNotLoggedIn' ); + $this->setExpectedException( UserNotLoggedIn::class ); $this->executeSpecialPage(); } diff --git a/tests/phpunit/includes/specials/SpecialPreferencesTest.php b/tests/phpunit/includes/specials/SpecialPreferencesTest.php index c8158aeca8..bdfbb62e7e 100644 --- a/tests/phpunit/includes/specials/SpecialPreferencesTest.php +++ b/tests/phpunit/includes/specials/SpecialPreferencesTest.php @@ -25,7 +25,7 @@ class SpecialPreferencesTest extends MediaWikiTestCase { // Set a low limit $this->setMwGlobals( 'wgMaxSigChars', 2 ); - $user = $this->createMock( 'User' ); + $user = $this->createMock( User::class ); $user->expects( $this->any() ) ->method( 'isAnon' ) ->will( $this->returnValue( false ) ); diff --git a/tests/phpunit/includes/specials/SpecialSearchTest.php b/tests/phpunit/includes/specials/SpecialSearchTest.php index 94924ee1e7..f0a5726699 100644 --- a/tests/phpunit/includes/specials/SpecialSearchTest.php +++ b/tests/phpunit/includes/specials/SpecialSearchTest.php @@ -194,7 +194,7 @@ class SpecialSearchTest extends MediaWikiTestCase { ); $mockSearchEngine = $this->mockSearchEngine( $searchResults ); - $search = $this->getMockBuilder( 'SpecialSearch' ) + $search = $this->getMockBuilder( SpecialSearch::class ) ->setMethods( [ 'getSearchEngine' ] ) ->getMock(); $search->expects( $this->any() ) @@ -213,7 +213,7 @@ class SpecialSearchTest extends MediaWikiTestCase { } protected function mockSearchEngine( $results ) { - $mock = $this->getMockBuilder( 'SearchEngine' ) + $mock = $this->getMockBuilder( SearchEngine::class ) ->setMethods( [ 'searchText', 'searchTitle' ] ) ->getMock(); diff --git a/tests/phpunit/includes/specials/SpecialUncategorizedcategoriesTest.php b/tests/phpunit/includes/specials/SpecialUncategorizedcategoriesTest.php index 2ecef79bf1..80bd365f35 100644 --- a/tests/phpunit/includes/specials/SpecialUncategorizedcategoriesTest.php +++ b/tests/phpunit/includes/specials/SpecialUncategorizedcategoriesTest.php @@ -9,7 +9,7 @@ class UncategorizedCategoriesPageTest extends MediaWikiTestCase { */ public function testGetQueryInfo( $msgContent, $expected ) { $msg = new RawMessage( $msgContent ); - $mockContext = $this->getMockBuilder( 'RequestContext' )->getMock(); + $mockContext = $this->getMockBuilder( RequestContext::class )->getMock(); $mockContext->method( 'msg' )->willReturn( $msg ); $special = new UncategorizedCategoriesPage(); $special->setContext( $mockContext ); diff --git a/tests/phpunit/includes/specials/SpecialWatchlistTest.php b/tests/phpunit/includes/specials/SpecialWatchlistTest.php index a0fe33921f..5adbed813d 100644 --- a/tests/phpunit/includes/specials/SpecialWatchlistTest.php +++ b/tests/phpunit/includes/specials/SpecialWatchlistTest.php @@ -56,7 +56,7 @@ class SpecialWatchlistTest extends SpecialPageTestBase { } public function testNotLoggedIn_throwsException() { - $this->setExpectedException( 'UserNotLoggedIn' ); + $this->setExpectedException( UserNotLoggedIn::class ); $this->executeSpecialPage(); } diff --git a/tests/phpunit/includes/title/ForeignTitleTest.php b/tests/phpunit/includes/title/ForeignTitleTest.php index 25ff186b25..f2fccc7577 100644 --- a/tests/phpunit/includes/title/ForeignTitleTest.php +++ b/tests/phpunit/includes/title/ForeignTitleTest.php @@ -68,7 +68,7 @@ class ForeignTitleTest extends MediaWikiTestCase { } public function testUnknownNamespaceError() { - $this->setExpectedException( 'MWException' ); + $this->setExpectedException( MWException::class ); $title = new ForeignTitle( null, 'this', 'that' ); $title->getNamespaceId(); } diff --git a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php index e7ac940b92..e1b98ec341 100644 --- a/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php +++ b/tests/phpunit/includes/title/MediaWikiTitleCodecTest.php @@ -64,7 +64,7 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { * @return GenderCache */ private function getGenderCache() { - $genderCache = $this->getMockBuilder( 'GenderCache' ) + $genderCache = $this->getMockBuilder( GenderCache::class ) ->disableOriginalConstructor() ->getMock(); @@ -385,7 +385,7 @@ class MediaWikiTitleCodecTest extends MediaWikiTestCase { * @dataProvider provideParseTitle_invalid */ public function testParseTitle_invalid( $text ) { - $this->setExpectedException( 'MalformedTitleException' ); + $this->setExpectedException( MalformedTitleException::class ); $codec = $this->makeCodec( 'en' ); $codec->parseTitle( $text, NS_MAIN ); diff --git a/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php index 93ce08009f..008cf5d939 100644 --- a/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php +++ b/tests/phpunit/includes/title/SubpageImportTitleFactoryTest.php @@ -80,7 +80,7 @@ class SubpageImportTitleFactoryTest extends MediaWikiTestCase { * @dataProvider failureProvider */ public function testFailures( Title $rootPage ) { - $this->setExpectedException( 'MWException' ); + $this->setExpectedException( MWException::class ); new SubpageImportTitleFactory( $rootPage ); } } diff --git a/tests/phpunit/includes/title/TitleValueTest.php b/tests/phpunit/includes/title/TitleValueTest.php index f8335549f4..d221b431a0 100644 --- a/tests/phpunit/includes/title/TitleValueTest.php +++ b/tests/phpunit/includes/title/TitleValueTest.php @@ -78,7 +78,7 @@ class TitleValueTest extends MediaWikiTestCase { * @dataProvider badConstructorProvider */ public function testConstructionErrors( $ns, $text, $fragment, $interwiki ) { - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); new TitleValue( $ns, $text, $fragment, $interwiki ); } diff --git a/tests/phpunit/includes/upload/UploadStashTest.php b/tests/phpunit/includes/upload/UploadStashTest.php index f46ad20646..39acbb0740 100644 --- a/tests/phpunit/includes/upload/UploadStashTest.php +++ b/tests/phpunit/includes/upload/UploadStashTest.php @@ -105,7 +105,7 @@ class UploadStashTest extends MediaWikiTestCase { $stash->stashFile( $this->tmpFile ); $this->fail( 'Expected UploadStashFileException not thrown' ); } catch ( UploadStashFileException $e ) { - $this->assertInstanceOf( 'ILocalizedException', $e ); + $this->assertInstanceOf( ILocalizedException::class, $e ); } catch ( Exception $e ) { $this->fail( 'Unexpected exception class ' . get_class( $e ) ); } diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php index 09cf350729..3bbc2dfaf2 100644 --- a/tests/phpunit/includes/user/BotPasswordTest.php +++ b/tests/phpunit/includes/user/BotPasswordTest.php @@ -32,14 +32,14 @@ class BotPasswordTest extends MediaWikiTestCase { $this->testUser = $this->getMutableTestUser(); $this->testUserName = $this->testUser->getUser()->getName(); - $mock1 = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock1 = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock1->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( true ) ); $mock1->expects( $this->any() )->method( 'lookupUserNames' ) ->will( $this->returnValue( [ $this->testUserName => 42, 'UTDummy' => 43, 'UTInvalid' => 0 ] ) ); $mock1->expects( $this->never() )->method( 'lookupCentralIds' ); - $mock2 = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock2 = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock2->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( false ) ); $mock2->expects( $this->any() )->method( 'lookupUserNames' ) @@ -96,7 +96,7 @@ class BotPasswordTest extends MediaWikiTestCase { public function testBasics() { $user = $this->testUser->getUser(); $bp = BotPassword::newFromUser( $user, 'BotPassword' ); - $this->assertInstanceOf( 'BotPassword', $bp ); + $this->assertInstanceOf( BotPassword::class, $bp ); $this->assertTrue( $bp->isSaved() ); $this->assertSame( 42, $bp->getUserCentralId() ); $this->assertSame( 'BotPassword', $bp->getAppId() ); @@ -124,7 +124,7 @@ class BotPasswordTest extends MediaWikiTestCase { 'user' => $user, 'appId' => 'DoesNotExist' ] ); - $this->assertInstanceOf( 'BotPassword', $bp ); + $this->assertInstanceOf( BotPassword::class, $bp ); $this->assertFalse( $bp->isSaved() ); $this->assertSame( 42, $bp->getUserCentralId() ); $this->assertSame( 'DoesNotExist', $bp->getAppId() ); @@ -137,7 +137,7 @@ class BotPasswordTest extends MediaWikiTestCase { 'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ), 'grants' => [ 'test' ], ] ); - $this->assertInstanceOf( 'BotPassword', $bp ); + $this->assertInstanceOf( BotPassword::class, $bp ); $this->assertFalse( $bp->isSaved() ); $this->assertSame( 43, $bp->getUserCentralId() ); $this->assertSame( 'DoesNotExist2', $bp->getAppId() ); @@ -149,7 +149,7 @@ class BotPasswordTest extends MediaWikiTestCase { 'centralId' => 45, 'appId' => 'DoesNotExist' ] ); - $this->assertInstanceOf( 'BotPassword', $bp ); + $this->assertInstanceOf( BotPassword::class, $bp ); $this->assertFalse( $bp->isSaved() ); $this->assertSame( 45, $bp->getUserCentralId() ); $this->assertSame( 'DoesNotExist', $bp->getAppId() ); @@ -159,7 +159,7 @@ class BotPasswordTest extends MediaWikiTestCase { 'user' => $user, 'appId' => 'BotPassword' ] ); - $this->assertInstanceOf( 'BotPassword', $bp ); + $this->assertInstanceOf( BotPassword::class, $bp ); $this->assertFalse( $bp->isSaved() ); $this->assertNull( BotPassword::newUnsaved( [ @@ -187,12 +187,12 @@ class BotPasswordTest extends MediaWikiTestCase { $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) ); $password = $bp->getPassword(); - $this->assertInstanceOf( 'Password', $password ); + $this->assertInstanceOf( Password::class, $password ); $this->assertTrue( $password->equals( 'foobaz' ) ); $bp->centralId = 44; $password = $bp->getPassword(); - $this->assertInstanceOf( 'InvalidPassword', $password ); + $this->assertInstanceOf( InvalidPassword::class, $password ); $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) ); $dbw = wfGetDB( DB_MASTER ); @@ -203,21 +203,21 @@ class BotPasswordTest extends MediaWikiTestCase { __METHOD__ ); $password = $bp->getPassword(); - $this->assertInstanceOf( 'InvalidPassword', $password ); + $this->assertInstanceOf( InvalidPassword::class, $password ); } public function testInvalidateAllPasswordsForUser() { $bp1 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) ); $bp2 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 43, 'BotPassword' ) ); - $this->assertNotInstanceOf( 'InvalidPassword', $bp1->getPassword(), 'sanity check' ); - $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword(), 'sanity check' ); + $this->assertNotInstanceOf( InvalidPassword::class, $bp1->getPassword(), 'sanity check' ); + $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword(), 'sanity check' ); BotPassword::invalidateAllPasswordsForUser( $this->testUserName ); - $this->assertInstanceOf( 'InvalidPassword', $bp1->getPassword() ); - $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword() ); + $this->assertInstanceOf( InvalidPassword::class, $bp1->getPassword() ); + $this->assertNotInstanceOf( InvalidPassword::class, $bp2->getPassword() ); $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) ); - $this->assertInstanceOf( 'InvalidPassword', $bp->getPassword() ); + $this->assertInstanceOf( InvalidPassword::class, $bp->getPassword() ); } public function testRemoveAllPasswordsForUser() { @@ -312,7 +312,7 @@ class BotPasswordTest extends MediaWikiTestCase { ); // Failed restriction - $request = $this->getMockBuilder( 'FauxRequest' ) + $request = $this->getMockBuilder( FauxRequest::class ) ->setMethods( [ 'getIP' ] ) ->getMock(); $request->expects( $this->any() )->method( 'getIP' ) @@ -333,7 +333,7 @@ class BotPasswordTest extends MediaWikiTestCase { 'sanity check' ); $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request ); - $this->assertInstanceOf( 'Status', $status ); + $this->assertInstanceOf( Status::class, $status ); $this->assertTrue( $status->isGood() ); $session = $status->getValue(); $this->assertInstanceOf( MediaWiki\Session\Session::class, $session ); @@ -368,7 +368,7 @@ class BotPasswordTest extends MediaWikiTestCase { $this->assertFalse( $bp->save( 'update', $passwordHash ) ); $this->assertTrue( $bp->save( 'insert', $passwordHash ) ); $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ); - $this->assertInstanceOf( 'BotPassword', $bp2 ); + $this->assertInstanceOf( BotPassword::class, $bp2 ); $this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() ); $this->assertEquals( $bp->getAppId(), $bp2->getAppId() ); $this->assertEquals( $bp->getToken(), $bp2->getToken() ); @@ -376,7 +376,7 @@ class BotPasswordTest extends MediaWikiTestCase { $this->assertEquals( $bp->getGrants(), $bp2->getGrants() ); $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword(); if ( $password === null ) { - $this->assertInstanceOf( 'InvalidPassword', $pw ); + $this->assertInstanceOf( InvalidPassword::class, $pw ); } else { $this->assertTrue( $pw->equals( $password ) ); } @@ -388,11 +388,11 @@ class BotPasswordTest extends MediaWikiTestCase { $this->assertTrue( $bp->save( 'update' ) ); $this->assertNotEquals( $token, $bp->getToken() ); $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ); - $this->assertInstanceOf( 'BotPassword', $bp2 ); + $this->assertInstanceOf( BotPassword::class, $bp2 ); $this->assertEquals( $bp->getToken(), $bp2->getToken() ); $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword(); if ( $password === null ) { - $this->assertInstanceOf( 'InvalidPassword', $pw ); + $this->assertInstanceOf( InvalidPassword::class, $pw ); } else { $this->assertTrue( $pw->equals( $password ) ); } diff --git a/tests/phpunit/includes/user/CentralIdLookupTest.php b/tests/phpunit/includes/user/CentralIdLookupTest.php index 789cf08fbf..dc9fe2add8 100644 --- a/tests/phpunit/includes/user/CentralIdLookupTest.php +++ b/tests/phpunit/includes/user/CentralIdLookupTest.php @@ -9,16 +9,16 @@ use Wikimedia\TestingAccessWrapper; class CentralIdLookupTest extends MediaWikiTestCase { public function testFactory() { - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $this->setMwGlobals( [ 'wgCentralIdLookupProviders' => [ - 'local' => [ 'class' => 'LocalIdLookup' ], - 'local2' => [ 'class' => 'LocalIdLookup' ], + 'local' => [ 'class' => LocalIdLookup::class ], + 'local2' => [ 'class' => LocalIdLookup::class ], 'mock' => [ 'factory' => function () use ( $mock ) { return $mock; } ], - 'bad' => [ 'class' => 'stdClass' ], + 'bad' => [ 'class' => stdClass::class ], ], 'wgCentralIdLookupProvider' => 'mock', ] ); @@ -29,13 +29,13 @@ class CentralIdLookupTest extends MediaWikiTestCase { $local = CentralIdLookup::factory( 'local' ); $this->assertNotSame( $mock, $local ); - $this->assertInstanceOf( 'LocalIdLookup', $local ); + $this->assertInstanceOf( LocalIdLookup::class, $local ); $this->assertSame( $local, CentralIdLookup::factory( 'local' ) ); $this->assertSame( 'local', $local->getProviderId() ); $local2 = CentralIdLookup::factory( 'local2' ); $this->assertNotSame( $local, $local2 ); - $this->assertInstanceOf( 'LocalIdLookup', $local2 ); + $this->assertInstanceOf( LocalIdLookup::class, $local2 ); $this->assertSame( 'local2', $local2->getProviderId() ); $this->assertNull( CentralIdLookup::factory( 'unconfigured' ) ); @@ -44,14 +44,14 @@ class CentralIdLookupTest extends MediaWikiTestCase { public function testCheckAudience() { $mock = TestingAccessWrapper::newFromObject( - $this->getMockForAbstractClass( 'CentralIdLookup' ) + $this->getMockForAbstractClass( CentralIdLookup::class ) ); $user = static::getTestSysop()->getUser(); $this->assertSame( $user, $mock->checkAudience( $user ) ); $user = $mock->checkAudience( CentralIdLookup::AUDIENCE_PUBLIC ); - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( User::class, $user ); $this->assertSame( 0, $user->getId() ); $this->assertNull( $mock->checkAudience( CentralIdLookup::AUDIENCE_RAW ) ); @@ -65,7 +65,7 @@ class CentralIdLookupTest extends MediaWikiTestCase { } public function testNameFromCentralId() { - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->once() )->method( 'lookupCentralIds' ) ->with( $this->equalTo( [ 15 => null ] ), @@ -86,7 +86,7 @@ class CentralIdLookupTest extends MediaWikiTestCase { * @param bool $succeeds */ public function testLocalUserFromCentralId( $name, $succeeds ) { - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( true ) ); $mock->expects( $this->once() )->method( 'lookupCentralIds' ) @@ -101,13 +101,13 @@ class CentralIdLookupTest extends MediaWikiTestCase { 42, CentralIdLookup::AUDIENCE_RAW, CentralIdLookup::READ_LATEST ); if ( $succeeds ) { - $this->assertInstanceOf( 'User', $user ); + $this->assertInstanceOf( User::class, $user ); $this->assertSame( $name, $user->getName() ); } else { $this->assertNull( $user ); } - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( false ) ); $mock->expects( $this->once() )->method( 'lookupCentralIds' ) @@ -133,7 +133,7 @@ class CentralIdLookupTest extends MediaWikiTestCase { } public function testCentralIdFromName() { - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->once() )->method( 'lookupUserNames' ) ->with( $this->equalTo( [ 'FooBar' => 0 ] ), @@ -149,7 +149,7 @@ class CentralIdLookupTest extends MediaWikiTestCase { } public function testCentralIdFromLocalUser() { - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( true ) ); $mock->expects( $this->once() )->method( 'lookupUserNames' ) @@ -167,7 +167,7 @@ class CentralIdLookupTest extends MediaWikiTestCase { ) ); - $mock = $this->getMockForAbstractClass( 'CentralIdLookup' ); + $mock = $this->getMockForAbstractClass( CentralIdLookup::class ); $mock->expects( $this->any() )->method( 'isAttached' ) ->will( $this->returnValue( false ) ); $mock->expects( $this->never() )->method( 'lookupUserNames' ); diff --git a/tests/phpunit/includes/user/UserArrayFromResultTest.php b/tests/phpunit/includes/user/UserArrayFromResultTest.php index cf980b1278..beaacec800 100644 --- a/tests/phpunit/includes/user/UserArrayFromResultTest.php +++ b/tests/phpunit/includes/user/UserArrayFromResultTest.php @@ -7,7 +7,7 @@ class UserArrayFromResultTest extends MediaWikiTestCase { private function getMockResultWrapper( $row = null, $numRows = 1 ) { - $resultWrapper = $this->getMockBuilder( 'ResultWrapper' ) + $resultWrapper = $this->getMockBuilder( Wikimedia\Rdbms\ResultWrapper::class ) ->disableOriginalConstructor(); $resultWrapper = $resultWrapper->getMock(); @@ -57,7 +57,7 @@ class UserArrayFromResultTest extends MediaWikiTestCase { $this->assertEquals( $resultWrapper, $object->res ); $this->assertSame( 0, $object->key ); - $this->assertInstanceOf( 'User', $object->current ); + $this->assertInstanceOf( User::class, $object->current ); $this->assertEquals( $username, $object->current->mName ); } @@ -88,7 +88,7 @@ class UserArrayFromResultTest extends MediaWikiTestCase { $username = 'addshore'; $userRow = $this->getRowWithUsername( $username ); $object = $this->getUserArrayFromResult( $this->getMockResultWrapper( $userRow ) ); - $this->assertInstanceOf( 'User', $object->current() ); + $this->assertInstanceOf( User::class, $object->current() ); $this->assertEquals( $username, $object->current()->mName ); } diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index ea7f715b5f..4c1a5fd103 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -121,7 +121,7 @@ class UserTest extends MediaWikiTestCase { $this->assertContains( 'nukeworld', $rights ); // Add a Session that limits rights - $mock = $this->getMockBuilder( stdclass::class ) + $mock = $this->getMockBuilder( stdClass::class ) ->setMethods( [ 'getAllowedUserRights', 'deregisterSession', 'getSessionId' ] ) ->getMock(); $mock->method( 'getAllowedUserRights' )->willReturn( [ 'test', 'writetest' ] ); diff --git a/tests/phpunit/includes/utils/BatchRowUpdateTest.php b/tests/phpunit/includes/utils/BatchRowUpdateTest.php index d80a61c4fb..f06a35319e 100644 --- a/tests/phpunit/includes/utils/BatchRowUpdateTest.php +++ b/tests/phpunit/includes/utils/BatchRowUpdateTest.php @@ -241,7 +241,7 @@ class BatchRowUpdateTest extends MediaWikiTestCase { protected function mockDb() { // @TODO: mock from Database // FIXME: the constructor normally sets mAtomicLevels and mSrvCache - $databaseMysql = $this->getMockBuilder( 'DatabaseMysqli' ) + $databaseMysql = $this->getMockBuilder( Wikimedia\Rdbms\DatabaseMysqli::class ) ->disableOriginalConstructor() ->getMock(); $databaseMysql->expects( $this->any() ) diff --git a/tests/phpunit/includes/utils/MWRestrictionsTest.php b/tests/phpunit/includes/utils/MWRestrictionsTest.php index 4c05326275..c411e53319 100644 --- a/tests/phpunit/includes/utils/MWRestrictionsTest.php +++ b/tests/phpunit/includes/utils/MWRestrictionsTest.php @@ -21,7 +21,7 @@ class MWRestrictionsTest extends PHPUnit_Framework_TestCase { */ public function testNewDefault() { $ret = MWRestrictions::newDefault(); - $this->assertInstanceOf( 'MWRestrictions', $ret ); + $this->assertInstanceOf( MWRestrictions::class, $ret ); $this->assertSame( '{"IPAddresses":["0.0.0.0/0","::/0"]}', $ret->toJson() @@ -41,7 +41,7 @@ class MWRestrictionsTest extends PHPUnit_Framework_TestCase { public function testArray( $data, $expect ) { if ( $expect === true ) { $ret = MWRestrictions::newFromArray( $data ); - $this->assertInstanceOf( 'MWRestrictions', $ret ); + $this->assertInstanceOf( MWRestrictions::class, $ret ); $this->assertSame( $data, $ret->toArray() ); } else { try { @@ -89,7 +89,7 @@ class MWRestrictionsTest extends PHPUnit_Framework_TestCase { public function testJson( $json, $expect ) { if ( is_array( $expect ) ) { $ret = MWRestrictions::newFromJson( $json ); - $this->assertInstanceOf( 'MWRestrictions', $ret ); + $this->assertInstanceOf( MWRestrictions::class, $ret ); $this->assertSame( $expect, $ret->toArray() ); $this->assertSame( $json, $ret->toJson( false ) ); @@ -180,7 +180,7 @@ class MWRestrictionsTest extends PHPUnit_Framework_TestCase { public function provideCheck() { $ret = []; - $mockBuilder = $this->getMockBuilder( 'FauxRequest' ) + $mockBuilder = $this->getMockBuilder( FauxRequest::class ) ->setMethods( [ 'getIP' ] ); foreach ( self::provideCheckIP() as $checkIP ) { diff --git a/tests/phpunit/includes/utils/UIDGeneratorTest.php b/tests/phpunit/includes/utils/UIDGeneratorTest.php index 230c9354b9..c6b8bdd474 100644 --- a/tests/phpunit/includes/utils/UIDGeneratorTest.php +++ b/tests/phpunit/includes/utils/UIDGeneratorTest.php @@ -18,7 +18,7 @@ class UIDGeneratorTest extends PHPUnit_Framework_TestCase { * @covers UIDGenerator::newTimestampedUID88 */ public function testTimestampedUID( $method, $digitlen, $bits, $tbits, $hostbits ) { - $id = call_user_func( [ 'UIDGenerator', $method ] ); + $id = call_user_func( [ UIDGenerator::class, $method ] ); $this->assertEquals( true, ctype_digit( $id ), "UID made of digit characters" ); $this->assertLessThanOrEqual( $digitlen, strlen( $id ), "UID has the right number of digits" ); @@ -27,7 +27,7 @@ class UIDGeneratorTest extends PHPUnit_Framework_TestCase { $ids = []; for ( $i = 0; $i < 300; $i++ ) { - $ids[] = call_user_func( [ 'UIDGenerator', $method ] ); + $ids[] = call_user_func( [ UIDGenerator::class, $method ] ); } $lastId = array_shift( $ids ); diff --git a/tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php index 82a11936a1..6dbb10697e 100644 --- a/tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/watcheditem/WatchedItemStoreUnitTest.php @@ -1118,7 +1118,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { $this->getMockNonAnonUserWithId( 1 ), new TitleValue( 0, 'SomeDbKey' ) ); - $this->assertInstanceOf( 'WatchedItem', $watchedItem ); + $this->assertInstanceOf( WatchedItem::class, $watchedItem ); $this->assertEquals( 1, $watchedItem->getUser()->getId() ); $this->assertEquals( 'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() ); $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() ); @@ -1317,7 +1317,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { $this->getMockNonAnonUserWithId( 1 ), new TitleValue( 0, 'SomeDbKey' ) ); - $this->assertInstanceOf( 'WatchedItem', $watchedItem ); + $this->assertInstanceOf( WatchedItem::class, $watchedItem ); $this->assertEquals( 1, $watchedItem->getUser()->getId() ); $this->assertEquals( 'SomeDbKey', $watchedItem->getLinkTarget()->getDBkey() ); $this->assertEquals( 0, $watchedItem->getLinkTarget()->getNamespace() ); @@ -1457,7 +1457,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { $this->assertInternalType( 'array', $watchedItems ); $this->assertCount( 2, $watchedItems ); foreach ( $watchedItems as $watchedItem ) { - $this->assertInstanceOf( 'WatchedItem', $watchedItem ); + $this->assertInstanceOf( WatchedItem::class, $watchedItem ); } $this->assertEquals( new WatchedItem( $user, new TitleValue( 0, 'Foo1' ), '20151212010101' ), @@ -1516,7 +1516,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { $this->getMockReadOnlyMode() ); - $this->setExpectedException( 'InvalidArgumentException' ); + $this->setExpectedException( InvalidArgumentException::class ); $store->getWatchedItemsForUser( $this->getMockNonAnonUserWithId( 1 ), [ 'sort' => 'foo' ] diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php index ce7197dc62..ad9bf3ea97 100644 --- a/tests/phpunit/maintenance/backupTextPassTest.php +++ b/tests/phpunit/maintenance/backupTextPassTest.php @@ -179,7 +179,7 @@ class TextPassDumperDatabaseTest extends DumpTestCase { ]; // The mock itself - $prefetchMock = $this->getMockBuilder( 'BaseDump' ) + $prefetchMock = $this->getMockBuilder( BaseDump::class ) ->setMethods( [ 'prefetch' ] ) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/phpunit/structure/ApiStructureTest.php b/tests/phpunit/structure/ApiStructureTest.php index cbc74f4ed7..6d8655137f 100644 --- a/tests/phpunit/structure/ApiStructureTest.php +++ b/tests/phpunit/structure/ApiStructureTest.php @@ -50,7 +50,7 @@ class ApiStructureTest extends MediaWikiTestCase { */ private function checkMessage( $msg, $what ) { $msg = ApiBase::makeMessage( $msg, self::getMain()->getContext() ); - $this->assertInstanceOf( 'Message', $msg, "$what message" ); + $this->assertInstanceOf( Message::class, $msg, "$what message" ); $this->assertTrue( $msg->exists(), "$what message {$msg->getKey()} exists" ); } diff --git a/tests/phpunit/suites/UploadFromUrlTestSuite.php b/tests/phpunit/suites/UploadFromUrlTestSuite.php index f2e6858abe..6fb428bb8e 100644 --- a/tests/phpunit/suites/UploadFromUrlTestSuite.php +++ b/tests/phpunit/suites/UploadFromUrlTestSuite.php @@ -30,7 +30,7 @@ class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite { $tmpGlobals['wgStylePath'] = '/skins'; $tmpGlobals['wgThumbnailScriptPath'] = false; $tmpGlobals['wgLocalFileRepo'] = [ - 'class' => 'LocalRepo', + 'class' => LocalRepo::class, 'name' => 'local', 'url' => 'http://example.com/images', 'hashLevels' => 2, diff --git a/tests/phpunit/tests/MediaWikiTestCaseTest.php b/tests/phpunit/tests/MediaWikiTestCaseTest.php index fb2957be83..1850f6fe5c 100644 --- a/tests/phpunit/tests/MediaWikiTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php @@ -165,7 +165,7 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { $logger2 = LoggerFactory::getInstance( 'foo' ); $this->assertNotSame( $logger1, $logger2 ); - $this->assertInstanceOf( '\Psr\Log\LoggerInterface', $logger2 ); + $this->assertInstanceOf( \Psr\Log\LoggerInterface::class, $logger2 ); } /**