SystemConfigChangedEvent example

$this->subscriber = $this->getContainer()->get(LicenseHostChangedSubscriber::class);
    }

    public function testIsSubscribedToSystemConfigChangedEvents(): void
    {
        static::assertArrayHasKey(SystemConfigChangedEvent::class$this->subscriber->getSubscribedEvents());
        static::assertEquals('onLicenseHostChanged', $this->subscriber->getSubscribedEvents()[SystemConfigChangedEvent::class]);
    }

    public function testOnlyHandlesLicenseHostChangedEvents(): void
    {
        $event = new SystemConfigChangedEvent('random.config.key', null, null);

        $this->subscriber->onLicenseHostChanged($event);
    }

    public function testDeletesShopSecretAndLogsOutAllUsers(): void
    {
        $context = Context::createDefaultContext();

        $systemConfigService = $this->getContainer()->get(SystemConfigService::class);
        $systemConfigService->set('core.store.shopSecret', 'shop-s3cr3t');

        
$this->createMock(ErrorController::class),
            $this->createMock(RequestStack::class),
            $this->createMock(SalesChannelContextServiceInterface::class),
            true,
            $this->createMock(CacheInterface::class),
            $this->createMock(AbstractCacheTracer::class),
            $this->createMock(EntityCacheKeyGenerator::class),
            $cacheInvalidator,
            new EventDispatcher()
        );

        $subscriber->onSystemConfigChanged(new SystemConfigChangedEvent($key, 'foo', null));
    }

    /** * @return iterable<string, array<mixed>> */
    public static function providerSystemConfigKeys(): iterable
    {
        yield 'key matches' => [
            'core.basicInformation.http404Page',
            true,
        ];

        
$event = new BeforeSystemConfigChangedEvent($key$value$salesChannelId);
            $this->eventDispatcher->dispatch($event);

            // Use modified value provided by potential event subscribers.             $value = $event->getValue();

            // On null value, delete the config             if ($value === null) {
                $toBeDeleted[] = $key;

                $events[] = new SystemConfigChangedEvent($key$value$salesChannelId);

                continue;
            }

            if (isset($existingIds[$key])) {
                $this->connection->update(
                    'system_config',
                    [
                        'configuration_value' => Json::encode(['_value' => $value]),
                        'updated_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    ],
                    [
$configStore = new MemoizedSystemConfigStore();
        $service = new MemoizedSystemConfigLoader($mock$configStore);

        $config = $service->load(TestDefaults::SALES_CHANNEL);
        static::assertSame($expectedConfig$config);

        $dispatcher = new EventDispatcher();
        $dispatcher->addSubscriber($configStore);

        // Dispatching the event resets the memoization and ensures load is called a second time.         $dispatcher->dispatch(new SystemConfigChangedEvent('abc.config.foo', 'none', TestDefaults::SALES_CHANNEL));

        // The load method is now called a second time as memoization has been reset for the sales channel.         $config = $service->load(TestDefaults::SALES_CHANNEL);
        static::assertSame($expectedConfig$config);
    }

    public function testMemoizationResetsOnValueChangeEventWithoutSalesChannelId(): void
    {
        $expectedConfig = ['abc' => ['config' => ['foo' => 'abc']]];

        $mock = $this->createMock(AbstractSystemConfigLoader::class);
        
Home | Imprint | This part of the site doesn't use cookies.