Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F585115
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
90 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tests/phpunit/includes/MediaWikiServicesTest.php b/tests/phpunit/includes/MediaWikiServicesTest.php
index f94d7b0a2b9..b37c9255bb3 100644
--- a/tests/phpunit/includes/MediaWikiServicesTest.php
+++ b/tests/phpunit/includes/MediaWikiServicesTest.php
@@ -321,7 +321,7 @@ class MediaWikiServicesTest extends MediaWikiIntegrationTestCase {
$this->assertNotSame( $oldInstance, $newInstance );
}
- public function provideGetters() {
+ public static function provideGetters() {
$getServiceCases = self::provideGetService();
$getterCases = [
// These are "mis-named" getters that don't follow the standard pattern, so are listed explicitly
diff --git a/tests/phpunit/includes/Output/OutputPageTest.php b/tests/phpunit/includes/Output/OutputPageTest.php
index df1fb8eecc9..c242530112d 100644
--- a/tests/phpunit/includes/Output/OutputPageTest.php
+++ b/tests/phpunit/includes/Output/OutputPageTest.php
@@ -632,7 +632,7 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
$this->assertEquals( $expected, @$op->checkLastModified( $timestamp ) );
}
- public function provideCheckLastModified() {
+ public static function provideCheckLastModified() {
$lastModified = time() - 3600;
return [
'Timestamp 0' =>
@@ -660,8 +660,8 @@ class OutputPageTest extends MediaWikiIntegrationTestCase {
[ MainConfigNames::CacheEpoch => wfTimestamp( TS_MW, $lastModified + 1 ) ] ],
'Recently-touched user' =>
[ $lastModified, $lastModified, false, [],
- function ( OutputPage $op ) {
- $op->getContext()->setUser( $this->getTestUser()->getUser() );
+ static function ( OutputPage $op, $testCase ) {
+ $op->getContext()->setUser( $testCase->getTestUser()->getUser() );
} ],
'After CDN expiry' =>
[ $lastModified, $lastModified, false,
diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
index ae26c0dbb3d..3a737902f89 100644
--- a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
+++ b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php
@@ -851,7 +851,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
*/
public function testGetRevisionByTitle( $getTitle ) {
$page = $this->getTestPage();
- $title = $getTitle();
+ $title = $getTitle( $this );
$content = new WikitextContent( __METHOD__ );
$status = $page->doUserEditContent(
$content,
@@ -868,13 +868,13 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
$this->assertSame( __METHOD__, $storeRecord->getComment()->text );
}
- public function provideRevisionByTitle() {
+ public static function provideRevisionByTitle() {
return [
- [ function () {
- return $this->getTestPageTitle();
+ [ static function ( $testCase ) {
+ return $testCase->getTestPageTitle();
} ],
- [ function () {
- return $this->getTestPageTitle()->toPageIdentity();
+ [ static function ( $testCase ) {
+ return $testCase->getTestPageTitle()->toPageIdentity();
} ]
];
}
@@ -1000,7 +1000,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
// Otherwise we might not get the correct revision and the test may fail...
MWTimestamp::setFakeTime( '20110401090000' );
$page = $this->getTestPage();
- $title = $getTitle();
+ $title = $getTitle( $this );
MWTimestamp::setFakeTime( '20110401090001' );
$content = new WikitextContent( __METHOD__ );
$status = $page->doUserEditContent(
@@ -1846,7 +1846,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase {
)->getNewRevision();
$store = $this->getServiceContainer()->getRevisionStore();
$storeRecord = $store->getKnownCurrentRevision(
- $getPageIdentity(),
+ $getPageIdentity( $this ),
$revRecord->getId()
);
$this->assertRevisionRecordsEqual( $revRecord, $storeRecord );
diff --git a/tests/phpunit/includes/api/ApiMainTest.php b/tests/phpunit/includes/api/ApiMainTest.php
index c797a8618fa..eeba7a57f6f 100644
--- a/tests/phpunit/includes/api/ApiMainTest.php
+++ b/tests/phpunit/includes/api/ApiMainTest.php
@@ -970,11 +970,17 @@ class ApiMainTest extends ApiTestCase {
/**
* @dataProvider provideExceptionErrors
*/
- public function testExceptionErrors( $error, $expectReturn, $expectResult ) {
+ public function testExceptionErrors( $errorCallback, $expectReturn, $expectResult ) {
$this->overrideConfigValues( [
MainConfigNames::Server => 'https://local.example',
MainConfigNames::ScriptPath => '/w',
] );
+
+ $error = $errorCallback( $this );
+ if ( isset( $expectResult['trace'] ) ) {
+ $expectResult['trace'] = $expectResult['trace']( $error );
+ }
+
$context = new RequestContext();
$context->setRequest( new FauxRequest( [ 'errorformat' => 'plaintext' ] ) );
$context->setLanguage( 'en' );
@@ -1000,55 +1006,18 @@ class ApiMainTest extends ApiTestCase {
);
}
- // Not static so $this can be used
- public function provideExceptionErrors() {
+ public static function provideExceptionErrors() {
$reqId = WebRequest::getRequestId();
$doclink = 'https://local.example/w/api.php';
- $ex = new InvalidArgumentException( 'Random exception' );
- $trace = wfMessage( 'api-exception-trace',
- get_class( $ex ),
- $ex->getFile(),
- $ex->getLine(),
- MWExceptionHandler::getRedactedTraceAsString( $ex )
- )->inLanguage( 'en' )->useDatabase( false )->text();
-
- $dbex = new DBQueryError(
- $this->createMock( IDatabase::class ),
- 'error', 1234, 'SELECT 1', __METHOD__ );
- $dbtrace = wfMessage( 'api-exception-trace',
- get_class( $dbex ),
- $dbex->getFile(),
- $dbex->getLine(),
- MWExceptionHandler::getRedactedTraceAsString( $dbex )
- )->inLanguage( 'en' )->useDatabase( false )->text();
-
// The specific exception doesn't matter, as long as it's namespaced.
$nsex = new ShellDisabledError();
- $nstrace = wfMessage( 'api-exception-trace',
- get_class( $nsex ),
- $nsex->getFile(),
- $nsex->getLine(),
- MWExceptionHandler::getRedactedTraceAsString( $nsex )
- )->inLanguage( 'en' )->useDatabase( false )->text();
-
- $apiEx1 = new ApiUsageException( null,
- StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
- TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
- $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'A warning', 'sv-warn1' ) );
- $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) );
- $apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) );
-
- $badMsg = $this->getMockBuilder( ApiRawMessage::class )
- ->setConstructorArgs( [ 'An error', 'ignored' ] )
- ->onlyMethods( [ 'getApiCode' ] )
- ->getMock();
- $badMsg->method( 'getApiCode' )->willReturn( "bad\nvalue" );
- $apiEx2 = new ApiUsageException( null, StatusValue::newFatal( $badMsg ) );
return [
[
- $ex,
+ static function () {
+ return new InvalidArgumentException( 'Random exception' );
+ },
[ 'existing-error', 'internal_api_error_InvalidArgumentException' ],
[
'warnings' => [
@@ -1064,12 +1033,24 @@ class ApiMainTest extends ApiTestCase {
],
]
],
- 'trace' => $trace,
+ 'trace' => static function ( $ex ) {
+ return wfMessage( 'api-exception-trace',
+ get_class( $ex ),
+ $ex->getFile(),
+ $ex->getLine(),
+ MWExceptionHandler::getRedactedTraceAsString( $ex )
+ )->inLanguage( 'en' )->useDatabase( false )->text();
+ },
'servedby' => wfHostname(),
]
],
[
- $dbex,
+ static function ( $testCase ) {
+ return new DBQueryError(
+ $testCase->createMock( IDatabase::class ),
+ 'error', 1234, 'SELECT 1', 'provideExceptionErrors'
+ );
+ },
[ 'existing-error', 'internal_api_error_DBQueryError' ],
[
'warnings' => [
@@ -1086,12 +1067,21 @@ class ApiMainTest extends ApiTestCase {
],
]
],
- 'trace' => $dbtrace,
+ 'trace' => static function ( $dbex ) {
+ return wfMessage( 'api-exception-trace',
+ get_class( $dbex ),
+ $dbex->getFile(),
+ $dbex->getLine(),
+ MWExceptionHandler::getRedactedTraceAsString( $dbex )
+ )->inLanguage( 'en' )->useDatabase( false )->text();
+ },
'servedby' => wfHostname(),
]
],
[
- $nsex,
+ static function () use ( $nsex ) {
+ return $nsex;
+ },
[ 'existing-error', 'internal_api_error_MediaWiki\Exception\ShellDisabledError' ],
[
'warnings' => [
@@ -1107,12 +1097,27 @@ class ApiMainTest extends ApiTestCase {
],
]
],
- 'trace' => $nstrace,
+ 'trace' => static function ( $nsex ) {
+ return wfMessage( 'api-exception-trace',
+ get_class( $nsex ),
+ $nsex->getFile(),
+ $nsex->getLine(),
+ MWExceptionHandler::getRedactedTraceAsString( $nsex )
+ )->inLanguage( 'en' )->useDatabase( false )->text();
+ },
'servedby' => wfHostname(),
]
],
[
- $apiEx1,
+ static function () {
+ $apiEx1 = new ApiUsageException( null,
+ StatusValue::newFatal( new ApiRawMessage( 'An error', 'sv-error1' ) ) );
+ TestingAccessWrapper::newFromObject( $apiEx1 )->modulePath = 'foo+bar';
+ $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'A warning', 'sv-warn1' ) );
+ $apiEx1->getStatusValue()->warning( new ApiRawMessage( 'Another warning', 'sv-warn2' ) );
+ $apiEx1->getStatusValue()->fatal( new ApiRawMessage( 'Another error', 'sv-error2' ) );
+ return $apiEx1;
+ },
[ 'existing-error', 'sv-error1', 'sv-error2' ],
[
'warnings' => [
@@ -1132,7 +1137,15 @@ class ApiMainTest extends ApiTestCase {
]
],
[
- $apiEx2,
+ static function ( $testCase ) {
+ $badMsg = $testCase->getMockBuilder( ApiRawMessage::class )
+ ->setConstructorArgs( [ 'An error', 'ignored' ] )
+ ->onlyMethods( [ 'getApiCode' ] )
+ ->getMock();
+ $badMsg->method( 'getApiCode' )->willReturn( "bad\nvalue" );
+ $apiEx2 = new ApiUsageException( null, StatusValue::newFatal( $badMsg ) );
+ return $apiEx2;
+ },
[ 'existing-error', '<invalid-code>' ],
[
'warnings' => [
diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php
index 8980699fc90..018cc739738 100644
--- a/tests/phpunit/includes/auth/AuthManagerTest.php
+++ b/tests/phpunit/includes/auth/AuthManagerTest.php
@@ -1033,30 +1033,16 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideAuthentication
- * @param StatusValue $preResponse
- * @param array<AuthenticationResponse|Exception> $primaryResponses
- * @param array<AuthenticationResponse|Exception> $secondaryResponses
- * @param array<AuthenticationResponse|Exception> $managerResponses
- * @param bool $link Whether the primary authentication provider is a "link" provider
*/
public function testAuthentication(
- StatusValue $preResponse, array $primaryResponses, array $secondaryResponses,
- array $managerResponses, $link = false
+ StatusValue $preResponse, $responses, $link = false
) {
$this->initializeManager();
$user = $this->getTestSysop()->getUser();
$id = $user->getId();
$name = $user->getName();
- // Hack: replace placeholder usernames with that of the test user. A better solution would be to instantiate
- // all responses here, only providing constructor arguments (like the status) from the data provider.
- $responseArrays = [ $primaryResponses, $secondaryResponses, $managerResponses ];
- foreach ( $responseArrays as $respArray ) {
- foreach ( $respArray as $resp ) {
- if ( $resp instanceof AuthenticationResponse && $resp->username === 'PLACEHOLDER' ) {
- $resp->username = $name;
- }
- }
- }
+ $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
+ [ $primaryResponses, $secondaryResponses, $managerResponses ] = $responses( $this, $req, $name );
// Set up lots of mocks...
$req = new RememberMeAuthenticationRequest;
@@ -1275,158 +1261,207 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
}
}
- public function provideAuthentication() {
- $rememberReq = new RememberMeAuthenticationRequest;
- $rememberReq->action = AuthManager::ACTION_LOGIN;
-
- $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
- $restartResponse = AuthenticationResponse::newRestart(
- $this->message( 'authmanager-authn-no-local-user' )
- );
- $restartResponse->neededRequests = [ $rememberReq ];
-
- $restartResponse2Pass = AuthenticationResponse::newPass( null );
- $restartResponse2Pass->linkRequest = $req;
- $restartResponse2 = AuthenticationResponse::newRestart(
- $this->message( 'authmanager-authn-no-local-user-link' )
- );
- $restartResponse2->createRequest = new CreateFromLoginAuthenticationRequest(
- null, [ $req->getUniqueId() => $req ]
- );
- $restartResponse2->createRequest->action = AuthManager::ACTION_LOGIN;
- $restartResponse2->neededRequests = [ $rememberReq, $restartResponse2->createRequest ];
-
- // Hack: use a placeholder that will be replaced with the actual username in the test method.
- $userNamePlaceholder = 'PLACEHOLDER';
-
+ public static function provideAuthentication() {
return [
'Failure in pre-auth' => [
StatusValue::newFatal( 'fail-from-pre' ),
- [],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'fail-from-pre' ) ),
- AuthenticationResponse::newFail(
- $this->message( 'authmanager-authn-not-in-progress' )
- ),
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ return [
+ [],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-pre' ) ),
+ AuthenticationResponse::newFail(
+ $testCase->message( 'authmanager-authn-not-in-progress' )
+ ),
+ ]
+ ];
+ },
],
'Failure in primary' => [
StatusValue::newGood(),
- $tmp = [
- AuthenticationResponse::newFail( $this->message( 'fail-from-primary' ) ),
- ],
- [],
- $tmp
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $tmp = [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-primary' ) ),
+ ];
+ return [
+ $tmp,
+ [],
+ $tmp
+ ];
+ },
],
'All primary abstain' => [
StatusValue::newGood(),
- [
- AuthenticationResponse::newAbstain(),
- ],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'authmanager-authn-no-primary' ) )
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ return [
+ [
+ AuthenticationResponse::newAbstain(),
+ ],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'authmanager-authn-no-primary' ) )
+ ]
+ ];
+ },
],
'Primary UI, then redirect, then fail' => [
StatusValue::newGood(),
- $tmp = [
- AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
- AuthenticationResponse::newFail( $this->message( 'fail-in-primary-continue' ) ),
- ],
- [],
- $tmp
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $tmp = [
+ AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) ),
+ AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
+ AuthenticationResponse::newFail( $testCase->message( 'fail-in-primary-continue' ) ),
+ ];
+ return [
+ $tmp,
+ [],
+ $tmp
+ ];
+ },
],
'Primary redirect, then abstain' => [
StatusValue::newGood(),
- [
+ static function ( $testCase, $req, $userNamePlaceholder ) {
$tmp = AuthenticationResponse::newRedirect(
[ $req ], '/foo.html', [ 'foo' => 'bar' ]
- ),
- AuthenticationResponse::newAbstain(),
- ],
- [],
- [
- $tmp,
- new DomainException(
- 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAuthentication() returned ABSTAIN'
- )
- ]
+ );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newAbstain(),
+ ],
+ [],
+ [
+ $tmp,
+ new DomainException(
+ 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAuthentication() returned ABSTAIN'
+ )
+ ]
+ ];
+ },
],
'Primary UI, then pass with no local user' => [
StatusValue::newGood(),
- [
- $tmp = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newPass( null ),
- ],
- [],
- [
- $tmp,
- $restartResponse,
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $rememberReq = new RememberMeAuthenticationRequest;
+ $rememberReq->action = AuthManager::ACTION_LOGIN;
+
+ $restartResponse = AuthenticationResponse::newRestart(
+ $testCase->message( 'authmanager-authn-no-local-user' )
+ );
+ $restartResponse->neededRequests = [ $rememberReq ];
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newPass( null ),
+ ],
+ [],
+ [
+ $tmp,
+ $restartResponse,
+ ]
+ ];
+ },
],
'Primary UI, then pass with no local user (link type)' => [
StatusValue::newGood(),
- [
- $tmp = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- $restartResponse2Pass,
- ],
- [],
- [
- $tmp,
- $restartResponse2,
- ],
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $rememberReq = new RememberMeAuthenticationRequest;
+ $rememberReq->action = AuthManager::ACTION_LOGIN;
+
+ $restartResponse2Pass = AuthenticationResponse::newPass( null );
+ $restartResponse2Pass->linkRequest = $req;
+ $restartResponse2 = AuthenticationResponse::newRestart(
+ $testCase->message( 'authmanager-authn-no-local-user-link' )
+ );
+ $restartResponse2->createRequest = new CreateFromLoginAuthenticationRequest(
+ null, [ $req->getUniqueId() => $req ]
+ );
+ $restartResponse2->createRequest->action = AuthManager::ACTION_LOGIN;
+ $restartResponse2->neededRequests = [ $rememberReq, $restartResponse2->createRequest ];
+
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ $tmp,
+ $restartResponse2Pass,
+ ],
+ [],
+ [
+ $tmp,
+ $restartResponse2,
+ ],
+ ];
+ },
true
],
'Primary pass with invalid username' => [
StatusValue::newGood(),
- [
- AuthenticationResponse::newPass( '<>' ),
- ],
- [],
- [
- new DomainException(
- 'MockAbstractPrimaryAuthenticationProvider returned an invalid username: <>'
- ),
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ return [
+ [
+ AuthenticationResponse::newPass( '<>' ),
+ ],
+ [],
+ [
+ new DomainException(
+ 'MockAbstractPrimaryAuthenticationProvider returned an invalid username: <>'
+ ),
+ ]
+ ];
+ },
],
'Secondary fail' => [
StatusValue::newGood(),
- [
- AuthenticationResponse::newPass( $userNamePlaceholder ),
- ],
- $tmp = [
- AuthenticationResponse::newFail( $this->message( 'fail-in-secondary' ) ),
- ],
- $tmp
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $tmp = [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-in-secondary' ) ),
+ ];
+ return [
+ [
+ AuthenticationResponse::newPass( $userNamePlaceholder ),
+ ],
+ $tmp,
+ $tmp
+ ];
+ },
],
'Secondary UI, then abstain' => [
StatusValue::newGood(),
- [
- AuthenticationResponse::newPass( $userNamePlaceholder ),
- ],
- [
- $tmp = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newAbstain()
- ],
- [
- $tmp,
- AuthenticationResponse::newPass( $userNamePlaceholder ),
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ AuthenticationResponse::newPass( $userNamePlaceholder ),
+ ],
+ [
+ $tmp,
+ AuthenticationResponse::newAbstain()
+ ],
+ [
+ $tmp,
+ AuthenticationResponse::newPass( $userNamePlaceholder ),
+ ]
+ ];
+ },
],
'Secondary pass' => [
StatusValue::newGood(),
- [
- AuthenticationResponse::newPass( $userNamePlaceholder ),
- ],
- [
- AuthenticationResponse::newPass()
- ],
- [
- AuthenticationResponse::newPass( $userNamePlaceholder ),
- ]
+ static function ( $testCase, $req, $userNamePlaceholder ) {
+ return [
+ [
+ AuthenticationResponse::newPass( $userNamePlaceholder ),
+ ],
+ [
+ AuthenticationResponse::newPass()
+ ],
+ [
+ AuthenticationResponse::newPass( $userNamePlaceholder ),
+ ]
+ ];
+ },
],
];
}
@@ -2246,24 +2281,19 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
/**
* @dataProvider provideAccountCreation
- * @param StatusValue $preTest
- * @param StatusValue $primaryTest
- * @param StatusValue $secondaryTest
- * @param array $primaryResponses
- * @param array $secondaryResponses
- * @param array $managerResponses
*/
public function testAccountCreation(
StatusValue $preTest, $primaryTest, $secondaryTest,
- array $primaryResponses, array $secondaryResponses, array $managerResponses
+ $responses
) {
$creator = $this->getTestSysop()->getUser();
$username = self::usernameForCreation();
$this->initializeManager();
+ $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
+ [ $primaryResponses, $secondaryResponses, $managerResponses ] = $responses( $this, $req );
// Set up lots of mocks...
- $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
$mocks = [];
foreach ( [ 'pre', 'primary', 'secondary' ] as $key ) {
$class = ucfirst( $key ) . 'AuthenticationProvider';
@@ -2533,122 +2563,166 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
->fetchField() );
}
- public function provideAccountCreation() {
- $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
+ public static function provideAccountCreation() {
$good = StatusValue::newGood();
return [
'Pre-creation test fail in pre' => [
StatusValue::newFatal( 'fail-from-pre' ), $good, $good,
- [],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'fail-from-pre' ) ),
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-pre' ) ),
+ ]
+ ];
+ },
],
'Pre-creation test fail in primary' => [
$good, StatusValue::newFatal( 'fail-from-primary' ), $good,
- [],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'fail-from-primary' ) ),
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-primary' ) ),
+ ]
+ ];
+ },
],
'Pre-creation test fail in secondary' => [
$good, $good, StatusValue::newFatal( 'fail-from-secondary' ),
- [],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'fail-from-secondary' ) ),
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-secondary' ) ),
+ ]
+ ];
+ },
],
'Failure in primary' => [
$good, $good, $good,
- $tmp = [
- AuthenticationResponse::newFail( $this->message( 'fail-from-primary' ) ),
- ],
- [],
- $tmp
+ static function ( $testCase, $req ) {
+ $tmp = [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-primary' ) ),
+ ];
+ return [
+ $tmp,
+ [],
+ $tmp
+ ];
+ },
],
'All primary abstain' => [
$good, $good, $good,
- [
- AuthenticationResponse::newAbstain(),
- ],
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'authmanager-create-no-primary' ) )
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [
+ AuthenticationResponse::newAbstain(),
+ ],
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'authmanager-create-no-primary' ) )
+ ]
+ ];
+ },
],
'Primary UI, then redirect, then fail' => [
$good, $good, $good,
- $tmp = [
- AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
- AuthenticationResponse::newFail( $this->message( 'fail-in-primary-continue' ) ),
- ],
- [],
- $tmp
+ static function ( $testCase, $req ) {
+ $tmp = [
+ AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) ),
+ AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
+ AuthenticationResponse::newFail( $testCase->message( 'fail-in-primary-continue' ) ),
+ ];
+ return [
+ $tmp,
+ [],
+ $tmp
+ ];
+ },
],
'Primary redirect, then abstain' => [
$good, $good, $good,
- [
+ static function ( $testCase, $req ) {
$tmp = AuthenticationResponse::newRedirect(
[ $req ], '/foo.html', [ 'foo' => 'bar' ]
- ),
- AuthenticationResponse::newAbstain(),
- ],
- [],
- [
- $tmp,
- new DomainException(
- 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAccountCreation() returned ABSTAIN'
- )
- ]
+ );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newAbstain(),
+ ],
+ [],
+ [
+ $tmp,
+ new DomainException(
+ 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAccountCreation() returned ABSTAIN'
+ )
+ ]
+ ];
+ },
],
'Primary UI, then pass; secondary abstain' => [
$good, $good, $good,
- [
- $tmp1 = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newPass(),
- ],
- [
- AuthenticationResponse::newAbstain(),
- ],
- [
- $tmp1,
- 'created' => AuthenticationResponse::newPass( '' ),
- ]
+ static function ( $testCase, $req ) {
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newPass(),
+ ],
+ [
+ AuthenticationResponse::newAbstain(),
+ ],
+ [
+ $tmp,
+ 'created' => AuthenticationResponse::newPass( '' ),
+ ]
+ ];
+ },
],
'Primary pass; secondary UI then pass' => [
$good, $good, $good,
- [
- AuthenticationResponse::newPass( '' ),
- ],
- [
- $tmp1 = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newPass( '' ),
- ],
- [
- 'created' => $tmp1,
- AuthenticationResponse::newPass( '' ),
- ]
+ static function ( $testCase, $req ) {
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ AuthenticationResponse::newPass( '' ),
+ ],
+ [
+ $tmp,
+ AuthenticationResponse::newPass( '' ),
+ ],
+ [
+ 'created' => $tmp,
+ AuthenticationResponse::newPass( '' ),
+ ]
+ ];
+ },
],
'Primary pass; secondary fail' => [
$good, $good, $good,
- [
- AuthenticationResponse::newPass(),
- ],
- [
- AuthenticationResponse::newFail( $this->message( '...' ) ),
- ],
- [
- 'created' => new DomainException(
- 'MockAbstractSecondaryAuthenticationProvider::beginSecondaryAccountCreation() returned FAIL. ' .
- 'Secondary providers are not allowed to fail account creation, ' .
- 'that should have been done via testForAccountCreation().'
- )
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [
+ AuthenticationResponse::newPass(),
+ ],
+ [
+ AuthenticationResponse::newFail( $testCase->message( '...' ) ),
+ ],
+ [
+ 'created' => new DomainException(
+ 'MockAbstractSecondaryAuthenticationProvider::beginSecondaryAccountCreation() returned FAIL. ' .
+ 'Secondary providers are not allowed to fail account creation, ' .
+ 'that should have been done via testForAccountCreation().'
+ )
+ ]
+ ];
+ },
],
];
}
@@ -3945,11 +4019,13 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
* @dataProvider provideAccountLink
*/
public function testAccountLink(
- StatusValue $preTest, array $primaryResponses, array $managerResponses
+ StatusValue $preTest, $responses
) {
$user = $this->getTestSysop()->getUser();
$this->initializeManager();
+ $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
+ [ $primaryResponses, $managerResponses ] = $responses( $this, $req );
// Set up lots of mocks...
$req = $this->getMockForAbstractClass( AuthenticationRequest::class );
@@ -4108,77 +4184,108 @@ class AuthManagerTest extends MediaWikiIntegrationTestCase {
$this->assertSame( $expectLog, $this->logger->getBuffer() );
}
- public function provideAccountLink() {
- $req = $this->getMockForAbstractClass( AuthenticationRequest::class );
+ public static function provideAccountLink() {
$good = StatusValue::newGood();
return [
'Pre-link test fail in pre' => [
StatusValue::newFatal( 'fail-from-pre' ),
- [],
- [
- AuthenticationResponse::newFail( $this->message( 'fail-from-pre' ) ),
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-pre' ) ),
+ ]
+ ];
+ },
],
'Failure in primary' => [
$good,
- $tmp = [
- AuthenticationResponse::newFail( $this->message( 'fail-from-primary' ) ),
- ],
- $tmp
+ static function ( $testCase, $req ) {
+ $tmp = [
+ AuthenticationResponse::newFail( $testCase->message( 'fail-from-primary' ) ),
+ ];
+ return [
+ $tmp,
+ $tmp
+ ];
+ },
],
'All primary abstain' => [
$good,
- [
- AuthenticationResponse::newAbstain(),
- ],
- [
- AuthenticationResponse::newFail( $this->message( 'authmanager-link-no-primary' ) )
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [
+ AuthenticationResponse::newAbstain(),
+ ],
+ [
+ AuthenticationResponse::newFail( $testCase->message( 'authmanager-link-no-primary' ) )
+ ]
+ ];
+ },
],
'Primary UI, then redirect, then fail' => [
$good,
- $tmp = [
- AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
- AuthenticationResponse::newFail( $this->message( 'fail-in-primary-continue' ) ),
- ],
- $tmp
+ static function ( $testCase, $req ) {
+ $tmp = [
+ AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) ),
+ AuthenticationResponse::newRedirect( [ $req ], '/foo.html', [ 'foo' => 'bar' ] ),
+ AuthenticationResponse::newFail( $testCase->message( 'fail-in-primary-continue' ) ),
+ ];
+ return [
+ $tmp,
+ $tmp
+ ];
+ },
],
'Primary redirect, then abstain' => [
$good,
- [
+ static function ( $testCase, $req ) {
$tmp = AuthenticationResponse::newRedirect(
[ $req ], '/foo.html', [ 'foo' => 'bar' ]
- ),
- AuthenticationResponse::newAbstain(),
- ],
- [
- $tmp,
- new DomainException(
- 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAccountLink() returned ABSTAIN'
- )
- ]
+ );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newAbstain(),
+ ],
+ [
+ $tmp,
+ new DomainException(
+ 'MockAbstractPrimaryAuthenticationProvider::continuePrimaryAccountLink() returned ABSTAIN'
+ )
+ ]
+ ];
+ },
],
'Primary UI, then pass' => [
$good,
- [
- $tmp1 = AuthenticationResponse::newUI( [ $req ], $this->message( '...' ) ),
- AuthenticationResponse::newPass(),
- ],
- [
- $tmp1,
- AuthenticationResponse::newPass( '' ),
- ]
+ static function ( $testCase, $req ) {
+ $tmp = AuthenticationResponse::newUI( [ $req ], $testCase->message( '...' ) );
+ return [
+ [
+ $tmp,
+ AuthenticationResponse::newPass(),
+ ],
+ [
+ $tmp,
+ AuthenticationResponse::newPass( '' ),
+ ]
+ ];
+ },
],
'Primary pass' => [
$good,
- [
- AuthenticationResponse::newPass( '' ),
- ],
- [
- AuthenticationResponse::newPass( '' ),
- ]
+ static function ( $testCase, $req ) {
+ return [
+ [
+ AuthenticationResponse::newPass( '' ),
+ ],
+ [
+ AuthenticationResponse::newPass( '' ),
+ ]
+ ];
+ },
],
];
}
diff --git a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
index 0dccc575204..0bebe01ab91 100644
--- a/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
+++ b/tests/phpunit/includes/auth/TemporaryPasswordPrimaryAuthenticationProviderTest.php
@@ -234,7 +234,7 @@ class TemporaryPasswordPrimaryAuthenticationProviderTest extends MediaWikiIntegr
$this->assertFalse( $result );
}
- public function provideTestUserCanAuthenticateErrorCases(): iterable {
+ public static function provideTestUserCanAuthenticateErrorCases(): iterable {
yield 'invalid user name' => [ '<invalid>' ];
yield 'nonexistent user' => [ 'DoesNotExist' ];
yield 'user with invalid password' => [
diff --git a/tests/phpunit/includes/jobqueue/JobFactoryTest.php b/tests/phpunit/includes/jobqueue/JobFactoryTest.php
index 388f4a84233..263fdde392d 100644
--- a/tests/phpunit/includes/jobqueue/JobFactoryTest.php
+++ b/tests/phpunit/includes/jobqueue/JobFactoryTest.php
@@ -37,14 +37,14 @@ class JobFactoryTest extends MediaWikiIntegrationTestCase {
$this->assertNotSame( $job, $job3, 'should not reuse instance' );
}
- public function provideTestNewJob() {
+ public static function provideTestNewJob() {
return [
'class name, no title' => [ 'NullJob', NullJob::class ],
'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
'closure' => [ static function ( Title $title, array $params ) {
return new NullJob( $params );
}, NullJob::class ],
- 'function' => [ [ $this, 'newNullJob' ], NullJob::class ],
+ 'function' => [ [ self::class, 'newNullJob' ], NullJob::class ],
'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
'object spec with no title and not subclass of GenericParameterJob' => [
@@ -63,7 +63,7 @@ class JobFactoryTest extends MediaWikiIntegrationTestCase {
];
}
- public function newNullJob( Title $title, array $params ) {
+ public static function newNullJob( Title $title, array $params ) {
return new NullJob( $params );
}
}
diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php
index 8070cf73ff0..981005c0e24 100644
--- a/tests/phpunit/includes/jobqueue/JobTest.php
+++ b/tests/phpunit/includes/jobqueue/JobTest.php
@@ -124,14 +124,14 @@ class JobTest extends MediaWikiIntegrationTestCase {
$this->assertNotSame( $job, $job3, 'should not reuse instance' );
}
- public function provideTestJobFactory() {
+ public static function provideTestJobFactory() {
return [
'class name, no title' => [ 'NullJob', NullJob::class ],
'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
'closure' => [ static function ( Title $title, array $params ) {
return new NullJob( $params );
}, NullJob::class ],
- 'function' => [ [ $this, 'newNullJob' ], NullJob::class ],
+ 'function' => [ [ self::class, 'newNullJob' ], NullJob::class ],
'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
'object spec with no title and not subclass of GenericParameterJob' => [
@@ -150,7 +150,7 @@ class JobTest extends MediaWikiIntegrationTestCase {
];
}
- public function newNullJob( Title $title, array $params ) {
+ public static function newNullJob( Title $title, array $params ) {
return new NullJob( $params );
}
diff --git a/tests/phpunit/includes/skins/SideBarTest.php b/tests/phpunit/includes/skins/SideBarTest.php
index 88d5d89eac8..0a0ef53cf98 100644
--- a/tests/phpunit/includes/skins/SideBarTest.php
+++ b/tests/phpunit/includes/skins/SideBarTest.php
@@ -15,9 +15,9 @@ class SideBarTest extends MediaWikiLangTestCase {
/** @var SkinTemplate */
private $skin;
/** @var string[][] Local cache for sidebar messages */
- private $messages;
+ private static $messages;
- private function initMessagesHref() {
+ private static function initMessagesHref() {
# List of default messages for the sidebar. The sidebar doesn't care at
# all whether they are full URLs, interwiki links or local titles.
$URL_messages = [
@@ -36,10 +36,10 @@ class SideBarTest extends MediaWikiLangTestCase {
foreach ( $URL_messages as $m ) {
$titleName = $messageCache->get( $m );
if ( MWHttpRequest::isValidURI( $titleName ) ) {
- $this->messages[$m]['href'] = $titleName;
+ self::$messages[$m]['href'] = $titleName;
} else {
$title = Title::newFromText( $titleName );
- $this->messages[$m]['href'] = $title->getLocalURL();
+ self::$messages[$m]['href'] = $title->getLocalURL();
}
}
}
@@ -51,8 +51,8 @@ class SideBarTest extends MediaWikiLangTestCase {
}
/** @return array */
- public function provideSidebars() {
- $this->initMessagesHref();
+ public static function provideSidebars() {
+ self::initMessagesHref();
return [
// sidebar with only two titles
[
@@ -69,7 +69,7 @@ class SideBarTest extends MediaWikiLangTestCase {
[ 'Title' => [
[
'text' => 'Help',
- 'href' => $this->messages['helppage']['href'],
+ 'href' => self::$messages['helppage']['href'],
'id' => 'n-help',
'icon' => 'help',
'active' => null
diff --git a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php b/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
index d531ae19ef6..aec9e83277e 100644
--- a/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
+++ b/tests/phpunit/includes/specialpage/SpecialPageFactoryTest.php
@@ -58,11 +58,11 @@ class SpecialPageFactoryTest extends MediaWikiIntegrationTestCase {
$this->assertSame( 1, $count );
}
- public function newSpecialAllPages() {
+ public static function newSpecialAllPages() {
return new SpecialAllPages();
}
- public function specialPageProvider() {
+ public static function specialPageProvider() {
$specialPageTestHelper = new SpecialPageTestHelper();
return [
@@ -70,7 +70,7 @@ class SpecialPageFactoryTest extends MediaWikiIntegrationTestCase {
'closure' => [ static function () {
return new SpecialAllPages();
}, false ],
- 'function' => [ [ $this, 'newSpecialAllPages' ], false ],
+ 'function' => [ [ self::class, 'newSpecialAllPages' ], false ],
'callback string' => [ SpecialPageTestHelper::class . '::newSpecialAllPages', false ],
'callback with object' => [
[ $specialPageTestHelper, 'newSpecialAllPages' ],
diff --git a/tests/phpunit/integration/includes/poolcounter/PoolCounterWorkTest.php b/tests/phpunit/integration/includes/poolcounter/PoolCounterWorkTest.php
index 99d787d1b3b..332d7b1f10f 100644
--- a/tests/phpunit/integration/includes/poolcounter/PoolCounterWorkTest.php
+++ b/tests/phpunit/integration/includes/poolcounter/PoolCounterWorkTest.php
@@ -76,13 +76,13 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
return TestingAccessWrapper::newFromObject( $worker );
}
- public function provideExecuteFlow() {
+ public static function provideExecuteFlow() {
yield "Not Cacheable and not skipCache should call acquireForMe" => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( 'StupidAction' ) )
+ 'acquireForMe' => self::returnValue( Status::newGood( 'StupidAction' ) )
], [], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
false
];
@@ -90,9 +90,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield "Not Cacheable and skipCache should call acquireForMe" => [
false, true,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( 'StupidAction' ) )
+ 'acquireForMe' => self::returnValue( Status::newGood( 'StupidAction' ) )
], [], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
false
];
@@ -100,9 +100,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield "Cacheable and not skipCache should call acquireForAnyone" => [
true, false,
[
- 'acquireForAnyone' => $this->returnValue( Status::newGood( 'StupidAction' ) )
+ 'acquireForAnyone' => self::returnValue( Status::newGood( 'StupidAction' ) )
], [], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
false
];
@@ -110,9 +110,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield "Cacheable and skipCache should call acquireForMe" => [
true, true,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( 'StupidAction' ) )
+ 'acquireForMe' => self::returnValue( Status::newGood( 'StupidAction' ) )
], [], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
false
];
@@ -120,11 +120,11 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If Fatal error call doWork and log error' => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newFatal( 'apierror' ) )
+ 'acquireForMe' => self::returnValue( Status::newFatal( 'apierror' ) )
], [
- 'doWork' => $this->returnValue( "SomeResults" )
+ 'doWork' => self::returnValue( "SomeResults" )
], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
"SomeResults"
];
@@ -136,10 +136,10 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If ' . $name . ' call doWork and return' => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( $acquireResult ) ),
- 'release' => $this->returnValue( null )
+ 'acquireForMe' => self::returnValue( Status::newGood( $acquireResult ) ),
+ 'release' => self::returnValue( null )
], [
- 'doWork' => $this->returnValue( "SomeResults" )
+ 'doWork' => self::returnValue( "SomeResults" )
], [],
"SomeResults"
];
@@ -148,9 +148,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If DONE and not chacheable call getCachedWork and return if OK' => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( PoolCounter::DONE ) ),
+ 'acquireForMe' => self::returnValue( Status::newGood( PoolCounter::DONE ) ),
], [
- 'getCachedWork' => $this->returnValue( "SomeResults" )
+ 'getCachedWork' => self::returnValue( "SomeResults" )
], [],
"SomeResults"
];
@@ -158,9 +158,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If DONE and chacheable call getCachedWork and return if OK' => [
true, false,
[
- 'acquireForAnyone' => $this->returnValue( Status::newGood( PoolCounter::DONE ) ),
+ 'acquireForAnyone' => self::returnValue( Status::newGood( PoolCounter::DONE ) ),
], [
- 'getCachedWork' => $this->returnValue( "SomeResults" )
+ 'getCachedWork' => self::returnValue( "SomeResults" )
], [],
"SomeResults"
];
@@ -168,12 +168,12 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If DONE and chacheable call getCachedWork and repeat if not OK' => [
true, false,
[
- 'acquireForAnyone' => $this->returnValue( Status::newGood( PoolCounter::DONE ) ),
- 'acquireForMe' => $this->returnValue( Status::newGood( PoolCounter::LOCKED ) ),
- 'release' => $this->returnValue( '' )
+ 'acquireForAnyone' => self::returnValue( Status::newGood( PoolCounter::DONE ) ),
+ 'acquireForMe' => self::returnValue( Status::newGood( PoolCounter::LOCKED ) ),
+ 'release' => self::returnValue( '' )
], [
- 'getCachedWork' => $this->returnValue( false ),
- 'doWork' => $this->returnValue( 'SomeResults' )
+ 'getCachedWork' => self::returnValue( false ),
+ 'doWork' => self::returnValue( 'SomeResults' )
], [],
"SomeResults"
];
@@ -185,9 +185,9 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If ' . $name . ' and not chacheable call fallback and return if OK' => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( $acquireResult ) ),
+ 'acquireForMe' => self::returnValue( Status::newGood( $acquireResult ) ),
], [
- 'fallback' => $this->returnValue( "SomeResults" )
+ 'fallback' => self::returnValue( "SomeResults" )
], [],
"SomeResults"
];
@@ -195,10 +195,10 @@ class PoolCounterWorkTest extends MediaWikiIntegrationTestCase {
yield 'If ' . $name . ' and not chacheable call fallback and log if not OK' => [
false, false,
[
- 'acquireForMe' => $this->returnValue( Status::newGood( $acquireResult ) ),
+ 'acquireForMe' => self::returnValue( Status::newGood( $acquireResult ) ),
], [
], [
- 'info' => $this->returnValue( null )
+ 'info' => self::returnValue( null )
],
false
];
diff --git a/tests/phpunit/structure/RestStructureTest.php b/tests/phpunit/structure/RestStructureTest.php
index 6806f1cb61f..abef2705c75 100644
--- a/tests/phpunit/structure/RestStructureTest.php
+++ b/tests/phpunit/structure/RestStructureTest.php
@@ -395,7 +395,7 @@ class RestStructureTest extends MediaWikiIntegrationTestCase {
}
}
- public function provideModuleDefinitionFiles() {
+ public static function provideModuleDefinitionFiles() {
$conf = MediaWikiServices::getInstance()->getMainConfig();
$entryPoint = TestingAccessWrapper::newFromClass( EntryPoint::class );
$routeFiles = $entryPoint->getRouteFiles( $conf );
diff --git a/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php b/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php
index 7d630ca5969..4fdd6e5ef9a 100644
--- a/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php
+++ b/tests/phpunit/unit/includes/api/ApiModuleManagerTest.php
@@ -41,11 +41,11 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
);
}
- public function newApiRsd( $main, $action ) {
+ public static function newApiRsd( $main, $action ) {
return new ApiRsd( $main, $action );
}
- public function addModuleProvider() {
+ public static function addModuleProvider() {
return [
'plain class' => [
'rsd',
@@ -58,7 +58,7 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
'rsd',
'action',
ApiRsd::class,
- [ $this, 'newApiRsd' ],
+ [ self::class, 'newApiRsd' ],
],
'with spec (class only)' => [
@@ -75,7 +75,7 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
'action',
[
'class' => ApiRsd::class,
- 'factory' => [ $this, 'newApiRsd' ],
+ 'factory' => [ self::class, 'newApiRsd' ],
],
null,
],
@@ -115,7 +115,7 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
$this->assertNotNull( $moduleManager->getModule( $name, $group, true ), 'getModule' );
}
- public function addModulesProvider() {
+ public static function addModulesProvider() {
return [
'empty' => [
[],
@@ -134,7 +134,7 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
[
'rsd' => [
'class' => ApiRsd::class,
- 'factory' => [ $this, 'newApiRsd' ],
+ 'factory' => [ self::class, 'newApiRsd' ],
],
'logout' => [
'class' => ApiLogout::class,
@@ -163,13 +163,13 @@ class ApiModuleManagerTest extends MediaWikiUnitTestCase {
$this->assertTrue( true ); // Don't mark the test as risky if $modules is empty
}
- public function getModuleProvider() {
+ public static function getModuleProvider() {
$modules = [
'disabled' => ApiDisabled::class,
'disabled2' => [ 'class' => ApiDisabled::class ],
'rsd' => [
'class' => ApiRsd::class,
- 'factory' => [ $this, 'newApiRsd' ],
+ 'factory' => [ self::class, 'newApiRsd' ],
],
'logout' => [
'class' => ApiLogout::class,
diff --git a/tests/phpunit/unit/includes/block/BlockUtilsTest.php b/tests/phpunit/unit/includes/block/BlockUtilsTest.php
index 33cbd04a85e..bbf0e0094b4 100644
--- a/tests/phpunit/unit/includes/block/BlockUtilsTest.php
+++ b/tests/phpunit/unit/includes/block/BlockUtilsTest.php
@@ -141,8 +141,8 @@ class BlockUtilsTest extends MediaWikiUnitTestCase {
);
}
- public function provideTestParseBlockTargetNonIpString() {
- $userIdentity = $this->createMock( UserIdentity::class );
+ public static function provideTestParseBlockTargetNonIpString() {
+ $userIdentity = UserIdentityValue::newRegistered( 42, 'DannyS712' );
yield 'Name returns a valid user' => [
'DannyS712',
$userIdentity,
diff --git a/tests/phpunit/unit/includes/mail/EmailUserTest.php b/tests/phpunit/unit/includes/mail/EmailUserTest.php
index 01cf063d155..c79033521cc 100644
--- a/tests/phpunit/unit/includes/mail/EmailUserTest.php
+++ b/tests/phpunit/unit/includes/mail/EmailUserTest.php
@@ -63,12 +63,62 @@ class EmailUserTest extends MediaWikiUnitTestCase {
* @dataProvider provideValidateTarget
*/
public function testValidateTarget(
- User $target,
- User $sender,
+ $targetSpec,
+ $senderSpec,
StatusValue $expected,
- ?UserOptionsLookup $userOptionsLookup = null,
- ?CentralIdLookup $centralIdLookup = null
+ ?array $userOptions = null,
+ ?int $senderCentralID = null
) {
+ if ( $targetSpec === 'anon' ) {
+ $target = $this->createMock( User::class );
+ $target->expects( $this->atLeastOnce() )->method( 'getId' )->willReturn( 0 );
+ $target->method( 'getUser' )->willReturnSelf();
+ } elseif ( $targetSpec === 'nonConfirmed' ) {
+ $target = $this->createMock( User::class );
+ $target->method( 'getId' )->willReturn( 1 );
+ $target->expects( $this->atLeastOnce() )->method( 'isEmailConfirmed' )->willReturn( false );
+ $target->method( 'getUser' )->willReturnSelf();
+ } elseif ( $targetSpec === 'cannotReceive' ) {
+ $target = $this->createMock( User::class );
+ $target->method( 'getId' )->willReturn( 1 );
+ $target->method( 'isEmailConfirmed' )->willReturn( true );
+ $target->expects( $this->atLeastOnce() )->method( 'canReceiveEmail' )->willReturn( false );
+ $target->method( 'getUser' )->willReturnSelf();
+ } else {
+ $target = $this->getValidTarget();
+ }
+ if ( $senderSpec === 'newbie' ) {
+ $sender = $this->createMock( User::class );
+ $sender->expects( $this->atLeastOnce() )->method( 'isNewbie' )->willReturn( true );
+ } else {
+ $sender = $this->createMock( User::class );
+ $sender->method( 'getUser' )->willReturnSelf();
+ }
+ if ( $userOptions !== null ) {
+ $userOptionsLookup = $this->createMock( UserOptionsLookup::class );
+ $optionName = array_key_first( $userOptions );
+ $optionValue = $userOptions[$optionName];
+ $userOptionsLookup->expects( $this->atLeastOnce() )
+ ->method( 'getOption' )
+ ->willReturnCallback(
+ function ( UserIdentity $user, string $option ) use ( $target, $optionName, $optionValue ) {
+ $this->assertSame( $target->getUser(), $user );
+ return $option === $optionName ? $optionValue : null;
+ }
+ );
+ } else {
+ $userOptionsLookup = null;
+ }
+ if ( $senderCentralID !== null ) {
+ $centralIdLookup = $this->createMock( CentralIdLookup::class );
+ $centralIdLookup->expects( $this->atLeastOnce() )
+ ->method( 'centralIdFromLocalUser' )
+ ->with( $sender )
+ ->willReturn( $senderCentralID );
+ } else {
+ $centralIdLookup = null;
+ }
+
$userFactory = $this->createMock( UserFactory::class );
$userFactory->method( 'newFromAuthority' )->willReturn( $sender );
$userFactory->method( 'newFromUserIdentity' )->willReturn( $target );
@@ -76,75 +126,38 @@ class EmailUserTest extends MediaWikiUnitTestCase {
$this->assertEquals( $expected, $emailUser->validateTarget( $target ) );
}
- public function provideValidateTarget(): Generator {
- $noopUserMock = $this->createMock( User::class );
- $noopUserMock->method( 'getUser' )->willReturnSelf();
- $validTarget = $this->getValidTarget();
-
- $anonTarget = $this->createMock( User::class );
- $anonTarget->expects( $this->atLeastOnce() )->method( 'getId' )->willReturn( 0 );
- $anonTarget->method( 'getUser' )->willReturnSelf();
- yield 'Target has user ID 0' => [ $anonTarget, $noopUserMock, StatusValue::newFatal( 'emailnotarget' ) ];
+ public static function provideValidateTarget(): Generator {
+ yield 'Target has user ID 0' => [ 'anon', 'noop', StatusValue::newFatal( 'emailnotarget' ) ];
- $emailNotConfirmedTarget = $this->createMock( User::class );
- $emailNotConfirmedTarget->method( 'getId' )->willReturn( 1 );
- $emailNotConfirmedTarget->expects( $this->atLeastOnce() )->method( 'isEmailConfirmed' )->willReturn( false );
- $emailNotConfirmedTarget->method( 'getUser' )->willReturnSelf();
yield 'Target does not have confirmed email' => [
- $emailNotConfirmedTarget,
- $noopUserMock,
+ 'nonConfirmed',
+ 'noop',
StatusValue::newFatal( 'noemailtext' )
];
- $cannotReceiveEmailsTarget = $this->createMock( User::class );
- $cannotReceiveEmailsTarget->method( 'getId' )->willReturn( 1 );
- $cannotReceiveEmailsTarget->method( 'isEmailConfirmed' )->willReturn( true );
- $cannotReceiveEmailsTarget->expects( $this->atLeastOnce() )->method( 'canReceiveEmail' )->willReturn( false );
- $cannotReceiveEmailsTarget->method( 'getUser' )->willReturnSelf();
yield 'Target cannot receive emails' => [
- $cannotReceiveEmailsTarget,
- $noopUserMock,
+ 'cannotReceive',
+ 'noop',
StatusValue::newFatal( 'nowikiemailtext' )
];
- $newbieSender = $this->createMock( User::class );
- $newbieSender->expects( $this->atLeastOnce() )->method( 'isNewbie' )->willReturn( true );
- $noNewbieEmailsOptionsLookup = $this->createMock( UserOptionsLookup::class );
- $noNewbieEmailsOptionsLookup->expects( $this->atLeastOnce() )
- ->method( 'getOption' )
- ->with( $validTarget, 'email-allow-new-users' )
- ->willReturn( false );
yield 'Target does not allow emails from newbie and sender is newbie' => [
- $validTarget,
- $newbieSender,
+ 'valid',
+ 'newbie',
StatusValue::newFatal( 'nowikiemailtext' ),
- $noNewbieEmailsOptionsLookup
+ [ 'email-allow-new-users' => false ],
];
$senderCentralID = 42;
- $muteListOptionsLookup = $this->createMock( UserOptionsLookup::class );
- $muteListOptionsLookup->expects( $this->atLeast( 2 ) )
- ->method( 'getOption' )
- ->willReturnCallback(
- function ( UserIdentity $user, string $option ) use ( $validTarget, $senderCentralID ) {
- $this->assertSame( $validTarget->getUser(), $user );
- return $option === 'email-blacklist' ? (string)$senderCentralID : null;
- }
- );
- $centralIdLookup = $this->createMock( CentralIdLookup::class );
- $centralIdLookup->expects( $this->atLeastOnce() )
- ->method( 'centralIdFromLocalUser' )
- ->with( $noopUserMock )
- ->willReturn( $senderCentralID );
yield 'Target muted the sender' => [
- $validTarget,
- $noopUserMock,
+ 'valid',
+ 'noop',
StatusValue::newFatal( 'nowikiemailtext' ),
- $muteListOptionsLookup,
- $centralIdLookup
+ [ 'email-blacklist' => (string)$senderCentralID ],
+ $senderCentralID
];
- yield 'Valid' => [ $validTarget, $noopUserMock, StatusValue::newGood() ];
+ yield 'Valid' => [ 'valid', 'noop', StatusValue::newGood() ];
}
/**
@@ -152,12 +165,19 @@ class EmailUserTest extends MediaWikiUnitTestCase {
* @dataProvider provideAuthorizeSend
*/
public function testAuthorizeSend(
- User $performerUser,
- StatusValue $expected,
+ $performerUserSpec,
+ $expected,
array $configOverrides = [],
array $hooks = [],
bool $expectDeprecation = false
) {
+ if ( is_callable( $performerUserSpec ) ) {
+ $performerUserSpec = $performerUserSpec( $this );
+ }
+ if ( is_callable( $expected ) ) {
+ $expected = $expected( $this );
+ }
+ $performerUser = $this->newMockUser( $performerUserSpec );
$userFactory = $this->createMock( UserFactory::class );
$userFactory->method( 'newFromAuthority' )->willReturn( $performerUser );
if ( $expectDeprecation ) {
@@ -171,12 +191,19 @@ class EmailUserTest extends MediaWikiUnitTestCase {
* @dataProvider provideCanSend
*/
public function testCanSend(
- User $performerUser,
- StatusValue $expected,
+ $performerUserSpec,
+ $expected,
array $configOverrides = [],
array $hooks = [],
bool $expectDeprecation = false
) {
+ if ( is_callable( $performerUserSpec ) ) {
+ $performerUserSpec = $performerUserSpec( $this );
+ }
+ if ( is_callable( $expected ) ) {
+ $expected = $expected( $this );
+ }
+ $performerUser = $this->newMockUser( $performerUserSpec );
$userFactory = $this->createMock( UserFactory::class );
$userFactory->method( 'newFromAuthority' )->willReturn( $performerUser );
if ( $expectDeprecation ) {
@@ -205,8 +232,8 @@ class EmailUserTest extends MediaWikiUnitTestCase {
return $user;
}
- public function provideCanSend(): Generator {
- $validSender = $this->newMockUser();
+ public static function provideCanSend(): Generator {
+ $validSender = [];
yield 'Emails disabled' => [
$validSender,
@@ -220,45 +247,45 @@ class EmailUserTest extends MediaWikiUnitTestCase {
[ MainConfigNames::EnableUserEmail => false ]
];
- $noEmailSender = $this->newMockUser( [ 'isEmailConfirmed' => false ] );
+ $noEmailSender = [ 'isEmailConfirmed' => false ];
yield 'Sender does not have an email' => [
$noEmailSender,
StatusValue::newFatal( 'mailnologin' )
];
- $notAllowedValidSender = $this->newMockUser( [
+ $notAllowedValidSender = [
'isAllowed' => false,
'isDefinitelyAllowed' => static function ( $user, StatusValue $status ) {
$status->fatal( 'badaccess' );
return false;
}
- ] );
+ ];
yield 'Sender is not allowed to send emails' => [
$notAllowedValidSender,
PermissionStatus::newFatal( 'badaccess' )
];
- $block = $this->createMock( AbstractBlock::class );
- $block->expects( $this->atLeastOnce() )
- ->method( 'appliesToRight' )
- ->with( 'sendemail' )
- ->willReturn( true );
-
- $blockedSender = $this->newMockUser( [
- 'getBlock' => $block,
- 'isDefinitelyAllowed' => static function ( $action, PermissionStatus $status )
- use ( $block ) {
- if ( $action === 'sendemail' ) {
- $status->setBlock( $block );
- return false;
- }
- return true;
- },
- ] );
-
- $blockedPermission = PermissionStatus::newEmpty();
- $blockedPermission->setBlock( $block );
+ $blockedSender = static function ( $testCase ) {
+ $block = $testCase->createMock( AbstractBlock::class );
+ return [
+ 'getBlock' => $block,
+ 'isDefinitelyAllowed' => static function ( $action, PermissionStatus $status ) use ( $block ) {
+ if ( $action === 'sendemail' ) {
+ $status->setBlock( $block );
+ return false;
+ }
+ return true;
+ },
+ ];
+ };
+
+ $blockedPermission = static function ( $testCase ) {
+ $block = $testCase->createMock( AbstractBlock::class );
+ $blockedPermission = PermissionStatus::newEmpty();
+ $blockedPermission->setBlock( $block );
+ return $blockedPermission;
+ };
yield 'Sender is blocked from emailing users' => [
$blockedSender,
@@ -303,8 +330,8 @@ class EmailUserTest extends MediaWikiUnitTestCase {
yield 'Successful' => [ $validSender, StatusValue::newGood() ];
}
- public function provideAuthorizeSend(): Generator {
- $ratelimitedSender = $this->newMockUser( [
+ public static function provideAuthorizeSend(): Generator {
+ $ratelimitedSender = [
'pingLimiter' => true,
'isDefinitelyAllowed' => static function ( $action, PermissionStatus $status ) {
if ( $action === 'sendemail' ) {
@@ -313,7 +340,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
return true;
}
- ] );
+ ];
$rateLimitStatus = PermissionStatus::newEmpty();
$rateLimitStatus->setRateLimitExceeded();
@@ -323,7 +350,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
$rateLimitStatus
];
- $validSender = $this->newMockUser();
+ $validSender = [];
$emailUserAuthorizeSendError = 'my-hook-error';
$emailUserAuthorizeSendHooks = [
@@ -346,12 +373,26 @@ class EmailUserTest extends MediaWikiUnitTestCase {
* @dataProvider provideSubmit
*/
public function testSubmit(
- User $target,
- Authority $sender,
+ string $targetSpec,
StatusValue $expected,
array $hooks = [],
- ?IEmailer $emailer = null
+ ?StatusValue $emailerStatus = null
) {
+ if ( $targetSpec === 'invalid' ) {
+ $target = $this->createMock( User::class );
+ $target->method( 'getId' )->willReturn( 0 );
+ $target->method( 'getUser' )->willReturnSelf();
+ } else {
+ $target = $this->getValidTarget();
+ }
+ $sender = $this->createMock( Authority::class );
+ if ( $emailerStatus !== null ) {
+ $emailer = $this->createMock( IEmailer::class );
+ $emailer->expects( $this->atLeastOnce() )->method( 'send' )->willReturn( $emailerStatus );
+ } else {
+ $emailer = null;
+ }
+
$userFactory = $this->createMock( UserFactory::class );
$userFactory->method( 'newFromUserIdentity' )
->with( $target )
@@ -367,14 +408,8 @@ class EmailUserTest extends MediaWikiUnitTestCase {
$this->assertEquals( $expected, $res );
}
- public function provideSubmit(): Generator {
- $validSender = $this->createMock( Authority::class );
- $validTarget = $this->getValidTarget();
-
- $invalidTarget = $this->createMock( User::class );
- $invalidTarget->method( 'getId' )->willReturn( 0 );
- $invalidTarget->method( 'getUser' )->willReturnSelf();
- yield 'Invalid target' => [ $invalidTarget, $validSender, StatusValue::newFatal( 'emailnotarget' ) ];
+ public static function provideSubmit(): Generator {
+ yield 'Invalid target' => [ 'invalid', StatusValue::newFatal( 'emailnotarget' ) ];
$hookStatusError = StatusValue::newFatal( 'some-hook-error' );
$emailUserHookUsingStatusHooks = [
@@ -384,8 +419,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserHook error as a Status' => [
- $validTarget,
- $validSender,
+ 'valid',
$hookStatusError,
$emailUserHookUsingStatusHooks
];
@@ -397,8 +431,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserHook error as boolean false' => [
- $validTarget,
- $validSender,
+ 'valid',
StatusValue::newFatal( 'hookaborted' ),
$emailUserHookUsingBooleanFalseHooks
];
@@ -410,8 +443,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserHook error as boolean true' => [
- $validTarget,
- $validSender,
+ 'valid',
StatusValue::newGood(),
$emailUserHookUsingBooleanTrueHooks
];
@@ -424,8 +456,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserHook error as array' => [
- $validTarget,
- $validSender,
+ 'valid',
StatusValue::newFatal( $hookError ),
$emailUserHookUsingArrayHooks
];
@@ -438,8 +469,7 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserHook error as MessageSpecifier' => [
- $validTarget,
- $validSender,
+ 'valid',
StatusValue::newFatal( $hookErrorMsg ),
$emailUserHookUsingMessageHooks
];
@@ -454,32 +484,25 @@ class EmailUserTest extends MediaWikiUnitTestCase {
}
];
yield 'EmailUserSendEmail error as a Status' => [
- $validTarget,
- $validSender,
+ 'valid',
StatusValue::newFatal( $emailUserSendEmailHookError ),
$emailUserHookUsingStatusHooks
];
$emailerErrorStatus = StatusValue::newFatal( 'emailer-error' );
- $errorEmailer = $this->createMock( IEmailer::class );
- $errorEmailer->expects( $this->atLeastOnce() )->method( 'send' )->willReturn( $emailerErrorStatus );
yield 'Error in the Emailer' => [
- $validTarget,
- $validSender,
+ 'valid',
$emailerErrorStatus,
[],
- $errorEmailer
+ $emailerErrorStatus
];
$emailerSuccessStatus = StatusValue::newGood( 42 );
- $successEmailer = $this->createMock( IEmailer::class );
- $successEmailer->expects( $this->atLeastOnce() )->method( 'send' )->willReturn( $emailerSuccessStatus );
yield 'Successful' => [
- $validTarget,
- $validSender,
+ 'valid',
$emailerSuccessStatus,
[],
- $successEmailer
+ $emailerSuccessStatus
];
}
diff --git a/tests/phpunit/unit/includes/watchlist/WatchedItemStoreUnitTest.php b/tests/phpunit/unit/includes/watchlist/WatchedItemStoreUnitTest.php
index 8c387d43d76..5d05a1eb276 100644
--- a/tests/phpunit/unit/includes/watchlist/WatchedItemStoreUnitTest.php
+++ b/tests/phpunit/unit/includes/watchlist/WatchedItemStoreUnitTest.php
@@ -360,15 +360,15 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertEquals( 12, $store->countWatchedItems( $user ) );
}
- public function provideTestPageFactory() {
+ public static function provideTestPageFactory() {
yield [ static function ( $pageId, $namespace, $dbKey ) {
return new TitleValue( $namespace, $dbKey );
} ];
yield [ static function ( $pageId, $namespace, $dbKey ) {
return new PageIdentityValue( $pageId, $namespace, $dbKey, PageIdentityValue::LOCAL );
} ];
- yield [ function ( $pageId, $namespace, $dbKey ) {
- return $this->makeMockTitle( $dbKey, [
+ yield [ static function ( $pageId, $namespace, $dbKey, $testCase ) {
+ return $testCase->makeMockTitle( $dbKey, [
'id' => $pageId,
'namespace' => $namespace
] );
@@ -379,7 +379,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
* @dataProvider provideTestPageFactory
*/
public function testCountWatchers( $testPageFactory ) {
- $titleValue = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $titleValue = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -419,9 +419,9 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testCountWatchersMultiple( $testPageFactory ) {
$titleValues = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 0, 'OtherDbKey' ),
- $testPageFactory( 102, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 0, 'OtherDbKey', $this ),
+ $testPageFactory( 102, 1, 'AnotherDbKey', $this ),
];
$mockDb = $this->getMockDb();
@@ -487,10 +487,10 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
];
}
- public function provideTestPageFactoryAndIntWithDbUnsafeVersion() {
- foreach ( $this->provideIntWithDbUnsafeVersion() as $dbint ) {
- foreach ( $this->provideTestPageFactory() as $testPageFactory ) {
- yield [ $dbint[0], $testPageFactory[0] ];
+ public static function provideTestPageFactoryAndIntWithDbUnsafeVersion() {
+ foreach ( self::provideIntWithDbUnsafeVersion() as [ $dbint ] ) {
+ foreach ( self::provideTestPageFactory() as [ $testPageFactory ] ) {
+ yield [ $dbint, $testPageFactory ];
}
}
}
@@ -500,9 +500,9 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testCountWatchersMultiple_withMinimumWatchers( $minWatchers, $testPageFactory ) {
$titleValues = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 0, 'OtherDbKey' ),
- $testPageFactory( 102, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 0, 'OtherDbKey', $this ),
+ $testPageFactory( 102, 1, 'AnotherDbKey', $this ),
];
$mockDb = $this->getMockDb();
@@ -570,7 +570,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
* @dataProvider provideTestPageFactory
*/
public function testCountVisitingWatchers( $testPageFactory ) {
- $titleValue = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $titleValue = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
@@ -613,9 +613,9 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testCountVisitingWatchersMultiple( $testPageFactory ) {
$titleValuesWithThresholds = [
- [ $testPageFactory( 100, 0, 'SomeDbKey' ), '111' ],
- [ $testPageFactory( 101, 0, 'OtherDbKey' ), '111' ],
- [ $testPageFactory( 102, 1, 'AnotherDbKey' ), '123' ],
+ [ $testPageFactory( 100, 0, 'SomeDbKey', $this ), '111' ],
+ [ $testPageFactory( 101, 0, 'OtherDbKey', $this ), '111' ],
+ [ $testPageFactory( 102, 1, 'AnotherDbKey', $this ), '123' ],
];
$dbResult = [
@@ -699,9 +699,9 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testCountVisitingWatchersMultiple_withMissingTargets( $testPageFactory ) {
$titleValuesWithThresholds = [
- [ $testPageFactory( 100, 0, 'SomeDbKey' ), '111' ],
- [ $testPageFactory( 101, 0, 'OtherDbKey' ), '111' ],
- [ $testPageFactory( 102, 1, 'AnotherDbKey' ), '123' ],
+ [ $testPageFactory( 100, 0, 'SomeDbKey', $this ), '111' ],
+ [ $testPageFactory( 101, 0, 'OtherDbKey', $this ), '111' ],
+ [ $testPageFactory( 102, 1, 'AnotherDbKey', $this ), '123' ],
[ new TitleValue( 0, 'SomeNotExisitingDbKey' ), null ],
[ new TitleValue( 0, 'OtherNotExisitingDbKey' ), null ],
];
@@ -791,9 +791,9 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testCountVisitingWatchersMultiple_withMinimumWatchers( $minWatchers, $testPageFactory ) {
$titleValuesWithThresholds = [
- [ $testPageFactory( 100, 0, 'SomeDbKey' ), '111' ],
- [ $testPageFactory( 101, 0, 'OtherDbKey' ), '111' ],
- [ $testPageFactory( 102, 1, 'AnotherDbKey' ), '123' ],
+ [ $testPageFactory( 100, 0, 'SomeDbKey', $this ), '111' ],
+ [ $testPageFactory( 101, 0, 'OtherDbKey', $this ), '111' ],
+ [ $testPageFactory( 102, 1, 'AnotherDbKey', $this ), '123' ],
];
$mockDb = $this->getMockDb();
@@ -942,8 +942,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$store = $this->newWatchedItemStore( [ 'db' => $mockDb ] );
$store->duplicateEntry(
- $testPageFactory( 100, 0, 'Old_Title' ),
- $testPageFactory( 101, 0, 'New_Title' )
+ $testPageFactory( 100, 0, 'Old_Title', $this ),
+ $testPageFactory( 101, 0, 'New_Title', $this )
);
}
@@ -986,8 +986,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
] );
$store->duplicateEntry(
- $testPageFactory( 100, 0, 'Old_Title' ),
- $testPageFactory( 101, 0, 'New_Title' )
+ $testPageFactory( 100, 0, 'Old_Title', $this ),
+ $testPageFactory( 101, 0, 'New_Title', $this )
);
}
@@ -1029,27 +1029,18 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$store = $this->newWatchedItemStore( [ 'db' => $mockDb, 'cache' => $mockCache ] );
$store->duplicateAllAssociatedEntries(
- $testPageFactory( 100, 0, 'Old_Title' ),
- $testPageFactory( 101, 0, 'New_Title' )
+ $testPageFactory( 100, 0, 'Old_Title', $this ),
+ $testPageFactory( 101, 0, 'New_Title', $this )
);
}
- public function provideLinkTargetPairs() {
- foreach ( $this->provideTestPageFactory() as $testPageFactoryArray ) {
- $testPageFactory = $testPageFactoryArray[0];
- yield [ $testPageFactory( 100, 0, 'Old_Title' ), $testPageFactory( 101, 0, 'New_Title' ) ];
- }
- }
-
/**
- * @param LinkTarget|PageIdentity $oldTarget
- * @param LinkTarget|PageIdentity $newTarget
- * @dataProvider provideLinkTargetPairs
+ * @dataProvider provideTestPageFactory
*/
- public function testDuplicateAllAssociatedEntries_somethingToDuplicate(
- $oldTarget,
- $newTarget
- ) {
+ public function testDuplicateAllAssociatedEntries_somethingToDuplicate( $testPageFactory ) {
+ $oldTarget = $testPageFactory( 100, 0, 'Old_Title', $this );
+ $newTarget = $testPageFactory( 101, 0, 'New_Title', $this );
+
$fakeRows = [
(object)[
'wl_user' => '1',
@@ -1169,7 +1160,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$store->addWatch(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'Some_Page' )
+ $testPageFactory( 100, 0, 'Some_Page', $this )
);
$this->assertSame(
@@ -1196,7 +1187,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$store->addWatch(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'Some_Page' )
+ $testPageFactory( 100, 0, 'Some_Page', $this )
);
$this->assertSame(
0,
@@ -1219,7 +1210,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->addWatchBatchForUser(
new UserIdentityValue( 1, 'MockUser' ),
- [ $testPageFactory( 100, 0, 'Some_Page' ), $testPageFactory( 101, 1, 'Some_Page' ) ]
+ [ $testPageFactory( 100, 0, 'Some_Page', $this ), $testPageFactory( 101, 1, 'Some_Page', $this ) ]
)
);
}
@@ -1269,7 +1260,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertTrue(
$store->addWatchBatchForUser(
$mockUser,
- [ $testPageFactory( 100, 0, 'Some_Page' ), $testPageFactory( 101, 1, 'Some_Page' ) ]
+ [ $testPageFactory( 100, 0, 'Some_Page', $this ), $testPageFactory( 101, 1, 'Some_Page', $this ) ]
)
);
$this->assertSame(
@@ -1293,7 +1284,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->addWatchBatchForUser(
new UserIdentityValue( 0, 'AnonUser' ),
- [ $testPageFactory( 100, 0, 'Other_Page' ) ]
+ [ $testPageFactory( 100, 0, 'Other_Page', $this ) ]
)
);
$this->assertSame(
@@ -1373,7 +1364,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$watchedItem = $store->loadWatchedItem(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
);
$this->assertInstanceOf( WatchedItem::class, $watchedItem );
$this->assertSame( 1, $watchedItem->getUserIdentity()->getId() );
@@ -1406,7 +1397,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->loadWatchedItem(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1430,7 +1421,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->loadWatchedItem(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1478,7 +1469,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertTrue(
$store->removeWatch(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1510,7 +1501,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->removeWatch(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1534,7 +1525,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->removeWatch(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1601,7 +1592,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$watchedItem = $store->getWatchedItem(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
);
$this->assertInstanceOf( WatchedItem::class, $watchedItem );
$this->assertSame( 1, $watchedItem->getUserIdentity()->getId() );
@@ -1619,7 +1610,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
->method( 'selectRow' );
$mockUser = new UserIdentityValue( 1, 'MockUser' );
- $linkTarget = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $linkTarget = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$cachedItem = new WatchedItem( $mockUser, $linkTarget, '20151212010101' );
$mockCache = $this->getMockCache( [ 'get' ] );
@@ -1691,7 +1682,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->getWatchedItem(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
@@ -1717,7 +1708,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->getWatchedItem(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
$this->assertSame(
@@ -1981,7 +1972,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertTrue(
$store->isWatched(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
}
@@ -2031,7 +2022,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->isWatched(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
}
@@ -2051,7 +2042,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->isWatched(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
}
@@ -2061,8 +2052,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testGetNotificationTimestampsBatch( $testPageFactory ) {
$targets = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 1, 'AnotherDbKey', $this ),
];
$mockDb = $this->getMockDb();
@@ -2127,7 +2118,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testGetNotificationTimestampsBatch_notWatchedTarget( $testPageFactory ) {
$targets = [
- $testPageFactory( 100, 0, 'OtherDbKey' ),
+ $testPageFactory( 100, 0, 'OtherDbKey', $this ),
];
$mockDb = $this->getMockDb();
@@ -2175,8 +2166,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testGetNotificationTimestampsBatch_cachedItem( $testPageFactory ) {
$targets = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 1, 'AnotherDbKey', $this ),
];
$user = new UserIdentityValue( 1, 'MockUser' );
@@ -2236,8 +2227,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testGetNotificationTimestampsBatch_allItemsCached( $testPageFactory ) {
$targets = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 1, 'AnotherDbKey', $this ),
];
$user = new UserIdentityValue( 1, 'MockUser' );
@@ -2276,8 +2267,8 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testGetNotificationTimestampsBatch_anonymousUser( $testPageFactory ) {
$targets = [
- $testPageFactory( 100, 0, 'SomeDbKey' ),
- $testPageFactory( 101, 1, 'AnotherDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
+ $testPageFactory( 101, 1, 'AnotherDbKey', $this ),
];
$mockDb = $this->createNoOpMock( IDatabase::class );
@@ -2311,7 +2302,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$this->assertFalse(
$store->resetNotificationTimestamp(
new UserIdentityValue( 0, 'AnonUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' )
+ $testPageFactory( 100, 0, 'SomeDbKey', $this )
)
);
}
@@ -2355,7 +2346,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$user = new UserIdentityValue( 1, 'MockUser' );
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$store = $this->newWatchedItemStore( [
'db' => $mockDb,
@@ -2375,7 +2366,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testResetNotificationTimestamp_item( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -2458,7 +2449,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testResetNotificationTimestamp_noItemForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->never() )
@@ -2528,7 +2519,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_oldidSpecifiedLatestRevisionForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeTitle' );
+ $title = $testPageFactory( 100, 0, 'SomeTitle', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->never() )
@@ -2594,7 +2585,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_oldidSpecifiedNotLatestRevisionForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockRevision = $this->createNoOpMock( RevisionRecord::class );
$mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
@@ -2702,7 +2693,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_notWatchedPageForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -2801,7 +2792,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_futureNotificationTimestampForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -2909,7 +2900,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_futureNotificationTimestampNotForced( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -3063,7 +3054,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testSetNotificationTimestampsForUser_specificTargets( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$timestamp = '20100101010101';
- $targets = [ $testPageFactory( 100, 0, 'Foo' ), $testPageFactory( 101, 0, 'Bar' ) ];
+ $targets = [ $testPageFactory( 100, 0, 'Foo', $this ), $testPageFactory( 101, 0, 'Bar', $this ) ];
$mockDb = $this->getMockDb();
$mockDb->expects( $this->once() )
@@ -3164,7 +3155,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
[ 2, 3 ],
$store->updateNotificationTimestamp(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
'20151212010101'
)
);
@@ -3214,7 +3205,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
$watchers = $store->updateNotificationTimestamp(
new UserIdentityValue( 1, 'MockUser' ),
- $testPageFactory( 100, 0, 'SomeDbKey' ),
+ $testPageFactory( 100, 0, 'SomeDbKey', $this ),
'20151212010101'
);
$this->assertSame( [], $watchers );
@@ -3225,7 +3216,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
*/
public function testUpdateNotificationTimestamp_clearsCachedItems( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
- $titleValue = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $titleValue = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$mockDb = $this->getMockDb();
$mockDb->method( 'timestamp' )
@@ -3438,7 +3429,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase {
public function testResetNotificationTimestamp_stashItemTypeCheck( $testPageFactory ) {
$user = new UserIdentityValue( 1, 'MockUser' );
$oldid = 22;
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$stash = new HashBagOStuff;
$mockRevision = $this->createNoOpMock( RevisionRecord::class );
$mockNextRevision = $this->createNoOpMock( RevisionRecord::class );
diff --git a/tests/phpunit/unit/includes/watchlist/WatchlistManagerUnitTest.php b/tests/phpunit/unit/includes/watchlist/WatchlistManagerUnitTest.php
index 11f6d457138..c9738c30ea6 100644
--- a/tests/phpunit/unit/includes/watchlist/WatchlistManagerUnitTest.php
+++ b/tests/phpunit/unit/includes/watchlist/WatchlistManagerUnitTest.php
@@ -235,15 +235,15 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
$manager->clearAllUserNotifications( $authority );
}
- public function provideTestPageFactory() {
+ public static function provideTestPageFactory() {
yield [ static function ( $pageId, $namespace, $dbKey ) {
return new TitleValue( $namespace, $dbKey );
} ];
yield [ static function ( $pageId, $namespace, $dbKey ) {
return new PageIdentityValue( $pageId, $namespace, $dbKey, PageIdentityValue::LOCAL );
} ];
- yield [ function ( $pageId, $namespace, $dbKey ) {
- return $this->makeMockTitle( $dbKey, [
+ yield [ static function ( $pageId, $namespace, $dbKey, $testCase ) {
+ return $testCase->makeMockTitle( $dbKey, [
'id' => $pageId,
'namespace' => $namespace
] );
@@ -257,7 +257,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
// ********** Code path #1 **********
// Early return: read only mode
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$userIdentity = new UserIdentityValue( 100, 'User Name' );
[ $authority, ] = $this->getAuthorityAndUserFactory( $userIdentity );
@@ -282,7 +282,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
// ********** Code path #2 **********
// Early return: User lacks `editmywatchlist`
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$userIdentity = new UserIdentityValue( 100, 'User Name' );
[ $authority, $userFactory ] = $this->getAuthorityAndUserFactory( $userIdentity );
@@ -307,7 +307,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
// ********** Code path #3 **********
// Early return: config with OPTION_ENOTIF false
- $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' );
+ $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere', $this );
$userIdentity = new UserIdentityValue( 100, 'User Name' );
[ $authority, $userFactory ] = $this->getAuthorityAndUserFactory(
@@ -335,7 +335,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
// ********** Code path #4 **********
// Early return: user is not registered
- $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' );
+ $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere', $this );
$options = [
WatchlistManager::OPTION_ENOTIF => true,
@@ -368,7 +368,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
// ********** Code path #5 **********
// No early returns; resetNotificationTimestamp is called
- $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere' );
+ $title = $testPageFactory( 100, NS_USER_TALK, 'PageTitleGoesHere', $this );
$options = [
WatchlistManager::OPTION_ENOTIF => true,
@@ -403,7 +403,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
$userIdentity = new UserIdentityValue( 0, 'User Name' );
- $title = $testPageFactory( 100, 0, 'SomeDbKey' );
+ $title = $testPageFactory( 100, 0, 'SomeDbKey', $this );
$manager = $this->getManager();
@@ -426,7 +426,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
$userIdentity = new UserIdentityValue( 100, 'User Name' );
- $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere' );
+ $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere', $this );
$watchedItem = $this->createMock( WatchedItem::class );
$watchedItem->expects( $this->once() )
@@ -473,7 +473,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
$userIdentity = new UserIdentityValue( 100, 'User Name' );
- $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere' );
+ $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere', $this );
$watchedItem = $this->createMock( WatchedItem::class );
$watchedItem->expects( $this->once() )
@@ -504,7 +504,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase {
$userIdentity = new UserIdentityValue( 100, 'User Name' );
- $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere' );
+ $title = $testPageFactory( 100, NS_MAIN, 'Page_db_Key_goesHere', $this );
$watchedItemStore = $this->createMock( WatchedItemStoreInterface::class );
$watchedItemStore->expects( $this->once() )
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:32 AM (18 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227536
Default Alt Text
(90 KB)
Attached To
Mode
rMW mediawiki
Attached
Detach File
Event Timeline
Log In to Comment