diff --git a/source/Internal/Framework/Cache/Command/ClearCacheCommand.php b/source/Internal/Framework/Cache/Command/ClearCacheCommand.php index f694169505..e53705b9e7 100644 --- a/source/Internal/Framework/Cache/Command/ClearCacheCommand.php +++ b/source/Internal/Framework/Cache/Command/ClearCacheCommand.php @@ -4,9 +4,9 @@ namespace OxidEsales\EshopCommunity\Internal\Framework\Cache\Command; +use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\ShopPoolServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ContainerCacheInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheServiceInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface; use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use Symfony\Component\Console\Command\Command; @@ -16,11 +16,11 @@ class ClearCacheCommand extends Command { public function __construct( - private ShopAdapterInterface $shopAdapter, - private TemplateCacheServiceInterface $templateCacheService, - private ContainerCacheInterface $containerCache, - private ModuleCacheServiceInterface $moduleCacheService, - private ContextInterface $context + private readonly ShopAdapterInterface $shopAdapter, + private readonly ShopTemplateCacheServiceInterface $templateCacheService, + private readonly ContainerCacheInterface $containerCache, + private readonly ShopPoolServiceInterface $shopPoolService, + private readonly ContextInterface $context ) { parent::__construct(); } @@ -32,15 +32,14 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $this->templateCacheService->invalidateTemplateCache(); + $this->templateCacheService->invalidateAllShopsCache(); $this->shopAdapter->invalidateModulesCache(); foreach ($this->context->getAllShopIds() as $shopId) { $this->containerCache->invalidate($shopId); + $this->shopPoolService->invalidate($shopId); } - $this->moduleCacheService->invalidateAll(); - $output->writeln("Cleared cache files"); return 0; diff --git a/source/Internal/Framework/Cache/Pool/ShopPoolService.php b/source/Internal/Framework/Cache/Pool/ShopPoolService.php new file mode 100644 index 0000000000..1e97b7aa31 --- /dev/null +++ b/source/Internal/Framework/Cache/Pool/ShopPoolService.php @@ -0,0 +1,24 @@ +templateCacheService->invalidateCache($shopId); + $this->shopAdapter->invalidateModulesCache(); + $this->cacheItemPool->clear(); + } +} \ No newline at end of file diff --git a/source/Internal/Framework/Cache/Pool/ShopPoolServiceInterface.php b/source/Internal/Framework/Cache/Pool/ShopPoolServiceInterface.php new file mode 100644 index 0000000000..9248cb67df --- /dev/null +++ b/source/Internal/Framework/Cache/Pool/ShopPoolServiceInterface.php @@ -0,0 +1,8 @@ +moduleCacheService->invalidate($event->getModuleId(), $event->getShopId()); + public function invalidateModuleCache(ModuleSetupEvent|ModuleConfigurationChangedEvent $event): void + { + $this->shopPoolService->invalidate($event->getShopId()); } public static function getSubscribedEvents(): array diff --git a/source/Internal/Framework/Module/Cache/ModuleCache.php b/source/Internal/Framework/Module/Cache/ModuleCache.php index 2516994108..b76ffd298b 100644 --- a/source/Internal/Framework/Module/Cache/ModuleCache.php +++ b/source/Internal/Framework/Module/Cache/ModuleCache.php @@ -9,35 +9,20 @@ namespace OxidEsales\EshopCommunity\Internal\Framework\Module\Cache; -use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface; -use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface; -use Symfony\Contracts\Cache\CacheInterface; +use Psr\Cache\CacheItemPoolInterface; class ModuleCache implements ModuleCacheServiceInterface { - public function __construct( - private readonly ShopAdapterInterface $shopAdapter, - private readonly ShopTemplateCacheServiceInterface $templateCacheService, - private readonly CacheInterface $cache - ) { - } - - public function invalidate(string $moduleId, int $shopId): void + public function __construct(private readonly CacheItemPoolInterface $cache) { - $this->templateCacheService->invalidateCache($shopId); - $this->shopAdapter->invalidateModuleCache($moduleId); - $this->cache->clear(); } - public function invalidateAll(): void + public function invalidate(string $key): void { - $this->templateCacheService->invalidateAllShopsCache(); - $this->shopAdapter->invalidateModulesCache(); - - $this->cache->clear(); + $this->cache->deleteItem($key); } - public function put(string $key, int $shopId, array $data): void + public function put(string $key, array $data): void { $cacheModulePathItem = $this->cache->getItem($key); $cacheModulePathItem->set($data); @@ -47,20 +32,18 @@ public function put(string $key, int $shopId, array $data): void /** * @throws CacheNotFoundException */ - public function get(string $key, int $shopId): array + public function get(string $key): array { $cacheModulePathItem = $this->cache->getItem($key); if (!$cacheModulePathItem->isHit()) { - throw new CacheNotFoundException( - "Cache with key '$key' for the shop with id $shopId not found." - ); + throw new CacheNotFoundException("Cache with key '$key' not found."); } return $cacheModulePathItem->get(); } - public function exists(string $key, int $shopId): bool + public function exists(string $key): bool { return $this->cache->getItem($key)->isHit(); } diff --git a/source/Internal/Framework/Module/Cache/ModuleCacheServiceInterface.php b/source/Internal/Framework/Module/Cache/ModuleCacheServiceInterface.php index eb06090865..6380ad8d2a 100644 --- a/source/Internal/Framework/Module/Cache/ModuleCacheServiceInterface.php +++ b/source/Internal/Framework/Module/Cache/ModuleCacheServiceInterface.php @@ -11,36 +11,11 @@ interface ModuleCacheServiceInterface { - /** - * Invalidate all module related cache items for a given module and a given shop - * - * @param string $moduleId - * @param int $shopId - */ - public function invalidate(string $moduleId, int $shopId): void; + public function invalidate(string $key): void; - public function invalidateAll(): void; + public function put(string $key, array $data): void; - /** - * @param string $key - * @param int $shopId - * @param array $data - */ - public function put(string $key, int $shopId, array $data): void; + public function get(string $key): array; - /** - * @param string $key - * @param int $shopId - * - * @return array - */ - public function get(string $key, int $shopId): array; - - /** - * @param string $key - * @param int $shopId - * - * @return bool - */ - public function exists(string $key, int $shopId): bool; + public function exists(string $key): bool; } diff --git a/source/Internal/Framework/Module/Facade/ActiveModulesDataProvider.php b/source/Internal/Framework/Module/Facade/ActiveModulesDataProvider.php index cb35c8601b..ae872e3af8 100644 --- a/source/Internal/Framework/Module/Facade/ActiveModulesDataProvider.php +++ b/source/Internal/Framework/Module/Facade/ActiveModulesDataProvider.php @@ -19,11 +19,11 @@ class ActiveModulesDataProvider implements ActiveModulesDataProviderInterface { public function __construct( - private ModuleConfigurationDaoInterface $moduleConfigurationDao, - private ModulePathResolverInterface $modulePathResolver, - private ContextInterface $context, - private ModuleCacheServiceInterface $moduleCacheService, - private ActiveClassExtensionChainResolverInterface $activeClassExtensionChainResolver + private readonly ModuleConfigurationDaoInterface $moduleConfigurationDao, + private readonly ModulePathResolverInterface $modulePathResolver, + private readonly ContextInterface $context, + private readonly ModuleCacheServiceInterface $moduleCacheService, + private readonly ActiveClassExtensionChainResolverInterface $activeClassExtensionChainResolver ) { } @@ -42,31 +42,28 @@ public function getModuleIds(): array /** @inheritDoc */ public function getModulePaths(): array { - $shopId = $this->context->getCurrentShopId(); $cacheKey = 'absolute_module_paths'; - if (!$this->moduleCacheService->exists($cacheKey, $shopId)) { + if (!$this->moduleCacheService->exists($cacheKey)) { $this->moduleCacheService->put( $cacheKey, - $shopId, $this->collectModulePathsForCaching() ); } - return $this->moduleCacheService->get($cacheKey, $shopId); + return $this->moduleCacheService->get($cacheKey); } /** @inheritDoc */ public function getControllers(): array { - $shopId = $this->context->getCurrentShopId(); $cacheKey = 'controllers'; - if (!$this->moduleCacheService->exists($cacheKey, $shopId)) { - $this->moduleCacheService->put($cacheKey, $shopId, $this->collectControllersForCaching()); + if (!$this->moduleCacheService->exists($cacheKey)) { + $this->moduleCacheService->put($cacheKey, $this->collectControllersForCaching()); } return $this->createControllersFromData( - $this->moduleCacheService->get($cacheKey, $shopId) + $this->moduleCacheService->get($cacheKey) ); } @@ -76,15 +73,14 @@ public function getClassExtensions(): array $shopId = $this->context->getCurrentShopId(); $cacheKey = 'module_class_extensions'; - if (!$this->moduleCacheService->exists($cacheKey, $shopId)) { + if (!$this->moduleCacheService->exists($cacheKey)) { $this->moduleCacheService->put( $cacheKey, - $shopId, $this->activeClassExtensionChainResolver->getActiveExtensionChain($shopId)->getChain() ); } - return $this->moduleCacheService->get($cacheKey, $shopId); + return $this->moduleCacheService->get($cacheKey); } /** @return array */ diff --git a/source/Internal/Framework/Module/Facade/ModuleSettingService.php b/source/Internal/Framework/Module/Facade/ModuleSettingService.php index 7f94b93234..8feb34208b 100644 --- a/source/Internal/Framework/Module/Facade/ModuleSettingService.php +++ b/source/Internal/Framework/Module/Facade/ModuleSettingService.php @@ -20,10 +20,10 @@ class ModuleSettingService implements ModuleSettingServiceInterface { public function __construct( - private ContextInterface $context, - private ModuleConfigurationDaoInterface $moduleConfigurationDao, - private ModuleCacheServiceInterface $moduleCacheService, - private EventDispatcherInterface $eventDispatcher + private readonly ContextInterface $context, + private readonly ModuleConfigurationDaoInterface $moduleConfigurationDao, + private readonly ModuleCacheServiceInterface $moduleCacheService, + private readonly EventDispatcherInterface $eventDispatcher ) { } @@ -92,8 +92,6 @@ private function saveSettingToModuleConfiguration(string $moduleId, string $name { $shopId = $this->context->getCurrentShopId(); - $this->moduleCacheService->invalidate($moduleId, $shopId); - $moduleConfiguration = $this->moduleConfigurationDao->get($moduleId, $shopId); $setting = $moduleConfiguration->getModuleSetting($name); $setting->setValue($value); @@ -110,7 +108,6 @@ private function getValue(string $moduleId, string $name): mixed if (!$this->moduleCacheService->exists($cacheKey, $shopId)) { $this->moduleCacheService->put( $cacheKey, - $shopId, ['value' => $this->moduleConfigurationDao->get($moduleId, $shopId)->getModuleSetting($name)->getValue()] ); } diff --git a/source/Internal/Framework/Theme/Command/ThemeActivateCommand.php b/source/Internal/Framework/Theme/Command/ThemeActivateCommand.php index 62767d141d..e8bdcf1050 100644 --- a/source/Internal/Framework/Theme/Command/ThemeActivateCommand.php +++ b/source/Internal/Framework/Theme/Command/ThemeActivateCommand.php @@ -9,9 +9,10 @@ namespace OxidEsales\EshopCommunity\Internal\Framework\Theme\Command; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheServiceInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\ShopPoolServiceInterface; +use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface; use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface; +use OxidEsales\EshopCommunity\Internal\Transition\Utility\BasicContextInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -25,8 +26,9 @@ class ThemeActivateCommand extends Command public function __construct( private readonly ShopAdapterInterface $shopAdapter, - private readonly TemplateCacheServiceInterface $templateCacheService, - private readonly ModuleCacheServiceInterface $moduleCacheService + private readonly ShopTemplateCacheServiceInterface $shopTemplateCacheService, + private readonly ShopPoolServiceInterface $shopPoolService, + private readonly BasicContextInterface $context ) { parent::__construct(); } @@ -57,8 +59,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $this->shopAdapter->activateTheme($themeId); - $this->moduleCacheService->invalidateAll(); - $this->templateCacheService->invalidateTemplateCache(); + $this->shopPoolService->invalidate($this->context->getCurrentShopId()); + $this->shopTemplateCacheService->invalidateAllShopsCache(); $output->writeLn('' . sprintf(self::MESSAGE_THEME_ACTIVATED, $themeId) . ''); return Command::SUCCESS; diff --git a/tests/Integration/Core/ModuleVariablesLocatorTest.php b/tests/Integration/Core/ModuleVariablesLocatorTest.php index 7b140c1c1a..d11408d9ae 100644 --- a/tests/Integration/Core/ModuleVariablesLocatorTest.php +++ b/tests/Integration/Core/ModuleVariablesLocatorTest.php @@ -80,7 +80,6 @@ private function putChainToCache(array $chain): void ->get(ModuleCacheServiceInterface::class) ->put( $cacheKey, - $shopId, $chain ); } diff --git a/tests/Integration/Internal/Framework/Cache/ShopPoolServiceTest.php b/tests/Integration/Internal/Framework/Cache/ShopPoolServiceTest.php new file mode 100644 index 0000000000..9a7c5e7d48 --- /dev/null +++ b/tests/Integration/Internal/Framework/Cache/ShopPoolServiceTest.php @@ -0,0 +1,45 @@ +getModuleCacheService(); + $moduleCache->put('test', ['something']); + + $shopPool = $this->getShopPoolService(); + $shopPool->invalidate(1); + + $this->assertFalse( + $moduleCache->exists('test') + ); + } + + private function getShopPoolService(): ShopPoolServiceInterface + { + return $this->get(ShopPoolServiceInterface::class); + } + + private function getModuleCacheService(): ModuleCacheServiceInterface + { + return $this->get(ModuleCacheServiceInterface::class); + } +} diff --git a/tests/Integration/Internal/Framework/Module/Cache/ModuleCacheTest.php b/tests/Integration/Internal/Framework/Module/Cache/ModuleCacheTest.php index 616a921f7c..37ce9a6c6e 100644 --- a/tests/Integration/Internal/Framework/Module/Cache/ModuleCacheTest.php +++ b/tests/Integration/Internal/Framework/Module/Cache/ModuleCacheTest.php @@ -23,49 +23,33 @@ final class ModuleCacheTest extends TestCase public function testPut(): void { $cache = $this->getModuleCacheService(); - $cache->put('test', 1, ['something']); + $cache->put('test', ['something']); $this->assertEquals( ['something'], - $cache->get('test', 1) + $cache->get('test') ); } public function testExists(): void { $cache = $this->getModuleCacheService(); - $cache->put('test', 1, ['something']); + $cache->put('test', ['something']); $this->assertTrue( - $cache->exists('test', 1) + $cache->exists('test') ); } public function testInvalidate(): void { $cache = $this->getModuleCacheService(); - $cache->put('test', 1, ['something']); + $cache->put('test_key', ['something']); - $cache->invalidate('someModule', 1); + $cache->invalidate('test_key'); $this->assertFalse( - $cache->exists('test', 1) - ); - } - - public function testInvalidateAll(): void - { - $cache = $this->getModuleCacheService(); - $cache->put('test', 1, ['something']); - $cache->put('test2', 2, ['something']); - - $cache->invalidateAll(); - - $this->assertFalse( - $cache->exists('test', 1) - ); - $this->assertFalse( - $cache->exists('test2', 2) + $cache->exists('test_key') ); } @@ -74,7 +58,7 @@ public function testGetNotExistentCache(): void $cache = $this->getModuleCacheService(); $this->expectException(CacheNotFoundException::class); - $cache->get('nonExistent', 1); + $cache->get('nonExistent'); } private function getModuleCacheService(): ModuleCacheServiceInterface diff --git a/tests/Integration/Internal/Framework/Module/Facade/ActiveModulesDataProviderTest.php b/tests/Integration/Internal/Framework/Module/Facade/ActiveModulesDataProviderTest.php index 205878ab76..68b3b6e483 100644 --- a/tests/Integration/Internal/Framework/Module/Facade/ActiveModulesDataProviderTest.php +++ b/tests/Integration/Internal/Framework/Module/Facade/ActiveModulesDataProviderTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Integration\Internal\Framework\Module\Facade; +namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Module\Facade; use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Dao\ModuleConfigurationDaoInterface; @@ -74,7 +74,7 @@ public function testGetModulePathsWillReturnSourcePathForActiveModule(): void public function testGetModulePathsUsesCacheIfItExists(): void { $cache = $this->getDummyCache(); - $cache->put('absolute_module_paths', 1, ['moduleId' => 'somePath']); + $cache->put('absolute_module_paths', ['moduleId' => 'somePath']); $activeModulesDataProvider = $this->getActiveModulesDataProviderWithCache($cache); @@ -127,7 +127,6 @@ public function testGetModuleClassExtensionsUsesCacheIfItExists(): void $cache = $this->getDummyCache(); $cache->put( 'module_class_extensions', - 1, [ 'shopClassCache' => ['moduleExtensionClassName1'], 'anotherShopClassCache' => ['moduleExtensionClassName2'], @@ -209,7 +208,7 @@ private function getDummyCache(): ModuleCacheServiceInterface return new class implements ModuleCacheServiceInterface { private array $cache; - public function invalidate(string $moduleId, int $shopId): void + public function invalidate(string $key): void { } @@ -217,19 +216,19 @@ public function invalidateAll(): void { } - public function put(string $key, int $shopId, array $data): void + public function put(string $key, array $data): void { - $this->cache[$shopId][$key] = $data; + $this->cache[$key] = $data; } - public function get(string $key, int $shopId): array + public function get(string $key): array { - return $this->cache[$shopId][$key]; + return $this->cache[$key]; } - public function exists(string $key, int $shopId): bool + public function exists(string $key): bool { - return isset($this->cache[$shopId][$key]); + return isset($this->cache[$key]); } }; } diff --git a/tests/Integration/Internal/Framework/Module/Facade/ModuleSettingServiceTest.php b/tests/Integration/Internal/Framework/Module/Facade/ModuleSettingServiceTest.php index ac8b46798c..df4fc49217 100644 --- a/tests/Integration/Internal/Framework/Module/Facade/ModuleSettingServiceTest.php +++ b/tests/Integration/Internal/Framework/Module/Facade/ModuleSettingServiceTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Integration\Internal\Framework\Module\Facade; +namespace OxidEsales\EshopCommunity\Tests\Integration\Internal\Framework\Module\Facade; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Dao\ModuleConfigurationDaoInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Configuration\Dao\ShopConfigurationDaoInterface; @@ -16,6 +16,7 @@ use OxidEsales\EshopCommunity\Internal\Framework\Module\Setting\Setting; use OxidEsales\EshopCommunity\Tests\ContainerTrait; use PHPUnit\Framework\TestCase; + use function Symfony\Component\String\u; final class ModuleSettingServiceTest extends TestCase @@ -51,7 +52,7 @@ public function testBoolean(): void { $this->settingFacade->saveBoolean('boolSetting', true, $this->testModuleId); - $this->assertSame(true, $this->settingFacade->getBoolean('boolSetting', $this->testModuleId)); + $this->assertTrue($this->settingFacade->getBoolean('boolSetting', $this->testModuleId)); } public function testString(): void diff --git a/tests/Unit/Internal/Framework/Cache/Command/ClearCacheCommandTest.php b/tests/Unit/Internal/Framework/Cache/Command/ClearCacheCommandTest.php index b064bcb943..323bf80b14 100644 --- a/tests/Unit/Internal/Framework/Cache/Command/ClearCacheCommandTest.php +++ b/tests/Unit/Internal/Framework/Cache/Command/ClearCacheCommandTest.php @@ -10,9 +10,9 @@ namespace OxidEsales\EshopCommunity\Tests\Unit\Internal\Framework\Cache\Command; use OxidEsales\EshopCommunity\Internal\Framework\Cache\Command\ClearCacheCommand; +use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\ShopPoolServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\DIContainer\Service\ContainerCacheInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\TemplateCacheService; +use OxidEsales\EshopCommunity\Internal\Framework\Templating\Cache\ShopTemplateCacheServiceInterface; use OxidEsales\EshopCommunity\Internal\Transition\Adapter\ShopAdapterInterface; use OxidEsales\EshopCommunity\Internal\Transition\Utility\ContextInterface; use PHPUnit\Framework\Attributes\Group; @@ -28,23 +28,23 @@ public function testClearCacheTriggersRegularAndTemplatesCleaners(): void $shopAdapterMock = $this->createMock(ShopAdapterInterface::class); $shopAdapterMock->expects($this->once())->method('invalidateModulesCache'); - $templateCacheServiceMock = $this->createMock(TemplateCacheService::class); - $templateCacheServiceMock->expects($this->once())->method('invalidateTemplateCache'); + $shopTemplateCacheServiceMock = $this->createMock(ShopTemplateCacheServiceInterface::class); + $shopTemplateCacheServiceMock->expects($this->once())->method('invalidateAllShopsCache'); $containerCacheMock = $this->createMock(ContainerCacheInterface::class); $containerCacheMock->expects($this->once())->method('invalidate'); - $moduleCacheServiceMock = $this->createMock(ModuleCacheServiceInterface::class); - $moduleCacheServiceMock->expects($this->once())->method('invalidateAll'); + $shopPoolServiceMock = $this->createMock(ShopPoolServiceInterface::class); + $shopPoolServiceMock->expects($this->once())->method('invalidate'); $contextMock = $this->createMock(ContextInterface::class); $contextMock->expects($this->once())->method('getAllShopIds')->willReturn([1]); $command = new ClearCacheCommand( $shopAdapterMock, - $templateCacheServiceMock, + $shopTemplateCacheServiceMock, $containerCacheMock, - $moduleCacheServiceMock, + $shopPoolServiceMock, $contextMock ); diff --git a/tests/Unit/Internal/Framework/Module/Cache/InvalidateModuleCacheEventSubscriberTest.php b/tests/Unit/Internal/Framework/Module/Cache/InvalidateModuleCacheEventSubscriberTest.php index 98ca100eaa..67d678beb1 100644 --- a/tests/Unit/Internal/Framework/Module/Cache/InvalidateModuleCacheEventSubscriberTest.php +++ b/tests/Unit/Internal/Framework/Module/Cache/InvalidateModuleCacheEventSubscriberTest.php @@ -9,29 +9,27 @@ namespace OxidEsales\EshopCommunity\Tests\Unit\Internal\Framework\Module\Cache; +use OxidEsales\EshopCommunity\Internal\Framework\Cache\Pool\ShopPoolServiceInterface; use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\InvalidateModuleCacheEventSubscriber; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Cache\ModuleCacheServiceInterface; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\FinalizingModuleActivationEvent; -use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\FinalizingModuleDeactivationEvent; use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Event\ModuleSetupEvent; use PHPUnit\Framework\TestCase; /** * @internal */ -class InvalidateModuleCacheEventSubscriberTest extends TestCase +final class InvalidateModuleCacheEventSubscriberTest extends TestCase { - public function testSubscriberCallsModuleCacheService() + public function testSubscriberCallsModuleCacheService(): void { - $moduleCacheService = $this->getMockBuilder(ModuleCacheServiceInterface::class)->getMock(); - $moduleCacheService + $shopPoolService = $this->getMockBuilder(ShopPoolServiceInterface::class)->getMock(); + $shopPoolService ->expects($this->once()) ->method('invalidate'); $event = new class (1, 'testModuleId') extends ModuleSetupEvent { }; - $subscriber = new InvalidateModuleCacheEventSubscriber($moduleCacheService); + $subscriber = new InvalidateModuleCacheEventSubscriber($shopPoolService); $subscriber->invalidateModuleCache($event); } }