diff options
author | jenkins-bot <jenkins-bot@gerrit.wikimedia.org> | 2021-04-23 14:43:04 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@wikimedia.org> | 2021-04-23 14:43:04 +0000 |
commit | 89b00fcfbe966092f405f0cc939eb6f052cf2a2b (patch) | |
tree | 436842e3898b57ceb305807d5aa1a1ea26374078 /tests/phpunit/unit/includes | |
parent | b95a07380a64e72581a8bf41f466f58a1901ecb1 (diff) | |
parent | c1ee8250e9bc9c9c3161ca0ded3946fd2af1da7d (diff) | |
download | mediawikicore-89b00fcfbe966092f405f0cc939eb6f052cf2a2b.tar.gz mediawikicore-89b00fcfbe966092f405f0cc939eb6f052cf2a2b.zip |
Merge "Remove unnecessary ->equalTo() from tests"
Diffstat (limited to 'tests/phpunit/unit/includes')
10 files changed, 42 insertions, 82 deletions
diff --git a/tests/phpunit/unit/includes/Permissions/PermissionManagerTest.php b/tests/phpunit/unit/includes/Permissions/PermissionManagerTest.php index 6b3dea05bd5c..52fe17df3d79 100644 --- a/tests/phpunit/unit/includes/Permissions/PermissionManagerTest.php +++ b/tests/phpunit/unit/includes/Permissions/PermissionManagerTest.php @@ -204,7 +204,7 @@ class PermissionManagerTest extends MediaWikiUnitTestCase { if ( $isRedirect ) { $target = $this->createMock( Title::class ); $target->method( 'inNamespace' ) - ->with( $this->equalTo( NS_USER ) ) + ->with( NS_USER ) ->willReturn( $targetNamespace === NS_USER ); $target->method( 'getText' )->willReturn( $targetText ); @@ -219,7 +219,7 @@ class PermissionManagerTest extends MediaWikiUnitTestCase { $revisionLookup = $this->createMock( RevisionLookup::class ); $revisionLookup->method( 'getRevisionByTitle' ) - ->with( $this->equalTo( $title ) ) + ->with( $title ) ->willReturn( $revisionRecord ); $permissionManager = $this->getPermissionManager( [ @@ -274,7 +274,7 @@ class PermissionManagerTest extends MediaWikiUnitTestCase { $title = $this->createMock( Title::class ); $title->expects( $this->once() ) ->method( 'getRestrictions' ) - ->with( $this->equalTo( $action ) ) + ->with( $action ) ->willReturn( $restrictions ); $title->method( 'areRestrictionsCascading' )->willReturn( $cascading ); diff --git a/tests/phpunit/unit/includes/Storage/RevertedTagUpdateTest.php b/tests/phpunit/unit/includes/Storage/RevertedTagUpdateTest.php index c8cbc01ae565..649f9021cce2 100644 --- a/tests/phpunit/unit/includes/Storage/RevertedTagUpdateTest.php +++ b/tests/phpunit/unit/includes/Storage/RevertedTagUpdateTest.php @@ -150,7 +150,7 @@ class RevertedTagUpdateTest extends MediaWikiUnitTestCase { $logger = $this->createMock( LoggerInterface::class ); $logger->expects( $this->once() ) ->method( $method ) - ->with( $this->equalTo( $message ) ); + ->with( $message ); return $logger; } diff --git a/tests/phpunit/unit/includes/api/ApiUnblockTest.php b/tests/phpunit/unit/includes/api/ApiUnblockTest.php index e78240f08763..6e1cf58270a2 100644 --- a/tests/phpunit/unit/includes/api/ApiUnblockTest.php +++ b/tests/phpunit/unit/includes/api/ApiUnblockTest.php @@ -86,10 +86,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $blockPermissionCheckerFactory = $this->createMock( BlockPermissionCheckerFactory::class ); $blockPermissionCheckerFactory->expects( $this->once() ) ->method( 'newBlockPermissionChecker' ) - ->with( - $this->equalTo( $target ), - $this->equalTo( $performer ) - ) + ->with( $target, $performer ) ->willReturn( $blockPermissionChecker ); return $blockPermissionCheckerFactory; @@ -105,12 +102,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $unblockUserFactory = $this->createMock( UnblockUserFactory::class ); $unblockUserFactory->expects( $this->once() ) ->method( 'newUnblockUser' ) - ->with( - $this->equalTo( $target ), - $this->equalTo( $performer ), - $this->equalTo( $reason ), - $this->equalTo( $tags ) - ) + ->with( $target, $performer, $reason, $tags ) ->willReturn( $unblockUser ); return $unblockUserFactory; @@ -148,12 +140,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $testException = new Exception( 'Error should be thrown in requireOnlyOneParameter' ); $apiUnblock->method( 'requireOnlyOneParameter' ) - ->with( - $this->equalTo( $requestParams ), - $this->equalTo( 'id' ), - $this->equalTo( 'user' ), - $this->equalTo( 'userid' ) - ) + ->with( $requestParams, 'id', 'user', 'userid' ) ->will( $this->throwException( $testException ) ); $this->expectException( Exception::class ); @@ -168,9 +155,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $args['performer']->expects( $this->once() ) ->method( 'isAllowed' ) - ->with( - $this->equalTo( 'block' ) - ) + ->with( 'block' ) ->willReturn( false ); $requestParams = [ 'actual contents are not used in this test' ]; @@ -184,10 +169,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $testException = new Exception( 'Error should be thrown in dieWithError' ); $apiUnblock->method( 'dieWithError' ) - ->with( - $this->equalTo( 'apierror-permissiondenied-unblock' ), - $this->equalTo( 'permissiondenied' ) - ) + ->with( 'apierror-permissiondenied-unblock', 'permissiondenied' ) ->will( $this->throwException( $testException ) ); $this->expectException( Exception::class ); @@ -203,10 +185,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $args['userCache']->expects( $this->once() ) ->method( 'getProp' ) - ->with( - $this->equalTo( 'userIdGoesHere' ), - $this->equalTo( 'name' ) - ) + ->with( 'userIdGoesHere', 'name' ) ->willReturn( false ); $requestParams = [ 'userid' => 'userIdGoesHere' ]; @@ -220,10 +199,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $testException = new Exception( 'Error should be thrown in dieWithError' ); $apiUnblock->method( 'dieWithError' ) - ->with( - $this->equalTo( [ 'apierror-nosuchuserid', 'userIdGoesHere' ] ), - $this->equalTo( 'nosuchuserid' ) - ) + ->with( [ 'apierror-nosuchuserid', 'userIdGoesHere' ], 'nosuchuserid' ) ->will( $this->throwException( $testException ) ); $this->expectException( Exception::class ); @@ -252,10 +228,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { // Also includes the test of the codepath where UserCache is used and works $args['userCache']->expects( $this->once() ) ->method( 'getProp' ) - ->with( - $this->equalTo( 'userIdGoesHere' ), - $this->equalTo( 'name' ) - ) + ->with( 'userIdGoesHere', 'name' ) ->willReturn( 'userNameOfTargetFromCache' ); $badStatus = Status::newFatal( 'bad status' ); @@ -283,7 +256,7 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $testException = new Exception( 'Error should be thrown in dieStatus' ); $apiUnblock->method( 'dieStatus' ) - ->with( $this->equalTo( $badStatus ) ) + ->with( $badStatus ) ->will( $this->throwException( $testException ) ); $this->expectException( Exception::class ); @@ -300,14 +273,14 @@ class ApiUnblockTest extends MediaWikiUnitTestCase { $apiResult->expects( $this->once() ) ->method( 'addValue' ) ->with( - $this->equalTo( null ), - $this->equalTo( $args['action'] ), - $this->equalTo( [ + null, + $args['action'], + [ 'id' => 678, // block id 'user' => 'targetNameGoesHere', // target name 'userid' => 123, // target user id 'reason' => 'reasonGoesHere', // reason in $requestParams - ] ) + ] ) ->willReturn( true ); $args['apiMain']->method( 'getResult' )->willReturn( $apiResult ); diff --git a/tests/phpunit/unit/includes/block/BlockUtilsTest.php b/tests/phpunit/unit/includes/block/BlockUtilsTest.php index 5f2e500f2c19..6920d7f7143c 100644 --- a/tests/phpunit/unit/includes/block/BlockUtilsTest.php +++ b/tests/phpunit/unit/includes/block/BlockUtilsTest.php @@ -91,10 +91,7 @@ class BlockUtilsTest extends MediaWikiUnitTestCase { $userFactory = $this->createMock( UserFactory::class ); $userFactory->expects( $this->once() ) ->method( 'newFromName' ) - ->with( - $this->equalTo( $ip ), - $this->equalTo( UserFactory::RIGOR_NONE ) - ) + ->with( $ip, UserFactory::RIGOR_NONE ) ->willReturn( $user ); $blockUtils = $this->getUtils( [], $userFactory ); @@ -137,9 +134,7 @@ class BlockUtilsTest extends MediaWikiUnitTestCase { $userFactory = $this->createMock( UserFactory::class ); $userFactory->expects( $this->once() ) ->method( 'newFromName' ) - ->with( - $this->equalTo( $baseName ) - ) + ->with( $baseName ) ->willReturn( $userFactoryResult ); $blockUtils = $this->getUtils( [], $userFactory ); $this->assertSame( diff --git a/tests/phpunit/unit/includes/editpage/Constraint/AutoSummaryMissingSummaryConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/AutoSummaryMissingSummaryConstraintTest.php index 66c3f67d3f6d..d9d395e02142 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/AutoSummaryMissingSummaryConstraintTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/AutoSummaryMissingSummaryConstraintTest.php @@ -36,7 +36,7 @@ class AutoSummaryMissingSummaryConstraintTest extends MediaWikiUnitTestCase { $newContent = $this->createMock( Content::class ); $newContent->expects( $this->once() ) ->method( 'equals' ) - ->with( $this->equalTo( $originalContent ) ) + ->with( $originalContent ) ->willReturn( false ); $newContent->expects( $this->once() ) ->method( 'isRedirect' ) @@ -56,7 +56,7 @@ class AutoSummaryMissingSummaryConstraintTest extends MediaWikiUnitTestCase { $newContent = $this->createMock( Content::class ); $newContent->expects( $this->once() ) ->method( 'equals' ) - ->with( $this->equalTo( $originalContent ) ) + ->with( $originalContent ) ->willReturn( false ); $newContent->expects( $this->once() ) ->method( 'isRedirect' ) diff --git a/tests/phpunit/unit/includes/editpage/Constraint/ContentModelChangeConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/ContentModelChangeConstraintTest.php index e133de1bbead..47fbf79f76a5 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/ContentModelChangeConstraintTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/ContentModelChangeConstraintTest.php @@ -47,7 +47,7 @@ class ContentModelChangeConstraintTest extends MediaWikiUnitTestCase { ->willReturn( 'differentStartingContentModel' ); $title->expects( $this->once() ) ->method( 'setContentModel' ) - ->with( $this->equalTo( $newContentModel ) ); + ->with( $newContentModel ); $performer = $this->mockRegisteredAuthorityWithPermissions( [ 'edit', 'editcontentmodel' ] ); $constraint = new ContentModelChangeConstraint( @@ -83,7 +83,7 @@ class ContentModelChangeConstraintTest extends MediaWikiUnitTestCase { ->willReturn( 'differentStartingContentModel' ); $title->expects( $this->once() ) ->method( 'setContentModel' ) - ->with( $this->equalTo( $newContentModel ) ); + ->with( $newContentModel ); $performer = $this->mockRegisteredAuthority( function ( string $permission, diff --git a/tests/phpunit/unit/includes/editpage/Constraint/SelfRedirectConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/SelfRedirectConstraintTest.php index 4fae9832e850..d782cae86fe4 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/SelfRedirectConstraintTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/SelfRedirectConstraintTest.php @@ -42,7 +42,7 @@ class SelfRedirectConstraintTest extends MediaWikiUnitTestCase { ->willReturn( $contentRedirectTarget ); $contentRedirectTarget->expects( $this->once() ) ->method( 'equals' ) - ->with( $this->equalTo( $title ) ) + ->with( $title ) ->willReturn( $isSelfRedirect ); return $content; } diff --git a/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php b/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php index 8fabbb94703c..ce39e9869490 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/SpamRegexConstraintTest.php @@ -42,13 +42,13 @@ class SpamRegexConstraintTest extends MediaWikiUnitTestCase { $spamChecker = $this->createMock( SpamChecker::class ); $spamChecker->expects( $this->once() ) ->method( 'checkSummary' ) - ->with( $this->equalTo( $summary ) ) + ->with( $summary ) ->willReturn( false ); $spamChecker->expects( $this->exactly( 2 ) ) ->method( 'checkContent' ) ->withConsecutive( - [ $this->equalTo( $sectionHeading ) ], - [ $this->equalTo( $text ) ] + [ $sectionHeading ], + [ $text ] ) ->willReturn( false ); @@ -80,7 +80,7 @@ class SpamRegexConstraintTest extends MediaWikiUnitTestCase { $spamChecker = $this->createMock( SpamChecker::class ); $spamChecker->expects( $this->once() ) ->method( 'checkSummary' ) - ->with( $this->equalTo( $summary ) ) + ->with( $summary ) ->willReturn( $matchingText ); $prefixedDBKey = 'PrefixedDBKeyGoesHere'; diff --git a/tests/phpunit/unit/includes/libs/SamplingStatsdClientTest.php b/tests/phpunit/unit/includes/libs/SamplingStatsdClientTest.php index 7bd161156dcf..6de10c0337b5 100644 --- a/tests/phpunit/unit/includes/libs/SamplingStatsdClientTest.php +++ b/tests/phpunit/unit/includes/libs/SamplingStatsdClientTest.php @@ -15,10 +15,10 @@ class SamplingStatsdClientTest extends PHPUnit\Framework\TestCase { */ public function testSampling( $data, $sampleRate, $seed, $expectWrite ) { $sender = $this->getMockBuilder( SenderInterface::class )->getMock(); - $sender->expects( $this->any() )->method( 'open' )->will( $this->returnValue( true ) ); + $sender->method( 'open' )->willReturn( true ); if ( $expectWrite ) { $sender->expects( $this->once() )->method( 'write' ) - ->with( $this->anything(), $this->equalTo( $data ) ); + ->with( $this->anything(), $data ); } else { $sender->expects( $this->never() )->method( 'write' ); } @@ -62,9 +62,9 @@ class SamplingStatsdClientTest extends PHPUnit\Framework\TestCase { $nonMatching->setValue( 1 ); $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 ) ); + $sender->method( 'open' )->willReturn( true ); + $sender->expects( $this->once() )->method( 'write' ) + ->with( $this->anything(), $nonMatching ); $client = new SamplingStatsdClient( $sender ); $client->setSamplingRates( [ 'foo.*' => 0.2 ] ); diff --git a/tests/phpunit/unit/includes/user/UserNamePrefixSearchTest.php b/tests/phpunit/unit/includes/user/UserNamePrefixSearchTest.php index 08188b343d61..5711c2715247 100644 --- a/tests/phpunit/unit/includes/user/UserNamePrefixSearchTest.php +++ b/tests/phpunit/unit/includes/user/UserNamePrefixSearchTest.php @@ -38,9 +38,7 @@ class UserNamePrefixSearchTest extends MediaWikiUnitTestCase { $userFactory = $this->createMock( UserFactory::class ); $userFactory->expects( $this->once() ) ->method( 'newFromName' ) - ->with( - $this->equalTo( $prefix ) - ) + ->with( $prefix ) ->willReturn( $user ); $permissionManager = $this->createMock( PermissionManager::class ); @@ -64,10 +62,7 @@ class UserNamePrefixSearchTest extends MediaWikiUnitTestCase { $audience = $this->createMock( User::class ); $permissionManager->expects( $this->once() ) ->method( 'userHasRight' ) - ->with( - $this->equalTo( $audience ), - $this->equalTo( 'hideuser' ) - ) + ->with( $audience, 'hideuser' ) ->willReturn( $hasHideuser ); } @@ -77,10 +72,7 @@ class UserNamePrefixSearchTest extends MediaWikiUnitTestCase { ->willReturn( 'anyStringGoesHere' ); $database->expects( $this->once() ) ->method( 'buildLike' ) - ->with( - $this->equalTo( $prefix ), - $this->equalTo( 'anyStringGoesHere' ) - ) + ->with( $prefix, 'anyStringGoesHere' ) ->willReturn( 'LIKE ' . $prefix . 'anyStringGoesHere' ); // Query parameters @@ -100,12 +92,12 @@ class UserNamePrefixSearchTest extends MediaWikiUnitTestCase { $database->expects( $this->once() ) ->method( 'selectFieldValues' ) ->with( - $this->equalTo( $tables ), - $this->equalTo( 'user_name' ), - $this->equalTo( $conds ), - $this->equalTo( 'MediaWiki\User\UserNamePrefixSearch::search' ), - $this->equalTo( $options ), - $this->equalTo( $joinConds ) + $tables, + 'user_name', + $conds, + 'MediaWiki\User\UserNamePrefixSearch::search', + $options, + $joinConds ) ->willReturn( $result ); |