diff options
Diffstat (limited to 'tests/phpunit/unit/includes')
9 files changed, 36 insertions, 69 deletions
diff --git a/tests/phpunit/unit/includes/ListToggleTest.php b/tests/phpunit/unit/includes/ListToggleTest.php index 4af02c082f1c..f12837589c46 100644 --- a/tests/phpunit/unit/includes/ListToggleTest.php +++ b/tests/phpunit/unit/includes/ListToggleTest.php @@ -31,8 +31,7 @@ class ListToggleTest extends MediaWikiUnitTestCase { } ); $output = $this->createMock( OutputPage::class ); - $output->expects( $this->any() ) - ->method( 'msg' ) + $output->method( 'msg' ) ->will( $this->returnCallback( static function ( $key ) { return new class( $key ) extends Message { protected function fetchMessage() { diff --git a/tests/phpunit/unit/includes/debug/logger/monolog/KafkaHandlerTest.php b/tests/phpunit/unit/includes/debug/logger/monolog/KafkaHandlerTest.php index d321414a7d43..7ce54512ad8f 100644 --- a/tests/phpunit/unit/includes/debug/logger/monolog/KafkaHandlerTest.php +++ b/tests/phpunit/unit/includes/debug/logger/monolog/KafkaHandlerTest.php @@ -86,8 +86,7 @@ class KafkaHandlerTest extends \MediaWikiUnitTestCase { $produce = $this->getMockBuilder( \Kafka\Produce::class ) ->disableOriginalConstructor() ->getMock(); - $produce->expects( $this->any() ) - ->method( 'getAvailablePartitions' ) + $produce->method( 'getAvailablePartitions' ) ->will( $this->throwException( new Exception ) ); $produce->method( 'send' ) ->willReturn( true ); @@ -154,8 +153,7 @@ class KafkaHandlerTest extends \MediaWikiUnitTestCase { ->willReturn( true ); $formatter = $this->createMock( \Monolog\Formatter\FormatterInterface::class ); - $formatter->expects( $this->any() ) - ->method( 'format' ) + $formatter->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); $handler = new KafkaHandler( $produce, [] ); @@ -183,8 +181,7 @@ class KafkaHandlerTest extends \MediaWikiUnitTestCase { ->willReturn( true ); $formatter = $this->createMock( \Monolog\Formatter\FormatterInterface::class ); - $formatter->expects( $this->any() ) - ->method( 'format' ) + $formatter->method( 'format' ) ->will( $this->onConsecutiveCalls( 'words', null, 'lines' ) ); $handler = new KafkaHandler( $produce, [] ); diff --git a/tests/phpunit/unit/includes/diff/ArrayDiffFormatterTest.php b/tests/phpunit/unit/includes/diff/ArrayDiffFormatterTest.php index d93736abd620..3f8378395900 100644 --- a/tests/phpunit/unit/includes/diff/ArrayDiffFormatterTest.php +++ b/tests/phpunit/unit/includes/diff/ArrayDiffFormatterTest.php @@ -37,8 +37,7 @@ class ArrayDiffFormatterTest extends \MediaWikiUnitTestCase { $diffOp->method( 'getOrig' ) ->willReturn( $orig ); if ( $type === 'change' ) { - $diffOp->expects( $this->any() ) - ->method( 'getClosing' ) + $diffOp->method( 'getClosing' ) ->with( $this->isType( 'integer' ) ) ->will( $this->returnCallback( static function () { return 'mockLine'; diff --git a/tests/phpunit/unit/includes/http/MwHttpRequestToResponseInterfaceAdapterTest.php b/tests/phpunit/unit/includes/http/MwHttpRequestToResponseInterfaceAdapterTest.php index c8b312671050..52654067fd2c 100644 --- a/tests/phpunit/unit/includes/http/MwHttpRequestToResponseInterfaceAdapterTest.php +++ b/tests/phpunit/unit/includes/http/MwHttpRequestToResponseInterfaceAdapterTest.php @@ -126,8 +126,7 @@ class MwHttpRequestToResponseInterfaceAdapterTest extends MediaWikiUnitTestCase private function newMockMWHttpRequestWithHeaders( array $headers ) { $req = $this->createMock( MWHttpRequest::class ); - $req->expects( $this->any() ) - ->method( 'getResponseHeaders' ) + $req->method( 'getResponseHeaders' ) ->willReturn( $headers ); return $req; diff --git a/tests/phpunit/unit/includes/libs/MemoizedCallableTest.php b/tests/phpunit/unit/includes/libs/MemoizedCallableTest.php index 8b05d388fd23..d6c63aabec5a 100644 --- a/tests/phpunit/unit/includes/libs/MemoizedCallableTest.php +++ b/tests/phpunit/unit/includes/libs/MemoizedCallableTest.php @@ -17,8 +17,7 @@ class MemoizedCallableTest extends PHPUnit\Framework\TestCase { public function testReturnValuePassedThrough() { $mock = $this->getMockBuilder( stdClass::class ) ->addMethods( [ 'reverse' ] )->getMock(); - $mock->expects( $this->any() ) - ->method( 'reverse' ) + $mock->method( 'reverse' ) ->will( $this->returnCallback( 'strrev' ) ); $memoized = new MemoizedCallable( [ $mock, 'reverse' ] ); diff --git a/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php index 2fcf38f72775..3719502a8d8a 100644 --- a/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/unit/includes/libs/objectcache/WANObjectCacheTest.php @@ -1126,8 +1126,8 @@ class WANObjectCacheTest extends PHPUnit\Framework\TestCase { ] ) ->getMock(); - $cache->expects( $this->any() )->method( 'worthRefreshExpiring' )->willReturn( $expiring ); - $cache->expects( $this->any() )->method( 'worthRefreshPopular' )->willReturn( $popular ); + $cache->method( 'worthRefreshExpiring' )->willReturn( $expiring ); + $cache->method( 'worthRefreshPopular' )->willReturn( $popular ); $wasSet = 0; $keyedIds = new ArrayIterator( $idsByKey ); diff --git a/tests/phpunit/unit/includes/libs/rdbms/database/DatabaseSqliteRdbmsTest.php b/tests/phpunit/unit/includes/libs/rdbms/database/DatabaseSqliteRdbmsTest.php index 76354263e33c..2725a037bcbf 100644 --- a/tests/phpunit/unit/includes/libs/rdbms/database/DatabaseSqliteRdbmsTest.php +++ b/tests/phpunit/unit/includes/libs/rdbms/database/DatabaseSqliteRdbmsTest.php @@ -22,7 +22,7 @@ class DatabaseSqliteRdbmsTest extends PHPUnit\Framework\TestCase { ->onlyMethods( [ 'open', 'query', 'addQuotes' ] ) ->getMock(); - $db->expects( $this->any() )->method( 'addQuotes' )->willReturnCallback( + $db->method( 'addQuotes' )->willReturnCallback( static function ( $s ) { return "'$s'"; } diff --git a/tests/phpunit/unit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php b/tests/phpunit/unit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php index 4bf48ab8b9fa..e38afc59fe98 100644 --- a/tests/phpunit/unit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php +++ b/tests/phpunit/unit/includes/watcheditem/WatchedItemQueryServiceUnitTest.php @@ -19,11 +19,9 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { */ private function getMockCommentStore() { $mockStore = $this->createMock( CommentStore::class ); - $mockStore->expects( $this->any() ) - ->method( 'getFields' ) + $mockStore->method( 'getFields' ) ->willReturn( [ 'commentstore' => 'fields' ] ); - $mockStore->expects( $this->any() ) - ->method( 'getJoin' ) + $mockStore->method( 'getJoin' ) ->willReturn( [ 'tables' => [ 'commentstore' => 'table' ], 'fields' => [ 'commentstore' => 'field' ], @@ -37,8 +35,7 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { */ private function getMockActorMigration() { $mockStore = $this->createMock( ActorMigration::class ); - $mockStore->expects( $this->any() ) - ->method( 'getJoin' ) + $mockStore->method( 'getJoin' ) ->willReturn( [ 'tables' => [ 'actormigration' => 'table' ], 'fields' => [ @@ -48,18 +45,15 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { ], 'joins' => [ 'actormigration' => 'join' ], ] ); - $mockStore->expects( $this->any() ) - ->method( 'getWhere' ) + $mockStore->method( 'getWhere' ) ->willReturn( [ 'tables' => [ 'actormigration' => 'table' ], 'conds' => 'actormigration_conds', 'joins' => [ 'actormigration' => 'join' ], ] ); - $mockStore->expects( $this->any() ) - ->method( 'isAnon' ) + $mockStore->method( 'isAnon' ) ->willReturn( 'actormigration is anon' ); - $mockStore->expects( $this->any() ) - ->method( 'isNotAnon' ) + $mockStore->method( 'isNotAnon' ) ->willReturn( 'actormigration is not anon' ); return $mockStore; } @@ -88,8 +82,7 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { private function getMockDb() { $mock = $this->createMock( IDatabase::class ); - $mock->expects( $this->any() ) - ->method( 'makeList' ) + $mock->method( 'makeList' ) ->with( $this->isType( 'array' ), $this->isType( 'int' ) @@ -109,18 +102,15 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { return implode( $sqlConj, $conds ); } ) ); - $mock->expects( $this->any() ) - ->method( 'addQuotes' ) + $mock->method( 'addQuotes' ) ->will( $this->returnCallback( static function ( $value ) { return "'$value'"; } ) ); - $mock->expects( $this->any() ) - ->method( 'timestamp' ) + $mock->method( 'timestamp' ) ->will( $this->returnArgument( 0 ) ); - $mock->expects( $this->any() ) - ->method( 'bitAnd' ) + $mock->method( 'bitAnd' ) ->willReturnCallback( static function ( $a, $b ) { return "($a & $b)"; } ); @@ -134,8 +124,7 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { */ private function getMockLoadBalancer( $mockDb ) { $mock = $this->createMock( LoadBalancer::class ); - $mock->expects( $this->any() ) - ->method( 'getConnectionRef' ) + $mock->method( 'getConnectionRef' ) ->with( DB_REPLICA ) ->willReturn( $mockDb ); return $mock; @@ -146,8 +135,7 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { */ private function getMockWatchedItemStore() { $mock = $this->createMock( WatchedItemStore::class ); - $mock->expects( $this->any() ) - ->method( 'getLatestNotificationTimestamp' ) + $mock->method( 'getLatestNotificationTimestamp' ) ->will( $this->returnCallback( static function ( $timestamp ) { return $timestamp; } ) ); @@ -1564,13 +1552,11 @@ class WatchedItemQueryServiceUnitTest extends MediaWikiUnitTestCase { $expectedConds = array_merge( [ 'wl_user' => 1 ], $expectedConds ); $mockDb = $this->getMockDb(); - $mockDb->expects( $this->any() ) - ->method( 'addQuotes' ) + $mockDb->method( 'addQuotes' ) ->will( $this->returnCallback( static function ( $value ) { return "'$value'"; } ) ); - $mockDb->expects( $this->any() ) - ->method( 'makeList' ) + $mockDb->method( 'makeList' ) ->with( $this->isType( 'array' ), $this->isType( 'int' ) diff --git a/tests/phpunit/unit/includes/watcheditem/WatchedItemStoreUnitTest.php b/tests/phpunit/unit/includes/watcheditem/WatchedItemStoreUnitTest.php index 22564952a86e..e3d5e9c9be9f 100644 --- a/tests/phpunit/unit/includes/watcheditem/WatchedItemStoreUnitTest.php +++ b/tests/phpunit/unit/includes/watcheditem/WatchedItemStoreUnitTest.php @@ -44,8 +44,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { ->disableOriginalConstructor() ->getMock(); if ( $expectedConnectionType !== null ) { - $mock->expects( $this->any() ) - ->method( 'getConnectionRef' ) + $mock->method( 'getConnectionRef' ) ->with( $expectedConnectionType ) ->willReturn( $mockDb ); } else { @@ -88,14 +87,12 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { $mock = $this->getMockBuilder( JobQueueGroup::class ) ->disableOriginalConstructor() ->getMock(); - $mock->expects( $this->any() ) - ->method( 'push' ) + $mock->method( 'push' ) ->will( $this->returnCallback( static function ( Job $job ) { $job->run(); } ) ); if ( $mockLazyPush ) { - $mock->expects( $this->any() ) - ->method( 'lazyPush' ) + $mock->method( 'lazyPush' ) ->will( $this->returnCallback( static function ( Job $job ) { $job->run(); } ) ); @@ -111,8 +108,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { ->disableOriginalConstructor() ->onlyMethods( [ 'get', 'set', 'delete', 'makeKey' ] ) ->getMock(); - $mock->expects( $this->any() ) - ->method( 'makeKey' ) + $mock->method( 'makeKey' ) ->will( $this->returnCallback( static function ( ...$args ) { return implode( ':', $args ); } ) ); @@ -741,8 +737,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { return 'TS' . $value . 'TS'; } ) ); - $mockDb->expects( $this->any() ) - ->method( 'makeList' ) + $mockDb->method( 'makeList' ) ->with( $this->isType( 'array' ), $this->isType( 'int' ) @@ -832,8 +827,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { ->will( $this->returnCallback( static function ( $value ) { return 'TS' . $value . 'TS'; } ) ); - $mockDb->expects( $this->any() ) - ->method( 'makeList' ) + $mockDb->method( 'makeList' ) ->with( $this->isType( 'array' ), $this->isType( 'int' ) @@ -2532,8 +2526,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->willReturnCallback( static function ( ActivityUpdateJob $job ) { // don't run } ); @@ -2627,8 +2620,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->will( $this->returnCallback( function ( ActivityUpdateJob $job ) use ( $title, $user ) { $this->verifyCallbackJob( @@ -2738,8 +2730,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->will( $this->returnCallback( function ( ActivityUpdateJob $job ) use ( $title, $user ) { $this->verifyCallbackJob( @@ -2841,8 +2832,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->will( $this->returnCallback( function ( ActivityUpdateJob $job ) use ( $title, $user ) { $this->verifyCallbackJob( @@ -2952,8 +2942,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->will( $this->returnCallback( function ( ActivityUpdateJob $job ) use ( $title, $user ) { $this->verifyCallbackJob( @@ -3063,8 +3052,7 @@ class WatchedItemStoreUnitTest extends MediaWikiUnitTestCase { 'titleFactory' => $titleFactory, ] ); - $mockQueueGroup->expects( $this->any() ) - ->method( 'lazyPush' ) + $mockQueueGroup->method( 'lazyPush' ) ->will( $this->returnCallback( function ( ActivityUpdateJob $job ) use ( $title, $user ) { $this->verifyCallbackJob( |