Merge "phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 6 Apr 2017 23:30:01 +0000 (23:30 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 6 Apr 2017 23:30:01 +0000 (23:30 +0000)
53 files changed:
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/MWTimestampTest.php
tests/phpunit/includes/MediaWikiServicesTest.php
tests/phpunit/includes/Services/ServiceContainerTest.php
tests/phpunit/includes/WatchedItemQueryServiceUnitTest.php
tests/phpunit/includes/WatchedItemStoreUnitTest.php
tests/phpunit/includes/WatchedItemUnitTest.php
tests/phpunit/includes/api/ApiMainTest.php
tests/phpunit/includes/auth/AbstractPrimaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/AbstractSecondaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/AuthManagerTest.php
tests/phpunit/includes/auth/AuthPluginPrimaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/AuthenticationRequestTest.php
tests/phpunit/includes/auth/EmailNotificationSecondaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/LegacyHookPreAuthenticationProviderTest.php
tests/phpunit/includes/auth/LocalPasswordPrimaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php
tests/phpunit/includes/auth/ThrottlerTest.php
tests/phpunit/includes/changes/ChangesListStringOptionsFilterGroupTest.php
tests/phpunit/includes/content/ContentHandlerTest.php
tests/phpunit/includes/content/FileContentHandlerTest.php
tests/phpunit/includes/content/TextContentHandlerTest.php
tests/phpunit/includes/content/WikitextContentHandlerTest.php
tests/phpunit/includes/debug/logger/monolog/KafkaHandlerTest.php
tests/phpunit/includes/filerepo/FileBackendDBRepoWrapperTest.php
tests/phpunit/includes/filerepo/MigrateFileRepoLayoutTest.php
tests/phpunit/includes/filerepo/RepoGroupTest.php
tests/phpunit/includes/filerepo/file/FileTest.php
tests/phpunit/includes/jobqueue/JobTest.php
tests/phpunit/includes/libs/MemoizedCallableTest.php
tests/phpunit/includes/libs/SamplingStatsdClientTest.php
tests/phpunit/includes/libs/objectcache/BagOStuffTest.php
tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php
tests/phpunit/includes/libs/rdbms/connectionmanager/ConnectionManagerTest.php
tests/phpunit/includes/libs/rdbms/connectionmanager/SessionConsistentConnectionManagerTest.php
tests/phpunit/includes/linker/LinkRendererFactoryTest.php
tests/phpunit/includes/mail/MailAddressTest.php
tests/phpunit/includes/search/SearchEngineTest.php
tests/phpunit/includes/session/BotPasswordSessionProviderTest.php
tests/phpunit/includes/session/CookieSessionProviderTest.php
tests/phpunit/includes/session/ImmutableSessionProviderWithCookieTest.php
tests/phpunit/includes/session/SessionBackendTest.php
tests/phpunit/includes/session/SessionManagerTest.php
tests/phpunit/includes/session/SessionTest.php
tests/phpunit/includes/site/SiteExporterTest.php
tests/phpunit/includes/site/SiteImporterTest.php
tests/phpunit/includes/specials/SpecialPreferencesTest.php
tests/phpunit/includes/user/BotPasswordTest.php
tests/phpunit/includes/user/PasswordResetTest.php
tests/phpunit/maintenance/MaintenanceTest.php
tests/phpunit/maintenance/backupTextPassTest.php
tests/phpunit/tests/MediaWikiTestCaseTest.php

index 564c0ff..29da00d 100644 (file)
@@ -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 ) );
        }
index 4bca478..c1a46fe 100644 (file)
@@ -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' )
index cc95e38..a72662f 100644 (file)
@@ -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;
                        }
index f22e123..617e39c 100644 (file)
@@ -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' );
 
index bdec0a5..76d1cb9 100644 (file)
@@ -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 ) );
index 0bd0bcc..b71e8f4 100644 (file)
@@ -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 ) ) );
index 7e1ff3d..8897645 100644 (file)
@@ -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 )
index 922f7f1..a1b7a87 100644 (file)
@@ -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(),
index d8588d5..8d84f4c 100644 (file)
@@ -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;
                }
 
index bb90dd9..41cf62e 100644 (file)
@@ -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;
                }
 
index f7be801..5c268f8 100644 (file)
@@ -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' ) );
index 96e50e0..6970313 100644 (file)
@@ -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' )
index 7d2ba8d..0e549a5 100644 (file)
@@ -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( [] ) );
 
index ec4bea1..ca6689a 100644 (file)
@@ -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' )
index b96455e..3b00194 100644 (file)
@@ -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 ],
                ] );
index 72a03c3..6e2058c 100644 (file)
@@ -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;
index bc7d65e..8d9509e 100644 (file)
@@ -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;
index 2f3e27c..ee82832 100644 (file)
@@ -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', [
index c945885..33c8ce6 100644 (file)
@@ -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() );
 
index dc868a8..0f556b8 100644 (file)
@@ -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 );
index a3d1dda..403bee1 100644 (file)
@@ -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 );
 
index 276a86e..65efcc9 100644 (file)
@@ -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' )
index 918815c..7d9f74e 100644 (file)
@@ -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' )
index ec97d76..290b11a 100644 (file)
@@ -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 );
 
index d6249bb..ce21412 100644 (file)
@@ -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' ) );
index 6c93c79..0d00fbc 100644 (file)
@@ -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 ) );
 
index d3f9374..800c2fc 100644 (file)
@@ -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' )
index 25c6e95..82ff12e 100644 (file)
@@ -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' ], [ [] ] );
index 6520610..5b5f1b0 100644 (file)
@@ -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 ) );
index 600a36f..1deb7aa 100644 (file)
@@ -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}' ) );
index 881f5e1..d99c587 100644 (file)
@@ -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' ) );
index 9a48930..c5bc03e 100644 (file)
@@ -1,13 +1,14 @@
 <?php
 
 use Liuggio\StatsdClient\Entity\StatsdData;
+use Liuggio\StatsdClient\Sender\SenderInterface;
 
 class SamplingStatsdClientTest extends PHPUnit_Framework_TestCase {
        /**
         * @dataProvider samplingDataProvider
         */
        public function testSampling( $data, $sampleRate, $seed, $expectWrite ) {
-               $sender = $this->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 ) );
index a1afa77..f2fe07d 100644 (file)
@@ -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', [
index d7ed4bd..18729f0 100644 (file)
@@ -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( [
index cd350e5..a3f3981 100644 (file)
@@ -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();
        }
 
        /**
index 3b26d6f..4e76f2a 100644 (file)
@@ -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();
        }
 
        /**
index bf12f80..27e5a65 100644 (file)
@@ -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 );
index 39b6f9f..c837d26 100644 (file)
@@ -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' )
                );
index 3fb4bbb..c74c893 100644 (file)
@@ -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 ) {
index c1eef2e..1ea27f3 100644 (file)
@@ -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;
index da4b06e..73485c8 100644 (file)
@@ -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 );
index 78edb76..7ef230e 100644 (file)
@@ -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;
index 8a0adba..4a28f7a 100644 (file)
@@ -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 ] ] );
index 48a72d3..c4b1072 100644 (file)
@@ -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 ];
index e6a6ad3..f6c88ec 100644 (file)
@@ -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' );
index cb4b697..c0d8c00 100644 (file)
@@ -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' )
index 45241c5..ea49429 100644 (file)
@@ -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' );
        }
index 4a46464..fd587bf 100644 (file)
@@ -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 ) );
index 81c84e8..594540f 100644 (file)
@@ -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 );
index 7ff882a..3363bca 100644 (file)
@@ -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 );
index cb3d227..6b0e344 100644 (file)
@@ -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() );
        }
index d7e72bb..d460401 100644 (file)
@@ -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 ) );
index edc81ff..7d75ffe 100644 (file)
@@ -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' );