From: Brad Jorsch Date: Thu, 12 Apr 2018 17:25:19 +0000 (-0400) Subject: AuthManagerTest: Fix for PHPUnit 6 X-Git-Tag: 1.31.0-rc.0~97^2 X-Git-Url: http://git.cyclocoop.org/%27.parametre_url%28%20%20%20generer_action_auteur%28%27charger_plugin%27%2C%20%27update_flux%27%29%2C%27update_flux%27%2C%20%27oui%27%29.%27?a=commitdiff_plain;h=23596834bf86f03be194d77c040df0140e438c65;p=lhc%2Fweb%2Fwiklou.git AuthManagerTest: Fix for PHPUnit 6 PHPUnit 6 apparently needs methods explicitly declared as mockable in some cases where PHPUnit 4 didn't, specifically 'providerAllowsAuthenticationDataChange' in testGetAuthenticationRequests. That also means we need to remove the (fortunately unnecessary) forcing of the mocked class name in there, or else it reuses the generic configuration created under that name for earlier tests. For good measure, let's also remove the mocked class name forcing from several other places where it isn't needed (but was presumably copy-pasted from the places where it was). Change-Id: If12ed836c7e47797f20deb0bdaa3ea852a921069 --- diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 211eba00b7..cc1624874f 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -879,14 +879,10 @@ class AuthManagerTest extends \MediaWikiTestCase { ); $mocks[$key]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); - $mocks[$key . '2'] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key . '2'] = $this->getMockForAbstractClass( "MediaWiki\\Auth\\$class" ); $mocks[$key . '2']->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key . '2' ) ); - $mocks[$key . '3'] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key . '3'] = $this->getMockForAbstractClass( "MediaWiki\\Auth\\$class" ); $mocks[$key . '3']->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key . '3' ) ); } @@ -1901,9 +1897,7 @@ class AuthManagerTest extends \MediaWikiTestCase { ) ); for ( $i = 2; $i <= 3; $i++ ) { - $mocks[$key . $i] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key . $i] = $this->getMockForAbstractClass( "MediaWiki\\Auth\\$class" ); $mocks[$key . $i]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key . $i ) ); $mocks[$key . $i]->expects( $this->any() )->method( 'testUserForCreation' ) @@ -2368,9 +2362,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $mocks = []; foreach ( [ 'pre', 'primary', 'secondary' ] as $key ) { $class = ucfirst( $key ) . 'AuthenticationProvider'; - $mocks[$key] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key] = $this->getMockForAbstractClass( "MediaWiki\\Auth\\$class" ); $mocks[$key]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); } @@ -2848,9 +2840,11 @@ class AuthManagerTest extends \MediaWikiTestCase { $mocks = []; foreach ( [ 'pre', 'primary', 'secondary' ] as $key ) { $class = ucfirst( $key ) . 'AuthenticationProvider'; - $mocks[$key] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key] = $this->getMockBuilder( "MediaWiki\\Auth\\$class" ) + ->setMethods( [ + 'getUniqueId', 'getAuthenticationRequests', 'providerAllowsAuthenticationDataChange', + ] ) + ->getMockForAbstractClass(); $mocks[$key]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); $mocks[$key]->expects( $this->any() )->method( 'getAuthenticationRequests' ) @@ -2868,9 +2862,12 @@ class AuthManagerTest extends \MediaWikiTestCase { PrimaryAuthenticationProvider::TYPE_LINK ] as $type ) { $class = 'PrimaryAuthenticationProvider'; - $mocks["primary-$type"] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks["primary-$type"] = $this->getMockBuilder( "MediaWiki\\Auth\\$class" ) + ->setMethods( [ + 'getUniqueId', 'accountCreationType', 'getAuthenticationRequests', + 'providerAllowsAuthenticationDataChange', + ] ) + ->getMockForAbstractClass(); $mocks["primary-$type"]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( "primary-$type" ) ); $mocks["primary-$type"]->expects( $this->any() )->method( 'accountCreationType' ) @@ -2885,9 +2882,12 @@ class AuthManagerTest extends \MediaWikiTestCase { $this->primaryauthMocks[] = $mocks["primary-$type"]; } - $mocks['primary2'] = $this->getMockForAbstractClass( - PrimaryAuthenticationProvider::class, [], "MockPrimaryAuthenticationProvider" - ); + $mocks['primary2'] = $this->getMockBuilder( PrimaryAuthenticationProvider::class ) + ->setMethods( [ + 'getUniqueId', 'accountCreationType', 'getAuthenticationRequests', + 'providerAllowsAuthenticationDataChange', + ] ) + ->getMockForAbstractClass(); $mocks['primary2']->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( 'primary2' ) ); $mocks['primary2']->expects( $this->any() )->method( 'accountCreationType' ) @@ -3138,9 +3138,7 @@ class AuthManagerTest extends \MediaWikiTestCase { $mocks = []; foreach ( [ 'primary', 'secondary' ] as $key ) { $class = ucfirst( $key ) . 'AuthenticationProvider'; - $mocks[$key] = $this->getMockForAbstractClass( - "MediaWiki\\Auth\\$class", [], "Mock$class" - ); + $mocks[$key] = $this->getMockForAbstractClass( "MediaWiki\\Auth\\$class" ); $mocks[$key]->expects( $this->any() )->method( 'getUniqueId' ) ->will( $this->returnValue( $key ) ); $mocks[$key]->expects( $this->any() )->method( 'providerAllowsPropertyChange' ) @@ -3224,8 +3222,7 @@ class AuthManagerTest extends \MediaWikiTestCase { public function testAutoCreateFailOnLogin() { $username = self::usernameForCreation(); - $mock = $this->getMockForAbstractClass( - PrimaryAuthenticationProvider::class, [], "MockPrimaryAuthenticationProvider" ); + $mock = $this->getMockForAbstractClass( PrimaryAuthenticationProvider::class ); $mock->expects( $this->any() )->method( 'getUniqueId' )->will( $this->returnValue( 'primary' ) ); $mock->expects( $this->any() )->method( 'beginPrimaryAuthentication' ) ->will( $this->returnValue( AuthenticationResponse::newPass( $username ) ) );