From 0ae7e354bde92956d34a7fdb3fc76b8cead8c83f Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Thu, 7 Nov 2024 09:20:08 +0100 Subject: [PATCH] Use more trivial NullLogger in tests, instead of mock The null implementation is made for such situations, and even more efficient than dynamically building a PHPUnit mock every time. Change-Id: I1ef539780b508a4d14779bb67e44af4ab7e317dd --- .../Hooks/OtherProjectsSidebarGeneratorFactoryTest.php | 4 ++-- .../unit/includes/Hooks/LangLinkHandlerFactoryTest.php | 4 ++-- .../unit/includes/Hooks/SiteLinksForDisplayLookupTest.php | 8 ++++---- .../includes/ServiceWiring/AffectedPagesFinderTest.php | 4 ++-- .../unit/includes/ServiceWiring/ChangeHandlerTest.php | 4 ++-- .../ServiceWiring/TermInLangIdsResolverFactoryTest.php | 4 ++-- .../phpunit/GlobalStateFactoryMethodsResourceTest.php | 5 ++--- .../Store/Sql/Terms/TermStoreWriterFactoryTest.php | 4 ++-- .../DispatchChangeDeletionNotificationJobTest.php | 3 ++- repo/tests/phpunit/includes/WikibasePingbackTest.php | 5 ++--- .../unit/ServiceWiring/MatchingTermsLookupFactoryTest.php | 4 ++-- .../ServiceWiring/TermInLangIdsResolverFactoryTest.php | 4 ++-- 12 files changed, 26 insertions(+), 27 deletions(-) diff --git a/client/tests/phpunit/integration/includes/Hooks/OtherProjectsSidebarGeneratorFactoryTest.php b/client/tests/phpunit/integration/includes/Hooks/OtherProjectsSidebarGeneratorFactoryTest.php index 6fed2d2dee4..4d946b4dca1 100644 --- a/client/tests/phpunit/integration/includes/Hooks/OtherProjectsSidebarGeneratorFactoryTest.php +++ b/client/tests/phpunit/integration/includes/Hooks/OtherProjectsSidebarGeneratorFactoryTest.php @@ -5,7 +5,7 @@ use MediaWiki\HookContainer\HookContainer; use MediaWiki\Site\SiteLookup; use MediaWikiIntegrationTestCase; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Hooks\OtherProjectsSidebarGenerator; use Wikibase\Client\Hooks\OtherProjectsSidebarGeneratorFactory; use Wikibase\Client\Hooks\SidebarLinkBadgeDisplay; @@ -38,7 +38,7 @@ public function testGetOtherProjectsSidebarGenerator() { $this->createMock( EntityLookup::class ), $this->createMock( SidebarLinkBadgeDisplay::class ), $this->createMock( HookContainer::class ), - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $otherProjectSidebarGenerator = $factory->getOtherProjectsSidebarGenerator( $this->createMock( UsageAccumulator::class ) ); diff --git a/client/tests/phpunit/unit/includes/Hooks/LangLinkHandlerFactoryTest.php b/client/tests/phpunit/unit/includes/Hooks/LangLinkHandlerFactoryTest.php index f1bcd72e380..f317accb5f1 100644 --- a/client/tests/phpunit/unit/includes/Hooks/LangLinkHandlerFactoryTest.php +++ b/client/tests/phpunit/unit/includes/Hooks/LangLinkHandlerFactoryTest.php @@ -4,7 +4,7 @@ use MediaWiki\HookContainer\HookContainer; use MediaWiki\Site\SiteStore; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Hooks\LangLinkHandler; use Wikibase\Client\Hooks\LangLinkHandlerFactory; use Wikibase\Client\Hooks\LanguageLinkBadgeDisplay; @@ -32,7 +32,7 @@ public function testGetLangLinkHandler() { $this->createMock( EntityLookup::class ), $this->createMock( SiteStore::class ), $this->createMock( HookContainer::class ), - $this->createMock( LoggerInterface::class ), + new NullLogger(), 'srwiki', [ 'wikipedia' ] ); diff --git a/client/tests/phpunit/unit/includes/Hooks/SiteLinksForDisplayLookupTest.php b/client/tests/phpunit/unit/includes/Hooks/SiteLinksForDisplayLookupTest.php index 060bbba9120..b0a8f522029 100644 --- a/client/tests/phpunit/unit/includes/Hooks/SiteLinksForDisplayLookupTest.php +++ b/client/tests/phpunit/unit/includes/Hooks/SiteLinksForDisplayLookupTest.php @@ -4,7 +4,7 @@ use MediaWiki\HookContainer\HookContainer; use MediaWiki\Title\Title; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Hooks\SiteLinksForDisplayLookup; use Wikibase\Client\Usage\UsageAccumulator; use Wikibase\DataModel\Entity\Item; @@ -44,7 +44,7 @@ public function testGetSiteLinksForPageTitle_unknownTitle() { $entityLookup, $this->createMock( UsageAccumulator::class ), $this->createMock( HookContainer::class ), - $this->createMock( LoggerInterface::class ), + new NullLogger(), 'srwiki' ); @@ -73,7 +73,7 @@ public function testGetSiteLinksForPageTitle_unknownEntity() { $entityLookup, $this->createMock( UsageAccumulator::class ), $this->createMock( HookContainer::class ), - $this->createMock( LoggerInterface::class ), + new NullLogger(), 'srwiki' ); @@ -128,7 +128,7 @@ public function testGetSiteLinksForPageTitle_knownEntity() { $entityLookup, $this->createMock( UsageAccumulator::class ), $hookContainer, - $this->createMock( LoggerInterface::class ), + new NullLogger(), 'srwiki' ); diff --git a/client/tests/phpunit/unit/includes/ServiceWiring/AffectedPagesFinderTest.php b/client/tests/phpunit/unit/includes/ServiceWiring/AffectedPagesFinderTest.php index 68becb68bab..35a21ba462e 100644 --- a/client/tests/phpunit/unit/includes/ServiceWiring/AffectedPagesFinderTest.php +++ b/client/tests/phpunit/unit/includes/ServiceWiring/AffectedPagesFinderTest.php @@ -4,7 +4,7 @@ namespace Wikibase\Client\Tests\Unit\ServiceWiring; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Changes\AffectedPagesFinder; use Wikibase\Client\Tests\Mocks\MockClientStore; use Wikibase\Client\Tests\Unit\ServiceWiringTestCase; @@ -32,7 +32,7 @@ public function testConstruction() { ); $this->mockService( 'WikibaseClient.Logger', - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $this->serviceContainer diff --git a/client/tests/phpunit/unit/includes/ServiceWiring/ChangeHandlerTest.php b/client/tests/phpunit/unit/includes/ServiceWiring/ChangeHandlerTest.php index 9a2e1df070c..2c55d5ccc32 100644 --- a/client/tests/phpunit/unit/includes/ServiceWiring/ChangeHandlerTest.php +++ b/client/tests/phpunit/unit/includes/ServiceWiring/ChangeHandlerTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Client\Tests\Unit\ServiceWiring; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Changes\AffectedPagesFinder; use Wikibase\Client\Changes\ChangeHandler; use Wikibase\Client\Hooks\WikibaseClientHookRunner; @@ -34,7 +34,7 @@ public function testConstruction(): void { $this->mockService( 'WikibaseClient.Logger', - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $this->mockService( diff --git a/client/tests/phpunit/unit/includes/ServiceWiring/TermInLangIdsResolverFactoryTest.php b/client/tests/phpunit/unit/includes/ServiceWiring/TermInLangIdsResolverFactoryTest.php index 4f1b1e55859..4f8623f5739 100644 --- a/client/tests/phpunit/unit/includes/ServiceWiring/TermInLangIdsResolverFactoryTest.php +++ b/client/tests/phpunit/unit/includes/ServiceWiring/TermInLangIdsResolverFactoryTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Client\Tests\Unit\ServiceWiring; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Client\Tests\Unit\ServiceWiringTestCase; use Wikibase\Lib\Rdbms\RepoDomainDbFactory; use Wikibase\Lib\Store\Sql\Terms\TermInLangIdsResolverFactory; @@ -20,7 +20,7 @@ class TermInLangIdsResolverFactoryTest extends ServiceWiringTestCase { public function testConstruction(): void { $this->mockService( 'WikibaseClient.Logger', - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $this->mockService( diff --git a/lib/tests/phpunit/GlobalStateFactoryMethodsResourceTest.php b/lib/tests/phpunit/GlobalStateFactoryMethodsResourceTest.php index 99c1a9a2622..e0652e83817 100644 --- a/lib/tests/phpunit/GlobalStateFactoryMethodsResourceTest.php +++ b/lib/tests/phpunit/GlobalStateFactoryMethodsResourceTest.php @@ -5,7 +5,7 @@ use MediaWiki\Http\HttpRequestFactory; use MediaWikiIntegrationTestCase; use ObjectCacheFactory; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Lib\StatsdRecordingSimpleCache; use Wikibase\Lib\TermFallbackCache\TermFallbackCacheServiceFactory; use Wikibase\Lib\TermFallbackCacheFactory; @@ -67,10 +67,9 @@ public function testWikibaseSettings_repoSettings(): void { * @dataProvider cacheTypeProvider */ public function testTermFallbackCacheFactory( $sharedCacheType ): void { - $logger = $this->createMock( LoggerInterface::class ); $factory = new TermFallbackCacheFactory( $sharedCacheType, - $logger, + new NullLogger(), $this->createMock( IBufferingStatsdDataFactory::class ), 'secret', new TermFallbackCacheServiceFactory(), diff --git a/lib/tests/phpunit/Store/Sql/Terms/TermStoreWriterFactoryTest.php b/lib/tests/phpunit/Store/Sql/Terms/TermStoreWriterFactoryTest.php index cba5032cf71..8680f45976e 100644 --- a/lib/tests/phpunit/Store/Sql/Terms/TermStoreWriterFactoryTest.php +++ b/lib/tests/phpunit/Store/Sql/Terms/TermStoreWriterFactoryTest.php @@ -6,7 +6,7 @@ use LogicException; use MediaWiki\Revision\SlotRecord; use PHPUnit\Framework\TestCase; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\DataAccess\DatabaseEntitySource; use Wikibase\DataModel\Services\Term\ItemTermStoreWriter; use Wikibase\DataModel\Services\Term\PropertyTermStoreWriter; @@ -53,7 +53,7 @@ public function testFailsToCreateWriterWhenNotOnLocalEntitySource( $this->newStubRepoDb(), $this->createMock( WANObjectCache::class ), $this->createMock( JobQueueGroup::class ), - $this->createMock( LoggerInterface::class ) + new NullLogger() ); if ( !$expected ) { diff --git a/repo/tests/phpunit/includes/ChangeModification/DispatchChangeDeletionNotificationJobTest.php b/repo/tests/phpunit/includes/ChangeModification/DispatchChangeDeletionNotificationJobTest.php index 4fcefe43979..668f3d43cd2 100644 --- a/repo/tests/phpunit/includes/ChangeModification/DispatchChangeDeletionNotificationJobTest.php +++ b/repo/tests/phpunit/includes/ChangeModification/DispatchChangeDeletionNotificationJobTest.php @@ -10,6 +10,7 @@ use MediaWiki\Utils\MWTimestamp; use MediaWikiIntegrationTestCase; use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\DataModel\Entity\Item; use Wikibase\DataModel\Entity\ItemId; use Wikibase\Lib\Changes\RepoRevisionIdentifier; @@ -54,7 +55,7 @@ public function testShouldDispatchJobsForClientWikis() { new RepoRevisionIdentifier( "Q303", $timestamp, $revisionRecordId ), ]; - $logger = $this->createMock( LoggerInterface::class ); + $logger = new NullLogger(); $factory = $this->newJobQueueGroupFactory( $expectedRevIdentifiers ); $job = $this->getJobAndInitialize( $pageTitle, $params, $logger, $factory ); diff --git a/repo/tests/phpunit/includes/WikibasePingbackTest.php b/repo/tests/phpunit/includes/WikibasePingbackTest.php index 16c866565e0..e331e1a8979 100644 --- a/repo/tests/phpunit/includes/WikibasePingbackTest.php +++ b/repo/tests/phpunit/includes/WikibasePingbackTest.php @@ -11,8 +11,8 @@ use MediaWiki\SiteStats\SiteStatsInit; use MediaWiki\Utils\MWTimestamp; use MediaWikiIntegrationTestCase; -use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; +use Psr\Log\NullLogger; use TestLogger; use Wikibase\Lib\Rdbms\RepoDomainDb; use Wikibase\Lib\SettingsArray; @@ -160,7 +160,6 @@ public function getPingbackWithRequestExpectation( $expectation, $logger ) { } private function getPingback( HttpRequestFactory $requestFactory = null ): WikibasePingback { - $logger = $this->createMock( LoggerInterface::class ); $extensions = $this->createMock( ExtensionRegistry::class ); $wikibaseRepoSettings = $this->createMock( SettingsArray::class ); $requestFactory ??= $this->createMock( HttpRequestFactory::class ); @@ -182,7 +181,7 @@ private function getPingback( HttpRequestFactory $requestFactory = null ): Wikib return new WikibasePingback( new HashConfig( [ MainConfigNames::DBtype => '' ] ), - $logger, + new NullLogger(), $extensions, $wikibaseRepoSettings, $requestFactory, diff --git a/repo/tests/phpunit/unit/ServiceWiring/MatchingTermsLookupFactoryTest.php b/repo/tests/phpunit/unit/ServiceWiring/MatchingTermsLookupFactoryTest.php index c9940b11e58..546741eb8ac 100644 --- a/repo/tests/phpunit/unit/ServiceWiring/MatchingTermsLookupFactoryTest.php +++ b/repo/tests/phpunit/unit/ServiceWiring/MatchingTermsLookupFactoryTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Repo\Tests\Unit\ServiceWiring; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\DataModel\Services\EntityId\EntityIdComposer; use Wikibase\Lib\Rdbms\RepoDomainDbFactory; use Wikibase\Lib\Store\MatchingTermsLookupFactory; @@ -26,7 +26,7 @@ public function testConstruction(): void { $this->mockService( 'WikibaseRepo.Logger', - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $this->mockService( diff --git a/repo/tests/phpunit/unit/ServiceWiring/TermInLangIdsResolverFactoryTest.php b/repo/tests/phpunit/unit/ServiceWiring/TermInLangIdsResolverFactoryTest.php index cf17cbeff17..612ae78816a 100644 --- a/repo/tests/phpunit/unit/ServiceWiring/TermInLangIdsResolverFactoryTest.php +++ b/repo/tests/phpunit/unit/ServiceWiring/TermInLangIdsResolverFactoryTest.php @@ -3,7 +3,7 @@ namespace Wikibase\Repo\Tests\Unit\ServiceWiring; -use Psr\Log\LoggerInterface; +use Psr\Log\NullLogger; use Wikibase\Lib\Rdbms\RepoDomainDbFactory; use Wikibase\Lib\Store\Sql\Terms\TermInLangIdsResolverFactory; use Wikibase\Repo\Tests\Unit\ServiceWiringTestCase; @@ -20,7 +20,7 @@ class TermInLangIdsResolverFactoryTest extends ServiceWiringTestCase { public function testConstruction(): void { $this->mockService( 'WikibaseRepo.Logger', - $this->createMock( LoggerInterface::class ) + new NullLogger() ); $this->serviceContainer