The default will remain PHPUnit 4.x due to PHP 5.5 support.
But, we should allow developers to run tests with newer PHPUnit
versions which are noticably faster (especially for code coverage
reports).
* <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0>
PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock().
It instead introduces the shortcut createMock() which has better defaults
than getMockBuilder(). For example, it sets 'disableArgumentCloning' and
other things by default.
Going forward, code should either use getMockBuilder directly and configure
it using the setter methods (instead of the confusing variadic arguments
of getMock) or simply use the new minimalistic createMock method. This patch
backports the createMock method to MediaWikiTestCase so that we can start
using it.
Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
*/
public function __call( $func, $args ) {
static $compatibility = [
+ 'createMock' => 'createMock2',
];
if ( isset( $compatibility[$func] ) ) {
}
}
+ /**
+ * 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 ) );
}
$expectedOutput, // The expected output
$desc // Description
) {
- $user = $this->getMock( 'User' );
+ $user = $this->createMock( 'User' );
$user->expects( $this->any() )
->method( 'getOption' )
->with( 'timecorrection' )
$expectedOutput, // The expected output
$desc // Description
) {
- $user = $this->getMock( 'User' );
+ $user = $this->createMock( 'User' );
$user->expects( $this->any() )
->method( 'getOption' )
->with( 'timecorrection' )
$newServices = $this->newMediaWikiServices();
$oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
- $service1 = $this->getMock( SalvageableService::class );
+ $service1 = $this->createMock( SalvageableService::class );
$service1->expects( $this->never() )
->method( 'salvage' );
$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 );
$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' );
'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;
}
$services->defineService(
'Test',
function() {
- $service = $this->getMock( 'MediaWiki\Services\DestructibleService' );
+ $service = $this->createMock( 'MediaWiki\Services\DestructibleService' );
$service->expects( $this->never() )->method( 'destroy' );
return $service;
}
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' );
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' );
* @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 ) );
}
private function getMockAnonUser() {
- $mock = $this->getMock( User::class );
+ $mock = $this->getMockBuilder( User::class )->getMock();
$mock->expects( $this->any() )
->method( 'isAnon' )
->will( $this->returnValue( true ) );
* @return PHPUnit_Framework_MockObject_MockObject|IDatabase
*/
private function getMockDb() {
- return $this->getMock( IDatabase::class );
+ return $this->createMock( IDatabase::class );
}
/**
* @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 ) );
* @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 ) ) );
* @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 ) );
$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 );
$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 );
$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 )
);
}
- // 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' ) );
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(),
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;
}
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;
}
*/
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" );
}
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';
// 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 );
$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 );
// 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 );
*/
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;
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;
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' ) );
);
}
- $plugin = $this->getMock( 'AuthPlugin' );
+ $plugin = $this->createMock( 'AuthPlugin' );
$plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
$provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
$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' );
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 ) );
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(
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 ) {
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 ) {
}
public function testGetUniqueId() {
- $plugin = $this->getMock( 'AuthPlugin' );
+ $plugin = $this->createMock( 'AuthPlugin' );
$plugin->expects( $this->any() )->method( 'domainList' )->willReturn( [] );
$provider = new AuthPluginPrimaryAuthenticationProvider( $plugin );
$this->assertSame(
* @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 ) );
}
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' ) )
$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' ) )
}
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' ) )
->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' ) )
->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' ) )
}
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 ) {
*/
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 ) );
if ( is_object( $type ) ) {
$req = $type;
} else {
- $req = $this->getMock( $type );
+ $req = $this->createMock( $type );
}
$req->action = AuthManager::ACTION_CHANGE;
$req->username = 'UTSysop';
}
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();
$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 ) {
$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 ) {
$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' )
* @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 ) );
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(
$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 ) );
);
}
- $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 ) );
$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 ) );
$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 ) );
$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' )
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' => [
],
] ) );
- $req2 = $this->getMock( AuthenticationRequest::class );
+ $req2 = $this->createMock( AuthenticationRequest::class );
$req2->required = AuthenticationRequest::REQUIRED;
$req2->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [
'string1' => [
],
] ) );
- $req3 = $this->getMock( AuthenticationRequest::class );
+ $req3 = $this->createMock( AuthenticationRequest::class );
$req3->required = AuthenticationRequest::REQUIRED;
$req3->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [
'string1' => [
],
] ) );
- $req4 = $this->getMock( AuthenticationRequest::class );
+ $req4 = $this->createMock( AuthenticationRequest::class );
$req4->required = AuthenticationRequest::REQUIRED;
$req4->expects( $this->any() )->method( 'getFieldInfo' )->will( $this->returnValue( [] ) );
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' )
* @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(
* @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 ],
] );
}
$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;
} elseif ( $type === PasswordDomainAuthenticationRequest::class ) {
$req = new $type( [] );
} else {
- $req = $this->getMock( $type );
+ $req = $this->createMock( $type );
}
$req->action = AuthManager::ACTION_CHANGE;
$req->username = $user;
if ( $type === PasswordAuthenticationRequest::class ) {
$changeReq = new $type();
} else {
- $changeReq = $this->getMock( $type );
+ $changeReq = $this->createMock( $type );
}
$changeReq->action = AuthManager::ACTION_CHANGE;
$changeReq->username = $user;
$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;
) {
$req = new $type();
} else {
- $req = $this->getMock( $type );
+ $req = $this->createMock( $type );
}
$req->action = AuthManager::ACTION_CHANGE;
$req->username = $user;
) {
$changeReq = new $type();
} else {
- $changeReq = $this->getMock( $type );
+ $changeReq = $this->createMock( $type );
}
$changeReq->action = AuthManager::ACTION_CHANGE;
$changeReq->username = $user;
$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', [
}
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() );
* @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 );
* @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 );
}
public function testIndexMapping() {
- $mockEngine = $this->getMock( 'SearchEngine' );
+ $mockEngine = $this->createMock( 'SearchEngine' );
$mockEngine->expects( $this->atLeastOnce() )
->method( 'makeSearchFieldMapping' )
public function testFieldsForIndex() {
$handler = new TextContentHandler();
- $mockEngine = $this->getMock( 'SearchEngine' );
+ $mockEngine = $this->createMock( 'SearchEngine' );
$mockEngine->expects( $this->atLeastOnce() )
->method( 'makeSearchFieldMapping' )
*/
public function testDataIndexFieldsFile() {
- $mockEngine = $this->getMock( 'SearchEngine' );
+ $mockEngine = $this->createMock( 'SearchEngine' );
$title = Title::newFromText( 'Somefile.jpg', NS_FILE );
$page = new WikiPage( $title );
[ $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' ) );
->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' ) );
->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 ) );
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' )
function testForEachForeignRepo() {
$this->setUpForeignRepo();
- $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
+ $fakeCallback = $this->createMock( 'RepoGroupTestHelper' );
$fakeCallback->expects( $this->once() )->method( 'callback' );
RepoGroup::singleton()->forEachForeignRepo(
[ $fakeCallback, 'callback' ], [ [] ] );
$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' ], [ [] ] );
->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'] ) );
'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 ) );
}
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}' ) );
* 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' ) );
* @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' ) );
<?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' )
$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 ) );
* @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', [
}
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( [
* @return IDatabase|PHPUnit_Framework_MockObject_MockObject
*/
private function getIDatabaseMock() {
- return $this->getMock( IDatabase::class );
+ return $this->getMockBuilder( IDatabase::class )
+ ->getMock();
}
/**
* @return IDatabase|PHPUnit_Framework_MockObject_MockObject
*/
private function getIDatabaseMock() {
- return $this->getMock( IDatabase::class );
+ return $this->getMockBuilder( IDatabase::class )
+ ->getMock();
}
/**
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 );
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' )
);
/**
* @var $mockEngine SearchEngine
*/
- $mockEngine = $this->getMock( 'SearchEngine', [ 'makeSearchFieldMapping' ] );
+ $mockEngine = $this->getMockBuilder( 'SearchEngine' )
+ ->setMethods( [ 'makeSearchFieldMapping' ] )->getMock();
$mockFieldBuilder = function ( $name, $type ) {
$mockField =
}
public function addAugmentors( &$setAugmentors, &$rowAugmentors ) {
- $setAugmentor = $this->getMock( 'ResultSetAugmentor' );
+ $setAugmentor = $this->createMock( 'ResultSetAugmentor' );
$setAugmentor->expects( $this->once() )
->method( 'augmentAll' )
->willReturnCallback( function ( SearchResultSet $resultSet ) {
} );
$setAugmentors['testSet'] = $setAugmentor;
- $rowAugmentor = $this->getMock( 'ResultAugmentor' );
+ $rowAugmentor = $this->createMock( 'ResultAugmentor' );
$rowAugmentor->expects( $this->exactly( 2 ) )
->method( 'augment' )
->willReturnCallback( function ( SearchResult $result ) {
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' );
$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' );
], $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;
);
\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 ] ] );
}
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;
\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 );
$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 );
$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 );
}
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;
}
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' );
}
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 );
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();
$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' )
// 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 ) {
$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 ] ] );
$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 ] ] );
$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 ] ] );
$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 ];
* @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 ) );
$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' )
$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 ) );
$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' );
}
private function newSiteStore( SiteList $sites ) {
- $store = $this->getMock( 'SiteStore' );
+ $store = $this->getMockBuilder( 'SiteStore' )->getMock();
$store->expects( $this->once() )
->method( 'saveSites' )
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' )
->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' );
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' );
}
// 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 ) );
);
// 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 );
$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' )
$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 );
* @covers Maintenance::setConfig
*/
public function testSetConfig() {
- $conf = $this->getMock( 'Config' );
+ $conf = $this->createMock( 'Config' );
$this->m->setConfig( $conf );
$this->assertSame( $conf, $this->m->getConfig() );
}
];
// 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 ) );
*/
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' );
* @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' );
*/
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' );