From: jenkins-bot Date: Thu, 6 Apr 2017 23:30:01 +0000 (+0000) Subject: Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat" X-Git-Tag: 1.31.0-rc.0~3569 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=424251a2cb5842727756d96f877c787c443ea056;hp=34478c64dbda1cc214a89183983c06cbe70d68ac Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat" --- diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 564c0ff834..29da00d50e 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -1298,6 +1298,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { */ public function __call( $func, $args ) { static $compatibility = [ + 'createMock' => 'createMock2', ]; if ( isset( $compatibility[$func] ) ) { @@ -1307,6 +1308,23 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } } + /** + * Return a test double for the specified class. + * + * @param string $originalClassName + * @return PHPUnit_Framework_MockObject_MockObject + * @throws Exception + */ + private function createMock2( $originalClassName ) { + return $this->getMockBuilder( $originalClassName ) + ->disableOriginalConstructor() + ->disableOriginalClone() + ->disableArgumentCloning() + // New in phpunit-mock-objects 3.2 (phpunit 5.4.0) + // ->disallowMockingUnknownTypes() + ->getMock(); + } + private static function unprefixTable( &$tableName, $ind, $prefix ) { $tableName = substr( $tableName, strlen( $prefix ) ); } diff --git a/tests/phpunit/includes/MWTimestampTest.php b/tests/phpunit/includes/MWTimestampTest.php index 4bca4788ac..c1a46fed5b 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->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' ) @@ -156,7 +156,7 @@ class MWTimestampTest extends MediaWikiLangTestCase { $expectedOutput, // The expected output $desc // Description ) { - $user = $this->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() ) ->method( 'getOption' ) ->with( 'timecorrection' ) diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php index cc95e383dd..a72662f483 100644 --- a/tests/phpunit/includes/MediaWikiServicesTest.php +++ b/tests/phpunit/includes/MediaWikiServicesTest.php @@ -71,7 +71,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance( $newServices ); - $service1 = $this->getMock( SalvageableService::class ); + $service1 = $this->createMock( SalvageableService::class ); $service1->expects( $this->never() ) ->method( 'salvage' ); @@ -104,11 +104,11 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance( $newServices ); - $service1 = $this->getMock( SalvageableService::class ); + $service1 = $this->createMock( SalvageableService::class ); $service1->expects( $this->never() ) ->method( 'salvage' ); - $service2 = $this->getMock( SalvageableService::class ); + $service2 = $this->createMock( SalvageableService::class ); $service2->expects( $this->once() ) ->method( 'salvage' ) ->with( $service1 ); @@ -178,11 +178,11 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $newServices = $this->newMediaWikiServices(); $oldServices = MediaWikiServices::forceGlobalInstance( $newServices ); - $service1 = $this->getMock( DestructibleService::class ); + $service1 = $this->createMock( DestructibleService::class ); $service1->expects( $this->once() ) ->method( 'destroy' ); - $service2 = $this->getMock( DestructibleService::class ); + $service2 = $this->createMock( DestructibleService::class ); $service2->expects( $this->never() ) ->method( 'destroy' ); @@ -219,7 +219,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { 'Test', function() use ( &$serviceCounter ) { $serviceCounter++; - $service = $this->getMock( 'MediaWiki\Services\DestructibleService' ); + $service = $this->createMock( 'MediaWiki\Services\DestructibleService' ); $service->expects( $this->once() )->method( 'destroy' ); return $service; } @@ -248,7 +248,7 @@ class MediaWikiServicesTest extends MediaWikiTestCase { $services->defineService( 'Test', function() { - $service = $this->getMock( 'MediaWiki\Services\DestructibleService' ); + $service = $this->createMock( 'MediaWiki\Services\DestructibleService' ); $service->expects( $this->never() )->method( 'destroy' ); return $service; } diff --git a/tests/phpunit/includes/Services/ServiceContainerTest.php b/tests/phpunit/includes/Services/ServiceContainerTest.php index f22e123856..617e39cf9d 100644 --- a/tests/phpunit/includes/Services/ServiceContainerTest.php +++ b/tests/phpunit/includes/Services/ServiceContainerTest.php @@ -326,7 +326,8 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { public function testDisableService() { $services = $this->newServiceContainer( [ 'Foo' ] ); - $destructible = $this->getMock( 'MediaWiki\Services\DestructibleService' ); + $destructible = $this->getMockBuilder( 'MediaWiki\Services\DestructibleService' ) + ->getMock(); $destructible->expects( $this->once() ) ->method( 'destroy' ); @@ -384,7 +385,8 @@ class ServiceContainerTest extends PHPUnit_Framework_TestCase { public function testDestroy() { $services = $this->newServiceContainer(); - $destructible = $this->getMock( 'MediaWiki\Services\DestructibleService' ); + $destructible = $this->getMockBuilder( 'MediaWiki\Services\DestructibleService' ) + ->getMock(); $destructible->expects( $this->once() ) ->method( 'destroy' ); diff --git a/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php b/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php index bdec0a50d9..76d1cb9401 100644 --- a/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php +++ b/tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php @@ -66,7 +66,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { * @return PHPUnit_Framework_MockObject_MockObject|User */ private function getMockNonAnonUserWithId( $id ) { - $mock = $this->getMock( User::class ); + $mock = $this->getMockBuilder( User::class )->getMock(); $mock->expects( $this->any() ) ->method( 'isAnon' ) ->will( $this->returnValue( false ) ); @@ -142,7 +142,7 @@ class WatchedItemQueryServiceUnitTest extends PHPUnit_Framework_TestCase { } private function getMockAnonUser() { - $mock = $this->getMock( User::class ); + $mock = $this->getMockBuilder( User::class )->getMock(); $mock->expects( $this->any() ) ->method( 'isAnon' ) ->will( $this->returnValue( true ) ); diff --git a/tests/phpunit/includes/WatchedItemStoreUnitTest.php b/tests/phpunit/includes/WatchedItemStoreUnitTest.php index 0bd0bccbf4..b71e8f4d5c 100644 --- a/tests/phpunit/includes/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/includes/WatchedItemStoreUnitTest.php @@ -13,7 +13,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { * @return PHPUnit_Framework_MockObject_MockObject|IDatabase */ private function getMockDb() { - return $this->getMock( IDatabase::class ); + return $this->createMock( IDatabase::class ); } /** @@ -63,7 +63,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { * @return PHPUnit_Framework_MockObject_MockObject|User */ private function getMockNonAnonUserWithId( $id ) { - $mock = $this->getMock( User::class ); + $mock = $this->createMock( User::class ); $mock->expects( $this->any() ) ->method( 'isAnon' ) ->will( $this->returnValue( false ) ); @@ -1978,7 +1978,7 @@ class WatchedItemStoreUnitTest extends MediaWikiTestCase { * @return PHPUnit_Framework_MockObject_MockObject|Title */ private function getMockTitle( $text, $ns = 0 ) { - $title = $this->getMock( Title::class ); + $title = $this->createMock( Title::class ); $title->expects( $this->any() ) ->method( 'getText' ) ->will( $this->returnValue( str_replace( '_', ' ', $text ) ) ); diff --git a/tests/phpunit/includes/WatchedItemUnitTest.php b/tests/phpunit/includes/WatchedItemUnitTest.php index 7e1ff3d7a9..8897645479 100644 --- a/tests/phpunit/includes/WatchedItemUnitTest.php +++ b/tests/phpunit/includes/WatchedItemUnitTest.php @@ -14,7 +14,7 @@ class WatchedItemUnitTest extends MediaWikiTestCase { * @return PHPUnit_Framework_MockObject_MockObject|User */ private function getMockUser( $id ) { - $user = $this->getMock( User::class ); + $user = $this->createMock( User::class ); $user->expects( $this->any() ) ->method( 'getId' ) ->will( $this->returnValue( $id ) ); @@ -84,7 +84,7 @@ class WatchedItemUnitTest extends MediaWikiTestCase { $checkRights = 0; /** @var User|PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMock( User::class ); + $user = $this->createMock( User::class ); $user->expects( $this->once() ) ->method( 'addWatch' ) ->with( $title, $checkRights ); @@ -99,7 +99,7 @@ class WatchedItemUnitTest extends MediaWikiTestCase { $checkRights = 0; /** @var User|PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMock( User::class ); + $user = $this->createMock( User::class ); $user->expects( $this->once() ) ->method( 'removeWatch' ) ->with( $title, $checkRights ); @@ -124,7 +124,7 @@ class WatchedItemUnitTest extends MediaWikiTestCase { $checkRights = 0; /** @var User|PHPUnit_Framework_MockObject_MockObject $user */ - $user = $this->getMock( User::class ); + $user = $this->createMock( User::class ); $user->expects( $this->once() ) ->method( 'isWatched' ) ->with( $title, $checkRights ) diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php index 922f7f147c..a1b7a87041 100644 --- a/tests/phpunit/includes/api/ApiMainTest.php +++ b/tests/phpunit/includes/api/ApiMainTest.php @@ -472,7 +472,7 @@ class ApiMainTest extends ApiTestCase { ); } - // Not static so $this->getMock() can be used + // Not static so $this can be used public function provideExceptionErrors() { $reqId = WebRequest::getRequestId(); $doclink = wfExpandUrl( wfScript( 'api' ) ); @@ -485,7 +485,9 @@ class ApiMainTest extends ApiTestCase { MWExceptionHandler::getRedactedTraceAsString( $ex ) )->inLanguage( 'en' )->useDatabase( false )->text(); - $dbex = new DBQueryError( $this->getMock( 'IDatabase' ), 'error', 1234, 'SELECT 1', __METHOD__ ); + $dbex = new DBQueryError( + $this->createMock( 'IDatabase' ), + 'error', 1234, 'SELECT 1', __METHOD__ ); $dbtrace = wfMessage( 'api-exception-trace', get_class( $dbex ), $dbex->getFile(), diff --git a/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php index d8588d51d1..8d84f4ca15 100644 --- a/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php @@ -60,7 +60,7 @@ class AbstractPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testProviderRevokeAccessForUser() { $reqs = []; for ( $i = 0; $i < 3; $i++ ) { - $reqs[$i] = $this->getMock( AuthenticationRequest::class ); + $reqs[$i] = $this->createMock( AuthenticationRequest::class ); $reqs[$i]->done = false; } diff --git a/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php index bb90dd9837..41cf62eaa2 100644 --- a/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php @@ -55,7 +55,7 @@ class AbstractSecondaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testProviderRevokeAccessForUser() { $reqs = []; for ( $i = 0; $i < 3; $i++ ) { - $reqs[$i] = $this->getMock( AuthenticationRequest::class ); + $reqs[$i] = $this->createMock( AuthenticationRequest::class ); $reqs[$i]->done = false; } diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index f7be8019b9..5c268f84cf 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -45,7 +45,9 @@ class AuthManagerTest extends \MediaWikiTestCase { */ protected function hook( $hook, $expect ) { global $wgHooks; - $mock = $this->getMock( __CLASS__, [ "on$hook" ] ); + $mock = $this->getMockBuilder( __CLASS__ ) + ->setMethods( [ "on$hook" ] ) + ->getMock(); $wgHooks[$hook] = [ $mock ]; return $mock->expects( $expect )->method( "on$hook" ); } @@ -762,9 +764,9 @@ class AuthManagerTest extends \MediaWikiTestCase { public function testCreateFromLogin() { $user = \User::newFromName( 'UTSysop' ); - $req1 = $this->getMock( AuthenticationRequest::class ); - $req2 = $this->getMock( AuthenticationRequest::class ); - $req3 = $this->getMock( AuthenticationRequest::class ); + $req1 = $this->createMock( AuthenticationRequest::class ); + $req2 = $this->createMock( AuthenticationRequest::class ); + $req3 = $this->createMock( AuthenticationRequest::class ); $userReq = new UsernameAuthenticationRequest; $userReq->username = 'UTDummy'; @@ -2661,7 +2663,8 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails $session->clear(); - $user = $this->getMock( 'User', [ 'addToDatabase' ] ); + $user = $this->getMockBuilder( 'User' ) + ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnValue( \Status::newFatal( 'because' ) ) ); $user->setName( $username ); @@ -2682,7 +2685,8 @@ class AuthManagerTest extends \MediaWikiTestCase { $backoffKey = wfMemcKey( 'AuthManager', 'autocreate-failed', md5( $username ) ); $this->assertFalse( $cache->get( $backoffKey ), 'sanity check' ); $session->clear(); - $user = $this->getMock( 'User', [ 'addToDatabase' ] ); + $user = $this->getMockBuilder( 'User' ) + ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->throwException( new \Exception( 'Excepted' ) ) ); $user->setName( $username ); @@ -2705,7 +2709,8 @@ class AuthManagerTest extends \MediaWikiTestCase { // Test addToDatabase fails because the user already exists. $session->clear(); - $user = $this->getMock( 'User', [ 'addToDatabase' ] ); + $user = $this->getMockBuilder( 'User' ) + ->setMethods( [ 'addToDatabase' ] )->getMock(); $user->expects( $this->once() )->method( 'addToDatabase' ) ->will( $this->returnCallback( function () use ( $username, &$user ) { $oldUser = \User::newFromName( $username ); @@ -2813,7 +2818,7 @@ class AuthManagerTest extends \MediaWikiTestCase { */ public function testGetAuthenticationRequests( $action, $expect, $state = [] ) { $makeReq = function ( $key ) use ( $action ) { - $req = $this->getMock( AuthenticationRequest::class ); + $req = $this->createMock( AuthenticationRequest::class ); $req->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); $req->action = $action === AuthManager::ACTION_UNLINK ? AuthManager::ACTION_REMOVE : $action; @@ -3016,7 +3021,7 @@ class AuthManagerTest extends \MediaWikiTestCase { public function testGetAuthenticationRequestsRequired() { $makeReq = function ( $key, $required ) { - $req = $this->getMock( AuthenticationRequest::class ); + $req = $this->createMock( AuthenticationRequest::class ); $req->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); $req->action = AuthManager::ACTION_LOGIN; @@ -3146,7 +3151,7 @@ class AuthManagerTest extends \MediaWikiTestCase { public function testAutoCreateOnLogin() { $username = self::usernameForCreation(); - $req = $this->getMock( AuthenticationRequest::class ); + $req = $this->createMock( AuthenticationRequest::class ); $mock = $this->getMockForAbstractClass( PrimaryAuthenticationProvider::class ); $mock->expects( $this->any() )->method( 'getUniqueId' )->will( $this->returnValue( 'primary' ) ); diff --git a/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php index 96e50e07ac..6970313498 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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); @@ -29,14 +29,14 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $provider->getAuthenticationRequests( AuthManager::ACTION_LOGIN, [] ) ); - $req = $this->getMock( PasswordAuthenticationRequest::class ); + $req = $this->createMock( PasswordAuthenticationRequest::class ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin, get_class( $req ) ); $this->assertEquals( [ $req ], $provider->getAuthenticationRequests( AuthManager::ACTION_LOGIN, [] ) ); - $reqType = get_class( $this->getMock( AuthenticationRequest::class ) ); + $reqType = get_class( $this->createMock( AuthenticationRequest::class ) ); try { $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin, $reqType ); $this->fail( 'Expected exception not thrown' ); @@ -51,7 +51,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { public function testOnUserSaveSettings() { $user = \User::newFromName( 'UTSysop' ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->any() )->method( 'allowPasswordChange' ) ->will( $this->returnValue( $allowPasswordChange ) ); @@ -321,7 +321,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testTestUserExists() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -355,7 +355,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( true ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -375,7 +375,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { ->getMock(); $pluginUser->expects( $this->once() )->method( 'isLocked' ) ->will( $this->returnValue( false ) ); - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->once() )->method( 'userExists' ) ->with( $this->equalTo( 'Foo' ) ) @@ -433,7 +433,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderAllowsPropertyChange() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( $domains ); $plugin->expects( $allow === null ? $this->never() : $this->once() ) ->method( 'allowPasswordChange' )->will( $this->returnValue( $allow ) ); @@ -466,7 +466,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { if ( is_object( $type ) ) { $req = $type; } else { - $req = $this->getMock( $type ); + $req = $this->createMock( $type ); } $req->action = AuthManager::ACTION_CHANGE; $req->username = 'UTSysop'; @@ -502,12 +502,12 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { } public function testProviderChangeAuthenticationData() { - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] ); $plugin->expects( $this->never() )->method( 'setPassword' ); $provider = new AuthPluginPrimaryAuthenticationProvider( $plugin ); $provider->providerChangeAuthenticationData( - $this->getMock( AuthenticationRequest::class ) + $this->createMock( AuthenticationRequest::class ) ); $req = new PasswordAuthenticationRequest(); @@ -515,7 +515,7 @@ class AuthPluginPrimaryAuthenticationProviderTest extends \MediaWikiTestCase { $req->username = 'foo'; $req->password = 'bar'; - $plugin = $this->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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->getMock( 'AuthPlugin' ); + $plugin = $this->createMock( 'AuthPlugin' ); $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 7d2ba8d749..0e549a5ca6 100644 --- a/tests/phpunit/includes/auth/AuthenticationRequestTest.php +++ b/tests/phpunit/includes/auth/AuthenticationRequestTest.php @@ -138,7 +138,7 @@ class AuthenticationRequestTest extends \MediaWikiTestCase { public function testMergeFieldInfo() { $msg = wfMessage( 'foo' ); - $req1 = $this->getMock( AuthenticationRequest::class ); + $req1 = $this->createMock( AuthenticationRequest::class ); $req1->required = AuthenticationRequest::REQUIRED; $req1->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [ 'string1' => [ @@ -165,7 +165,7 @@ class AuthenticationRequestTest extends \MediaWikiTestCase { ], ] ) ); - $req2 = $this->getMock( AuthenticationRequest::class ); + $req2 = $this->createMock( AuthenticationRequest::class ); $req2->required = AuthenticationRequest::REQUIRED; $req2->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [ 'string1' => [ @@ -187,7 +187,7 @@ class AuthenticationRequestTest extends \MediaWikiTestCase { ], ] ) ); - $req3 = $this->getMock( AuthenticationRequest::class ); + $req3 = $this->createMock( AuthenticationRequest::class ); $req3->required = AuthenticationRequest::REQUIRED; $req3->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [ 'string1' => [ @@ -197,7 +197,7 @@ class AuthenticationRequestTest extends \MediaWikiTestCase { ], ] ) ); - $req4 = $this->getMock( AuthenticationRequest::class ); + $req4 = $this->createMock( AuthenticationRequest::class ); $req4->required = AuthenticationRequest::REQUIRED; $req4->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [] ) ); diff --git a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php index ec4bea11a1..ca6689a9ca 100644 --- a/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php @@ -57,24 +57,24 @@ class EmailNotificationSecondaryAuthenticationProviderTest extends \PHPUnit_Fram public function testBeginSecondaryAccountCreation() { $authManager = new AuthManager( new \FauxRequest(), new \HashConfig() ); - $creator = $this->getMock( 'User' ); - $userWithoutEmail = $this->getMock( 'User' ); + $creator = $this->getMockBuilder( 'User' )->getMock(); + $userWithoutEmail = $this->getMockBuilder( 'User' )->getMock(); $userWithoutEmail->expects( $this->any() )->method( 'getEmail' )->willReturn( '' ); $userWithoutEmail->expects( $this->any() )->method( 'getInstanceForUpdate' )->willReturnSelf(); $userWithoutEmail->expects( $this->never() )->method( 'sendConfirmationMail' ); - $userWithEmailError = $this->getMock( 'User' ); + $userWithEmailError = $this->getMockBuilder( 'User' )->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->getMock( 'User' ); + $userExpectsConfirmation = $this->getMockBuilder( 'User' )->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->getMock( 'User' ); + $userNotExpectsConfirmation = $this->getMockBuilder( 'User' )->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 b96455e091..3b0019499d 100644 --- a/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php @@ -15,7 +15,8 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { * @return LegacyHookPreAuthenticationProvider */ protected function getProvider() { - $request = $this->getMock( 'FauxRequest', [ 'getIP' ] ); + $request = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' )->will( $this->returnValue( '127.0.0.42' ) ); $manager = new AuthManager( @@ -39,7 +40,7 @@ class LegacyHookPreAuthenticationProviderTest extends \MediaWikiTestCase { * @return object $mock->expects( $expect )->method( ... ). */ protected function hook( $hook, $expect ) { - $mock = $this->getMock( __CLASS__, [ "on$hook" ] ); + $mock = $this->getMockBuilder( __CLASS__ )->setMethods( [ "on$hook" ] )->getMock(); $this->mergeMwGlobalArrayValue( 'wgHooks', [ $hook => [ $mock ], ] ); diff --git a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php index 72a03c311a..6e2058c485 100644 --- a/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php @@ -38,11 +38,10 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCase } $this->validity = \Status::newGood(); - $provider = $this->getMock( - LocalPasswordPrimaryAuthenticationProvider::class, - [ 'checkPasswordValidity' ], - [ [ 'loginOnly' => $loginOnly ] ] - ); + $provider = $this->getMockBuilder( LocalPasswordPrimaryAuthenticationProvider::class ) + ->setMethods( [ 'checkPasswordValidity' ] ) + ->setConstructorArgs( [ [ 'loginOnly' => $loginOnly ] ] ) + ->getMock(); $provider->expects( $this->any() )->method( 'checkPasswordValidity' ) ->will( $this->returnCallback( function () { return $this->validity; @@ -348,7 +347,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCase } elseif ( $type === PasswordDomainAuthenticationRequest::class ) { $req = new $type( [] ); } else { - $req = $this->getMock( $type ); + $req = $this->createMock( $type ); } $req->action = AuthManager::ACTION_CHANGE; $req->username = $user; @@ -444,7 +443,7 @@ class LocalPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestCase if ( $type === PasswordAuthenticationRequest::class ) { $changeReq = new $type(); } else { - $changeReq = $this->getMock( $type ); + $changeReq = $this->createMock( $type ); } $changeReq->action = AuthManager::ACTION_CHANGE; $changeReq->username = $user; diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php index bc7d65e81d..8d9509e9a1 100644 --- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php @@ -42,11 +42,10 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC $this->validity = \Status::newGood(); $mockedMethods[] = 'checkPasswordValidity'; - $provider = $this->getMock( - TemporaryPasswordPrimaryAuthenticationProvider::class, - $mockedMethods, - [ $params ] - ); + $provider = $this->getMockBuilder( TemporaryPasswordPrimaryAuthenticationProvider::class ) + ->setMethods( $mockedMethods ) + ->setConstructorArgs( [ $params ] ) + ->getMock(); $provider->expects( $this->any() )->method( 'checkPasswordValidity' ) ->will( $this->returnCallback( function () { return $this->validity; @@ -366,7 +365,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC ) { $req = new $type(); } else { - $req = $this->getMock( $type ); + $req = $this->createMock( $type ); } $req->action = AuthManager::ACTION_CHANGE; $req->username = $user; @@ -446,7 +445,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends \MediaWikiTestC ) { $changeReq = new $type(); } else { - $changeReq = $this->getMock( $type ); + $changeReq = $this->createMock( $type ); } $changeReq->action = AuthManager::ACTION_CHANGE; $changeReq->username = $user; diff --git a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php index 2f3e27c6fe..ee8283288a 100644 --- a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php @@ -119,7 +119,9 @@ class ThrottlePreAuthenticationProviderTest extends \MediaWikiTestCase { $user = \User::newFromName( 'RandomUser' ); $creator = \User::newFromName( $creatorname ); if ( $hook ) { - $mock = $this->getMock( 'stdClass', [ 'onExemptFromAccountCreationThrottle' ] ); + $mock = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'onExemptFromAccountCreationThrottle' ] ) + ->getMock(); $mock->expects( $this->any() )->method( 'onExemptFromAccountCreationThrottle' ) ->will( $this->returnValue( false ) ); $this->mergeMwGlobalArrayValue( 'wgHooks', [ diff --git a/tests/phpunit/includes/auth/ThrottlerTest.php b/tests/phpunit/includes/auth/ThrottlerTest.php index c945885c76..33c8ce6e10 100644 --- a/tests/phpunit/includes/auth/ThrottlerTest.php +++ b/tests/phpunit/includes/auth/ThrottlerTest.php @@ -163,7 +163,8 @@ class ThrottlerTest extends \MediaWikiTestCase { } public function testExpiration() { - $cache = $this->getMock( HashBagOStuff::class, [ 'add' ] ); + $cache = $this->getMockBuilder( HashBagOStuff::class ) + ->setMethods( [ 'add' ] )->getMock(); $throttler = new Throttler( [ [ 'count' => 3, 'seconds' => 10 ] ], [ 'cache' => $cache ] ); $throttler->setLogger( new NullLogger() ); diff --git a/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php b/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php index dc868a89b6..0f556b8ff1 100644 --- a/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php +++ b/tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php @@ -183,8 +183,8 @@ class ChangesListStringOptionsFilterGroupTest extends MediaWikiTestCase { * @dataProvider provideModifyQuery */ protected function modifyQueryHelper( $groupDefinition, $input ) { - $ctx = $this->getMock( 'IContextSource' ); - $dbr = $this->getMock( 'IDatabase' ); + $ctx = $this->createMock( 'IContextSource' ); + $dbr = $this->createMock( 'IDatabase' ); $tables = $fields = $conds = $query_options = $join_conds = []; $group = new ChangesListStringOptionsFilterGroup( $groupDefinition ); diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index a3d1ddac31..403bee17b1 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -429,7 +429,7 @@ class ContentHandlerTest extends MediaWikiTestCase { * @covers ContentHandler::getDataForSearchIndex */ public function testDataIndexFields() { - $mockEngine = $this->getMock( 'SearchEngine' ); + $mockEngine = $this->createMock( 'SearchEngine' ); $title = Title::newFromText( 'Not_Main_Page', NS_MAIN ); $page = new WikiPage( $title ); diff --git a/tests/phpunit/includes/content/FileContentHandlerTest.php b/tests/phpunit/includes/content/FileContentHandlerTest.php index 276a86ee5e..65efcc9e80 100644 --- a/tests/phpunit/includes/content/FileContentHandlerTest.php +++ b/tests/phpunit/includes/content/FileContentHandlerTest.php @@ -16,7 +16,7 @@ class FileContentHandlerTest extends MediaWikiLangTestCase { } public function testIndexMapping() { - $mockEngine = $this->getMock( 'SearchEngine' ); + $mockEngine = $this->createMock( 'SearchEngine' ); $mockEngine->expects( $this->atLeastOnce() ) ->method( 'makeSearchFieldMapping' ) diff --git a/tests/phpunit/includes/content/TextContentHandlerTest.php b/tests/phpunit/includes/content/TextContentHandlerTest.php index 918815ca05..7d9f74eca0 100644 --- a/tests/phpunit/includes/content/TextContentHandlerTest.php +++ b/tests/phpunit/includes/content/TextContentHandlerTest.php @@ -16,7 +16,7 @@ class TextContentHandlerTest extends MediaWikiLangTestCase { public function testFieldsForIndex() { $handler = new TextContentHandler(); - $mockEngine = $this->getMock( 'SearchEngine' ); + $mockEngine = $this->createMock( 'SearchEngine' ); $mockEngine->expects( $this->atLeastOnce() ) ->method( 'makeSearchFieldMapping' ) diff --git a/tests/phpunit/includes/content/WikitextContentHandlerTest.php b/tests/phpunit/includes/content/WikitextContentHandlerTest.php index ec97d76371..290b11ab00 100644 --- a/tests/phpunit/includes/content/WikitextContentHandlerTest.php +++ b/tests/phpunit/includes/content/WikitextContentHandlerTest.php @@ -245,7 +245,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase { */ public function testDataIndexFieldsFile() { - $mockEngine = $this->getMock( 'SearchEngine' ); + $mockEngine = $this->createMock( 'SearchEngine' ); $title = Title::newFromText( 'Somefile.jpg', NS_FILE ); $page = new WikiPage( $title ); diff --git a/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php b/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php index d6249bba46..ce21412000 100644 --- a/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php +++ b/tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php @@ -160,7 +160,7 @@ class KafkaHandlerTest extends MediaWikiTestCase { [ $this->anything(), $this->anything(), [ 'lines' ] ] ] ); - $formatter = $this->getMock( 'Monolog\Formatter\FormatterInterface' ); + $formatter = $this->createMock( 'Monolog\Formatter\FormatterInterface' ); $formatter->expects( $this->any() ) ->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); @@ -191,7 +191,7 @@ class KafkaHandlerTest extends MediaWikiTestCase { ->method( 'send' ) ->will( $this->returnValue( true ) ); - $formatter = $this->getMock( 'Monolog\Formatter\FormatterInterface' ); + $formatter = $this->createMock( 'Monolog\Formatter\FormatterInterface' ); $formatter->expects( $this->any() ) ->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); diff --git a/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php b/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php index 6c93c79a4a..0d00fbc284 100644 --- a/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php +++ b/tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php @@ -117,20 +117,21 @@ class FileBackendDBRepoWrapperTest extends MediaWikiTestCase { ->disableOriginalConstructor() ->getMock(); - $backendMock = $this->getMock( 'FSFileBackend', - [], - [ [ - 'name' => $this->backendName, - 'wikiId' => wfWikiID() - ] ] ); - - $wrapperMock = $this->getMock( 'FileBackendDBRepoWrapper', - [ 'getDB' ], - [ [ - 'backend' => $backendMock, - 'repoName' => $this->repoName, - 'dbHandleFactory' => null - ] ] ); + $backendMock = $this->getMockBuilder( 'FSFileBackend' ) + ->setConstructorArgs( [ [ + 'name' => $this->backendName, + 'wikiId' => wfWikiID() + ] ] ) + ->getMock(); + + $wrapperMock = $this->getMockBuilder( 'FileBackendDBRepoWrapper' ) + ->setMethods( [ 'getDB' ] ) + ->setConstructorArgs( [ [ + 'backend' => $backendMock, + 'repoName' => $this->repoName, + 'dbHandleFactory' => null + ] ] ) + ->getMock(); $wrapperMock->expects( $this->any() )->method( 'getDB' )->will( $this->returnValue( $dbMock ) ); diff --git a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php index d3f9374c53..800c2fc76e 100644 --- a/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php +++ b/tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php @@ -41,19 +41,21 @@ class MigrateFileRepoLayoutTest extends MediaWikiTestCase { new FakeResultWrapper( [] ) // filearchive ) ); - $repoMock = $this->getMock( 'LocalRepo', - [ 'getMasterDB' ], - [ [ - 'name' => 'migratefilerepolayouttest', - 'backend' => $backend - ] ] ); + $repoMock = $this->getMockBuilder( 'LocalRepo' ) + ->setMethods( [ 'getMasterDB' ] ) + ->setConstructorArgs( [ [ + 'name' => 'migratefilerepolayouttest', + 'backend' => $backend + ] ] ) + ->getMock(); $repoMock ->expects( $this->any() ) ->method( 'getMasterDB' ) ->will( $this->returnValue( $dbMock ) ); - $this->migratorMock = $this->getMock( 'MigrateFileRepoLayout', [ 'getRepo' ] ); + $this->migratorMock = $this->getMockBuilder( 'MigrateFileRepoLayout' ) + ->setMethods( [ 'getRepo' ] )->getMock(); $this->migratorMock ->expects( $this->any() ) ->method( 'getRepo' ) diff --git a/tests/phpunit/includes/filerepo/RepoGroupTest.php b/tests/phpunit/includes/filerepo/RepoGroupTest.php index 25c6e9520d..82ff12e3e3 100644 --- a/tests/phpunit/includes/filerepo/RepoGroupTest.php +++ b/tests/phpunit/includes/filerepo/RepoGroupTest.php @@ -15,7 +15,7 @@ class RepoGroupTest extends MediaWikiTestCase { function testForEachForeignRepo() { $this->setUpForeignRepo(); - $fakeCallback = $this->getMock( 'RepoGroupTestHelper' ); + $fakeCallback = $this->createMock( 'RepoGroupTestHelper' ); $fakeCallback->expects( $this->once() )->method( 'callback' ); RepoGroup::singleton()->forEachForeignRepo( [ $fakeCallback, 'callback' ], [ [] ] ); @@ -25,7 +25,7 @@ class RepoGroupTest extends MediaWikiTestCase { $this->setMwGlobals( 'wgForeignFileRepos', [] ); RepoGroup::destroySingleton(); FileBackendGroup::destroySingleton(); - $fakeCallback = $this->getMock( 'RepoGroupTestHelper' ); + $fakeCallback = $this->createMock( 'RepoGroupTestHelper' ); $fakeCallback->expects( $this->never() )->method( 'callback' ); RepoGroup::singleton()->forEachForeignRepo( [ $fakeCallback, 'callback' ], [ [] ] ); diff --git a/tests/phpunit/includes/filerepo/file/FileTest.php b/tests/phpunit/includes/filerepo/file/FileTest.php index 6520610786..5b5f1b09fe 100644 --- a/tests/phpunit/includes/filerepo/file/FileTest.php +++ b/tests/phpunit/includes/filerepo/file/FileTest.php @@ -155,7 +155,8 @@ class FileTest extends MediaWikiMediaTestCase { ->method( 'getLocalReference' ) ->will( $this->returnValue( $fsFile ) ); - $handlerMock = $this->getMock( 'BitmapHandler', [ 'supportsBucketing' ] ); + $handlerMock = $this->getMockBuilder( 'BitmapHandler' ) + ->setMethods( [ 'supportsBucketing' ] )->getMock(); $handlerMock->expects( $this->any() ) ->method( 'supportsBucketing' ) ->will( $this->returnValue( $data['supportsBucketing'] ) ); @@ -261,7 +262,8 @@ class FileTest extends MediaWikiMediaTestCase { 'generateAndSaveThumb', 'getHandler' ] ) ->getMockForAbstractClass(); - $handlerMock = $this->getMock( 'JpegHandler', [ 'supportsBucketing' ] ); + $handlerMock = $this->getMockBuilder( 'JpegHandler' ) + ->setMethods( [ 'supportsBucketing' ] )->getMock(); $handlerMock->expects( $this->any() ) ->method( 'supportsBucketing' ) ->will( $this->returnValue( true ) ); diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php index 600a36ffe4..1deb7aa35d 100644 --- a/tests/phpunit/includes/jobqueue/JobTest.php +++ b/tests/phpunit/includes/jobqueue/JobTest.php @@ -18,7 +18,8 @@ class JobTest extends MediaWikiTestCase { } public function provideTestToString() { - $mockToStringObj = $this->getMock( 'stdClass', [ '__toString' ] ); + $mockToStringObj = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ '__toString' ] )->getMock(); $mockToStringObj->expects( $this->any() ) ->method( '__toString' ) ->will( $this->returnValue( '{STRING_OBJ_VAL}' ) ); diff --git a/tests/phpunit/includes/libs/MemoizedCallableTest.php b/tests/phpunit/includes/libs/MemoizedCallableTest.php index 881f5e1167..d99c58781c 100644 --- a/tests/phpunit/includes/libs/MemoizedCallableTest.php +++ b/tests/phpunit/includes/libs/MemoizedCallableTest.php @@ -31,7 +31,8 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { * way as the original underlying callable. */ public function testReturnValuePassedThrough() { - $mock = $this->getMock( 'stdClass', [ 'reverse' ] ); + $mock = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'reverse' ] )->getMock(); $mock->expects( $this->any() ) ->method( 'reverse' ) ->will( $this->returnCallback( 'strrev' ) ); @@ -47,7 +48,8 @@ class MemoizedCallableTest extends PHPUnit_Framework_TestCase { * @requires function apc_store/apcu_store */ public function testCallableMemoized() { - $observer = $this->getMock( 'stdClass', [ 'computeSomething' ] ); + $observer = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'computeSomething' ] )->getMock(); $observer->expects( $this->once() ) ->method( 'computeSomething' ) ->will( $this->returnValue( 'ok' ) ); diff --git a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php index 9a489303a7..c5bc03ea5d 100644 --- a/tests/phpunit/includes/libs/SamplingStatsdClientTest.php +++ b/tests/phpunit/includes/libs/SamplingStatsdClientTest.php @@ -1,13 +1,14 @@ getMock( 'Liuggio\StatsdClient\Sender\SenderInterface' ); + $sender = $this->getMockBuilder( SenderInterface::class )->getMock(); $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) ); if ( $expectWrite ) { $sender->expects( $this->once() )->method( 'write' ) @@ -50,7 +51,7 @@ class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase { $nonMatching->setKey( 'oof.bar' ); $nonMatching->setValue( 1 ); - $sender = $this->getMock( 'Liuggio\StatsdClient\Sender\SenderInterface' ); + $sender = $this->getMockBuilder( SenderInterface::class )->getMock(); $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) ); $sender->expects( $this->once() )->method( 'write' )->with( $this->anything(), $this->equalTo( $nonMatching ) ); diff --git a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php index a1afa77726..f2fe07de40 100644 --- a/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/BagOStuffTest.php @@ -275,7 +275,7 @@ class BagOStuffTest extends MediaWikiTestCase { * @covers BagOStuff::trackDuplicateKeys */ public function testReportDupes() { - $logger = $this->getMock( 'Psr\Log\NullLogger' ); + $logger = $this->createMock( Psr\Log\NullLogger::class ); $logger->expects( $this->once() ) ->method( 'warning' ) ->with( 'Duplicate get(): "{key}" fetched {count} times', [ diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index d7ed4bd9ce..18729f0723 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -963,7 +963,8 @@ class WANObjectCacheTest extends PHPUnit_Framework_TestCase { } public function testMcRouterSupport() { - $localBag = $this->getMock( 'EmptyBagOStuff', [ 'set', 'delete' ] ); + $localBag = $this->getMockBuilder( 'EmptyBagOStuff' ) + ->setMethods( [ 'set', 'delete' ] )->getMock(); $localBag->expects( $this->never() )->method( 'set' ); $localBag->expects( $this->never() )->method( 'delete' ); $wanCache = new WANObjectCache( [ diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php index cd350e5ccf..a3f3981037 100644 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php @@ -19,7 +19,8 @@ class ConnectionManagerTest extends \PHPUnit_Framework_TestCase { * @return IDatabase|PHPUnit_Framework_MockObject_MockObject */ private function getIDatabaseMock() { - return $this->getMock( IDatabase::class ); + return $this->getMockBuilder( IDatabase::class ) + ->getMock(); } /** diff --git a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php index 3b26d6f90a..4e76f2a839 100644 --- a/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php +++ b/tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php @@ -19,7 +19,8 @@ class SessionConsistentConnectionManagerTest extends \PHPUnit_Framework_TestCase * @return IDatabase|PHPUnit_Framework_MockObject_MockObject */ private function getIDatabaseMock() { - return $this->getMock( IDatabase::class ); + return $this->getMockBuilder( IDatabase::class ) + ->getMock(); } /** diff --git a/tests/phpunit/includes/linker/LinkRendererFactoryTest.php b/tests/phpunit/includes/linker/LinkRendererFactoryTest.php index bf12f80f0a..27e5a657ed 100644 --- a/tests/phpunit/includes/linker/LinkRendererFactoryTest.php +++ b/tests/phpunit/includes/linker/LinkRendererFactoryTest.php @@ -69,7 +69,8 @@ class LinkRendererFactoryTest extends MediaWikiLangTestCase { public function testCreateForUser() { /** @var PHPUnit_Framework_MockObject_MockObject|User $user */ - $user = $this->getMock( User::class, [ 'getStubThreshold' ] ); + $user = $this->getMockBuilder( User::class ) + ->setMethods( [ 'getStubThreshold' ] )->getMock(); $user->expects( $this->once() ) ->method( 'getStubThreshold' ) ->willReturn( 15 ); diff --git a/tests/phpunit/includes/mail/MailAddressTest.php b/tests/phpunit/includes/mail/MailAddressTest.php index 39b6f9f8f4..c837d26f5b 100644 --- a/tests/phpunit/includes/mail/MailAddressTest.php +++ b/tests/phpunit/includes/mail/MailAddressTest.php @@ -17,7 +17,7 @@ class MailAddressTest extends MediaWikiTestCase { if ( wfIsWindows() ) { $this->markTestSkipped( 'This test only works on non-Windows platforms' ); } - $user = $this->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() )->method( 'getName' )->will( $this->returnValue( 'UserName' ) ); diff --git a/tests/phpunit/includes/search/SearchEngineTest.php b/tests/phpunit/includes/search/SearchEngineTest.php index 3fb4bbbb1f..c74c893901 100644 --- a/tests/phpunit/includes/search/SearchEngineTest.php +++ b/tests/phpunit/includes/search/SearchEngineTest.php @@ -164,7 +164,8 @@ class SearchEngineTest extends MediaWikiLangTestCase { /** * @var $mockEngine SearchEngine */ - $mockEngine = $this->getMock( 'SearchEngine', [ 'makeSearchFieldMapping' ] ); + $mockEngine = $this->getMockBuilder( 'SearchEngine' ) + ->setMethods( [ 'makeSearchFieldMapping' ] )->getMock(); $mockFieldBuilder = function ( $name, $type ) { $mockField = @@ -230,7 +231,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { } public function addAugmentors( &$setAugmentors, &$rowAugmentors ) { - $setAugmentor = $this->getMock( 'ResultSetAugmentor' ); + $setAugmentor = $this->createMock( 'ResultSetAugmentor' ); $setAugmentor->expects( $this->once() ) ->method( 'augmentAll' ) ->willReturnCallback( function ( SearchResultSet $resultSet ) { @@ -244,7 +245,7 @@ class SearchEngineTest extends MediaWikiLangTestCase { } ); $setAugmentors['testSet'] = $setAugmentor; - $rowAugmentor = $this->getMock( 'ResultAugmentor' ); + $rowAugmentor = $this->createMock( 'ResultAugmentor' ); $rowAugmentor->expects( $this->exactly( 2 ) ) ->method( 'augment' ) ->willReturnCallback( function ( SearchResult $result ) { diff --git a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php index c1eef2e809..1ea27f3f8e 100644 --- a/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php +++ b/tests/phpunit/includes/session/BotPasswordSessionProviderTest.php @@ -183,7 +183,8 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { public function testNewSessionInfoForRequest() { $provider = $this->getProvider(); $user = static::getTestSysop()->getUser(); - $request = $this->getMock( 'FauxRequest', [ 'getIP' ] ); + $request = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '127.0.0.1' ) ); $bp = \BotPassword::newFromUser( $user, 'BotPasswordSessionProvider' ); @@ -210,7 +211,8 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { $provider->setLogger( $logger ); $user = static::getTestSysop()->getUser(); - $request = $this->getMock( 'FauxRequest', [ 'getIP' ] ); + $request = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'getIP' ] )->getMock(); $request->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '127.0.0.1' ) ); $bp = \BotPassword::newFromUser( $user, 'BotPasswordSessionProvider' ); @@ -261,7 +263,8 @@ class BotPasswordSessionProviderTest extends MediaWikiTestCase { ], $logger->getBuffer() ); $logger->clearBuffer(); - $request2 = $this->getMock( 'FauxRequest', [ 'getIP' ] ); + $request2 = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'getIP' ] )->getMock(); $request2->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '10.0.0.1' ) ); $data['metadata'] = $dataMD; diff --git a/tests/phpunit/includes/session/CookieSessionProviderTest.php b/tests/phpunit/includes/session/CookieSessionProviderTest.php index da4b06ec83..73485c828c 100644 --- a/tests/phpunit/includes/session/CookieSessionProviderTest.php +++ b/tests/phpunit/includes/session/CookieSessionProviderTest.php @@ -414,7 +414,9 @@ class CookieSessionProviderTest extends MediaWikiTestCase { ); \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; - $mock = $this->getMock( 'stdClass', [ 'onUserSetCookies' ] ); + $mock = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'onUserSetCookies' ] ) + ->getMock(); $mock->expects( $this->never() )->method( 'onUserSetCookies' ); $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] ); @@ -560,13 +562,15 @@ class CookieSessionProviderTest extends MediaWikiTestCase { } protected function getSentRequest() { - $sentResponse = $this->getMock( 'FauxResponse', [ 'headersSent', 'setCookie', 'header' ] ); + $sentResponse = $this->getMockBuilder( 'FauxResponse' ) + ->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->getMock( 'FauxRequest', [ 'response' ] ); + $sentRequest = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'response' ] )->getMock(); $sentRequest->expects( $this->any() )->method( 'response' ) ->will( $this->returnValue( $sentResponse ) ); return $sentRequest; @@ -603,7 +607,8 @@ class CookieSessionProviderTest extends MediaWikiTestCase { \TestingAccessWrapper::newFromObject( $backend )->usePhpSessionHandling = false; // Anonymous user - $mock = $this->getMock( 'stdClass', [ 'onUserSetCookies' ] ); + $mock = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'onUserSetCookies' ] )->getMock(); $mock->expects( $this->never() )->method( 'onUserSetCookies' ); $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserSetCookies' => [ $mock ] ] ); $backend->setUser( $anon ); @@ -621,7 +626,8 @@ class CookieSessionProviderTest extends MediaWikiTestCase { $provider->persistSession( $backend, $this->getSentRequest() ); // Logged-in user, no remember - $mock = $this->getMock( __CLASS__, [ 'onUserSetCookies' ] ); + $mock = $this->getMockBuilder( __CLASS__ ) + ->setMethods( [ 'onUserSetCookies' ] )->getMock(); $mock->expects( $this->once() )->method( 'onUserSetCookies' ) ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) { $this->assertSame( $user, $u ); @@ -664,7 +670,8 @@ class CookieSessionProviderTest extends MediaWikiTestCase { $provider->persistSession( $backend, $this->getSentRequest() ); // Logged-in user, remember - $mock = $this->getMock( __CLASS__, [ 'onUserSetCookies' ] ); + $mock = $this->getMockBuilder( __CLASS__ ) + ->setMethods( [ 'onUserSetCookies' ] )->getMock(); $mock->expects( $this->once() )->method( 'onUserSetCookies' ) ->will( $this->returnCallback( function ( $u, &$sessionData, &$cookies ) use ( $user ) { $this->assertSame( $user, $u ); diff --git a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php index 78edb7671e..7ef230e269 100644 --- a/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php +++ b/tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php @@ -157,13 +157,16 @@ class ImmutableSessionProviderWithCookieTest extends MediaWikiTestCase { } protected function getSentRequest() { - $sentResponse = $this->getMock( 'FauxResponse', [ 'headersSent', 'setCookie', 'header' ] ); + $sentResponse = $this->getMockBuilder( 'FauxResponse' ) + ->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->getMock( 'FauxRequest', [ 'response' ] ); + $sentRequest = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'response' ] )->getMock(); $sentRequest->expects( $this->any() )->method( 'response' ) ->will( $this->returnValue( $sentResponse ) ); return $sentRequest; diff --git a/tests/phpunit/includes/session/SessionBackendTest.php b/tests/phpunit/includes/session/SessionBackendTest.php index 8a0adbad76..4a28f7ae1d 100644 --- a/tests/phpunit/includes/session/SessionBackendTest.php +++ b/tests/phpunit/includes/session/SessionBackendTest.php @@ -293,7 +293,8 @@ class SessionBackendTest extends MediaWikiTestCase { } public function testPersist() { - $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->once() )->method( 'persistSession' ); $backend = $this->getBackend(); $this->assertFalse( $backend->isPersistent(), 'sanity check' ); @@ -312,7 +313,8 @@ class SessionBackendTest extends MediaWikiTestCase { } public function testUnpersist() { - $this->provider = $this->getMock( 'DummySessionProvider', [ 'unpersistSession' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'unpersistSession' ] )->getMock(); $this->provider->expects( $this->once() )->method( 'unpersistSession' ); $backend = $this->getBackend(); $wrap = \TestingAccessWrapper::newFromObject( $backend ); @@ -362,7 +364,8 @@ class SessionBackendTest extends MediaWikiTestCase { public function testSetUser() { $user = static::getTestSysop()->getUser(); - $this->provider = $this->getMock( 'DummySessionProvider', [ 'canChangeUser' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'canChangeUser' ] )->getMock(); $this->provider->expects( $this->any() )->method( 'canChangeUser' ) ->will( $this->returnValue( false ) ); $backend = $this->getBackend(); @@ -488,7 +491,8 @@ class SessionBackendTest extends MediaWikiTestCase { $this->store = new TestBagOStuff(); $testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ]; - $neverHook = $this->getMock( __CLASS__, [ 'onSessionMetadata' ] ); + $neverHook = $this->getMockBuilder( __CLASS__ ) + ->setMethods( [ 'onSessionMetadata' ] )->getMock(); $neverHook->expects( $this->never() )->method( 'onSessionMetadata' ); $builder = $this->getMockBuilder( 'DummySessionProvider' ) @@ -694,7 +698,8 @@ class SessionBackendTest extends MediaWikiTestCase { // Bad hook $this->provider = null; - $mockHook = $this->getMock( __CLASS__, [ 'onSessionMetadata' ] ); + $mockHook = $this->getMockBuilder( __CLASS__ ) + ->setMethods( [ 'onSessionMetadata' ] )->getMock(); $mockHook->expects( $this->any() )->method( 'onSessionMetadata' ) ->will( $this->returnCallback( function ( SessionBackend $backend, array &$metadata, array $requests ) { @@ -738,7 +743,8 @@ class SessionBackendTest extends MediaWikiTestCase { $testData = [ 'foo' => 'foo!', 'bar', [ 'baz', null ] ]; // Not persistent - $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->never() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] ); @@ -763,7 +769,8 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertNotEquals( 0, $wrap->expires ); // Persistent - $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->atLeastOnce() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] ); @@ -789,7 +796,8 @@ class SessionBackendTest extends MediaWikiTestCase { $this->assertNotEquals( 0, $wrap->expires ); // Not persistent, not expiring - $this->provider = $this->getMock( 'DummySessionProvider', [ 'persistSession' ] ); + $this->provider = $this->getMockBuilder( 'DummySessionProvider' ) + ->setMethods( [ 'persistSession' ] )->getMock(); $this->provider->expects( $this->never() )->method( 'persistSession' ); $this->onSessionMetadataCalled = false; $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'SessionMetadata' => [ $this ] ] ); diff --git a/tests/phpunit/includes/session/SessionManagerTest.php b/tests/phpunit/includes/session/SessionManagerTest.php index 48a72d3415..c4b1072cda 100644 --- a/tests/phpunit/includes/session/SessionManagerTest.php +++ b/tests/phpunit/includes/session/SessionManagerTest.php @@ -779,7 +779,8 @@ class SessionManagerTest extends MediaWikiTestCase { $manager = \TestingAccessWrapper::newFromObject( $this->getManager() ); $manager->setLogger( new \Psr\Log\NullLogger() ); - $mock = $this->getMock( 'stdClass', [ 'shutdown' ] ); + $mock = $this->getMockBuilder( 'stdClass' ) + ->setMethods( [ 'shutdown' ] )->getMock(); $mock->expects( $this->once() )->method( 'shutdown' ); $manager->allSessionBackends = [ $mock ]; diff --git a/tests/phpunit/includes/session/SessionTest.php b/tests/phpunit/includes/session/SessionTest.php index e6a6ad351f..f6c88ecf08 100644 --- a/tests/phpunit/includes/session/SessionTest.php +++ b/tests/phpunit/includes/session/SessionTest.php @@ -37,8 +37,9 @@ class SessionTest extends MediaWikiTestCase { * @param bool $ret Whether the method returns a value */ public function testMethods( $m, $args, $index, $ret ) { - $mock = $this->getMock( DummySessionBackend::class, - [ $m, 'deregisterSession' ] ); + $mock = $this->getMockBuilder( DummySessionBackend::class ) + ->setMethods( [ $m, 'deregisterSession' ] ) + ->getMock(); $mock->expects( $this->once() )->method( 'deregisterSession' ) ->with( $this->identicalTo( 42 ) ); @@ -223,9 +224,9 @@ class SessionTest extends MediaWikiTestCase { $session = TestUtils::getDummySession(); $priv = \TestingAccessWrapper::newFromObject( $session ); - $backend = $this->getMock( - DummySessionBackend::class, [ 'canSetUser', 'setUser', 'save' ] - ); + $backend = $this->getMockBuilder( DummySessionBackend::class ) + ->setMethods( [ 'canSetUser', 'setUser', 'save' ] ) + ->getMock(); $backend->expects( $this->once() )->method( 'canSetUser' ) ->will( $this->returnValue( true ) ); $backend->expects( $this->once() )->method( 'setUser' ) @@ -238,9 +239,9 @@ class SessionTest extends MediaWikiTestCase { $this->assertSame( [], $backend->data ); $this->assertTrue( $backend->dirty ); - $backend = $this->getMock( - DummySessionBackend::class, [ 'canSetUser', 'setUser', 'save' ] - ); + $backend = $this->getMockBuilder( DummySessionBackend::class ) + ->setMethods( [ 'canSetUser', 'setUser', 'save' ] ) + ->getMock(); $backend->data = []; $backend->expects( $this->once() )->method( 'canSetUser' ) ->will( $this->returnValue( true ) ); @@ -253,9 +254,9 @@ class SessionTest extends MediaWikiTestCase { $session->clear(); $this->assertFalse( $backend->dirty ); - $backend = $this->getMock( - DummySessionBackend::class, [ 'canSetUser', 'setUser', 'save' ] - ); + $backend = $this->getMockBuilder( DummySessionBackend::class ) + ->setMethods( [ 'canSetUser', 'setUser', 'save' ] ) + ->getMock(); $backend->expects( $this->once() )->method( 'canSetUser' ) ->will( $this->returnValue( false ) ); $backend->expects( $this->never() )->method( 'setUser' ); diff --git a/tests/phpunit/includes/site/SiteExporterTest.php b/tests/phpunit/includes/site/SiteExporterTest.php index cb4b6976f4..c0d8c00147 100644 --- a/tests/phpunit/includes/site/SiteExporterTest.php +++ b/tests/phpunit/includes/site/SiteExporterTest.php @@ -75,7 +75,7 @@ class SiteExporterTest extends PHPUnit_Framework_TestCase { } private function newSiteStore( SiteList $sites ) { - $store = $this->getMock( 'SiteStore' ); + $store = $this->getMockBuilder( 'SiteStore' )->getMock(); $store->expects( $this->once() ) ->method( 'saveSites' ) diff --git a/tests/phpunit/includes/site/SiteImporterTest.php b/tests/phpunit/includes/site/SiteImporterTest.php index 45241c5941..ea49429c3b 100644 --- a/tests/phpunit/includes/site/SiteImporterTest.php +++ b/tests/phpunit/includes/site/SiteImporterTest.php @@ -32,7 +32,7 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { private function newSiteImporter( array $expectedSites, $errorCount ) { - $store = $this->getMock( 'SiteStore' ); + $store = $this->getMockBuilder( 'SiteStore' )->getMock(); $store->expects( $this->once() ) ->method( 'saveSites' ) @@ -44,7 +44,7 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { ->method( 'getSites' ) ->will( $this->returnValue( new SiteList() ) ); - $errorHandler = $this->getMock( 'Psr\Log\LoggerInterface' ); + $errorHandler = $this->getMockBuilder( 'Psr\Log\LoggerInterface' )->getMock(); $errorHandler->expects( $this->exactly( $errorCount ) ) ->method( 'error' ); @@ -148,7 +148,7 @@ class SiteImporterTest extends PHPUnit_Framework_TestCase { public function testImportFromXML_malformed() { $this->setExpectedException( 'Exception' ); - $store = $this->getMock( 'SiteStore' ); + $store = $this->getMockBuilder( 'SiteStore' )->getMock(); $importer = new SiteImporter( $store ); $importer->importFromXML( 'THIS IS NOT XML' ); } diff --git a/tests/phpunit/includes/specials/SpecialPreferencesTest.php b/tests/phpunit/includes/specials/SpecialPreferencesTest.php index 4a46464d71..fd587bfa0c 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->getMock( 'User' ); + $user = $this->createMock( 'User' ); $user->expects( $this->any() ) ->method( 'isAnon' ) ->will( $this->returnValue( false ) ); diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php index 81c84e8306..594540f7a2 100644 --- a/tests/phpunit/includes/user/BotPasswordTest.php +++ b/tests/phpunit/includes/user/BotPasswordTest.php @@ -311,7 +311,9 @@ class BotPasswordTest extends MediaWikiTestCase { ); // Failed restriction - $request = $this->getMock( 'FauxRequest', [ 'getIP' ] ); + $request = $this->getMockBuilder( 'FauxRequest' ) + ->setMethods( [ 'getIP' ] ) + ->getMock(); $request->expects( $this->any() )->method( 'getIP' ) ->will( $this->returnValue( '10.0.0.1' ) ); $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request ); diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php index 7ff882a5ad..3363bca524 100644 --- a/tests/phpunit/includes/user/PasswordResetTest.php +++ b/tests/phpunit/includes/user/PasswordResetTest.php @@ -23,7 +23,7 @@ class PasswordResetTest extends PHPUnit_Framework_TestCase { $authManager->expects( $this->any() )->method( 'allowsAuthenticationDataChange' ) ->willReturn( $allowsAuthenticationDataChange ? Status::newGood() : Status::newFatal( 'foo' ) ); - $user = $this->getMock( User::class ); + $user = $this->getMockBuilder( User::class )->getMock(); $user->expects( $this->any() )->method( 'getName' )->willReturn( 'Foo' ); $user->expects( $this->any() )->method( 'isBlocked' )->willReturn( $userIsBlocked ); $user->expects( $this->any() )->method( 'isAllowed' ) @@ -124,12 +124,12 @@ class PasswordResetTest extends PHPUnit_Framework_TestCase { $request = new FauxRequest(); $request->setIP( '1.2.3.4' ); - $performingUser = $this->getMock( User::class ); + $performingUser = $this->getMockBuilder( User::class )->getMock(); $performingUser->expects( $this->any() )->method( 'getRequest' )->willReturn( $request ); $performingUser->expects( $this->any() )->method( 'isAllowed' )->willReturn( true ); - $targetUser1 = $this->getMock( User::class ); - $targetUser2 = $this->getMock( User::class ); + $targetUser1 = $this->getMockBuilder( User::class )->getMock(); + $targetUser2 = $this->getMockBuilder( User::class )->getMock(); $targetUser1->expects( $this->any() )->method( 'getName' )->willReturn( 'User1' ); $targetUser2->expects( $this->any() )->method( 'getName' )->willReturn( 'User2' ); $targetUser1->expects( $this->any() )->method( 'getId' )->willReturn( 1 ); diff --git a/tests/phpunit/maintenance/MaintenanceTest.php b/tests/phpunit/maintenance/MaintenanceTest.php index cb3d227203..6b0e3443c1 100644 --- a/tests/phpunit/maintenance/MaintenanceTest.php +++ b/tests/phpunit/maintenance/MaintenanceTest.php @@ -835,7 +835,7 @@ class MaintenanceTest extends MediaWikiTestCase { * @covers Maintenance::setConfig */ public function testSetConfig() { - $conf = $this->getMock( 'Config' ); + $conf = $this->createMock( 'Config' ); $this->m->setConfig( $conf ); $this->assertSame( $conf, $this->m->getConfig() ); } diff --git a/tests/phpunit/maintenance/backupTextPassTest.php b/tests/phpunit/maintenance/backupTextPassTest.php index d7e72bb023..d460401a86 100644 --- a/tests/phpunit/maintenance/backupTextPassTest.php +++ b/tests/phpunit/maintenance/backupTextPassTest.php @@ -169,7 +169,10 @@ class TextPassDumperDatabaseTest extends DumpTestCase { ]; // The mock itself - $prefetchMock = $this->getMock( 'BaseDump', [ 'prefetch' ], [], '', false ); + $prefetchMock = $this->getMockBuilder( 'BaseDump' ) + ->setMethods( [ 'prefetch' ] ) + ->disableOriginalConstructor() + ->getMock(); $prefetchMock->expects( $this->exactly( 6 ) ) ->method( 'prefetch' ) ->will( $this->returnValueMap( $prefetchMap ) ); diff --git a/tests/phpunit/tests/MediaWikiTestCaseTest.php b/tests/phpunit/tests/MediaWikiTestCaseTest.php index edc81ff925..7d75ffe648 100644 --- a/tests/phpunit/tests/MediaWikiTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php @@ -142,7 +142,7 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { */ public function testLoggersAreRestoredOnTearDown_replacingExistingLogger() { $logger1 = LoggerFactory::getInstance( 'foo' ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); $logger2 = LoggerFactory::getInstance( 'foo' ); $this->tearDown(); $logger3 = LoggerFactory::getInstance( 'foo' ); @@ -156,7 +156,7 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { * @covers MediaWikiTestCase::restoreLoggers */ public function testLoggersAreRestoredOnTearDown_replacingNonExistingLogger() { - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); $logger1 = LoggerFactory::getInstance( 'foo' ); $this->tearDown(); $logger2 = LoggerFactory::getInstance( 'foo' ); @@ -171,8 +171,8 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { */ public function testLoggersAreRestoredOnTearDown_replacingSameLoggerTwice() { $logger1 = LoggerFactory::getInstance( 'baz' ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); - $this->setLogger( 'foo', $this->getMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); + $this->setLogger( 'foo', $this->createMock( LoggerInterface::class ) ); $this->tearDown(); $logger2 = LoggerFactory::getInstance( 'baz' );