StaticSystemConfigService example



        $newsletterRecipientEntity = new NewsletterRecipientEntity();
        $newsletterRecipientEntity->setId(Uuid::randomHex());
        $newsletterRecipientEntity->setConfirmedAt(new \DateTime());

        $entityRepository = new StaticEntityRepository([
            [$newsletterRecipientEntity->getId()],
            new NewsletterRecipientCollection([$newsletterRecipientEntity]),
        ]);

        $systemConfig = new StaticSystemConfigService([
            TestDefaults::SALES_CHANNEL => [
                'core.newsletter.doubleOptIn' => true,
            ],
        ]);

        $eventDispatcher = $this->createMock(EventDispatcherInterface::class);
        $eventDispatcher
            ->expects(static::once())
            ->method('dispatch')
            ->willReturnOnConsecutiveCalls(
                static::isInstanceOf(BuildValidationEvent::class),
                
class PagingProcessorTest extends TestCase
{
    /** * @dataProvider prepareProvider */
    public function testPrepare(Request $request, Criteria $expected, string $method = Request::METHOD_GET): void
    {
        $request->setMethod($method);
        $criteria = new Criteria();
        $context = $this->createMock(SalesChannelContext::class);

        $config = new StaticSystemConfigService([
            'core.listing.productsPerPage' => 24,
        ]);

        $processor = new PagingListingProcessor($config);
        $processor->prepare($request$criteria$context);

        static::assertSame($expected->getOffset()$criteria->getOffset());
        static::assertSame($expected->getLimit()$criteria->getLimit());
    }

    public static function prepareProvider(): \Generator
    {
self::getSystemConfigServiceMock('salesChannelId', 'salesChannelSpecificDefault'),
            self::getCategory(null, false),
            null,
            'salesChannelSpecificDefault',
            'salesChannelId',
        ];
    }

    private static function getSystemConfigServiceMock(?string $salesChannelId = null, ?string $cmsPageId = null): SystemConfigService
    {
        if ($salesChannelId === null && $cmsPageId === null) {
            return new StaticSystemConfigService([]);
        }

        if ($salesChannelId === null) {
            return new StaticSystemConfigService([
                CategoryDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_CATEGORY => $cmsPageId,
            ]);
        }

        return new StaticSystemConfigService([
            $salesChannelId => [
                CategoryDefinition::CONFIG_KEY_DEFAULT_CMS_PAGE_CATEGORY => $cmsPageId,
            ],
$salesChannelContext = $this->mockSalesChannelContext();
        $actual = $customerProfileValidationFactory->create($salesChannelContext);
        $expected = new DataValidationDefinition('customer.profile.create');
        $this->addConstraintsSalesChannelContext($expected$salesChannelContext);

        static::assertEquals($expected$actual);
    }

    public function testCreateWithSalesChannelContextButBirthdayFieldIsHidden(): void
    {
        $configService = new StaticSystemConfigService([
            TestDefaults::SALES_CHANNEL => ['core.loginRegistration.showBirthdayField' => false],
        ]);

        $customerProfileValidationFactory = new CustomerProfileValidationFactory(
            $this->salutationDefinition,
            $configService,
            $this->accountTypes,
        );

        $salesChannelContext = $this->mockSalesChannelContext();
        $actual = $customerProfileValidationFactory->create($salesChannelContext);
        
public function testInvalidDomain(): void
    {
        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('Expected domain');

        $configService = new ConfigurationService(
            [],
            new ConfigReader(),
            $this->createMock(AppLoader::class),
            new StaticEntityRepository([]),
            new StaticSystemConfigService([])
        );

        static::assertFalse($configService->checkConfiguration('invalid!', Context::createDefaultContext()));

        $configService->getConfiguration('invalid!', Context::createDefaultContext());
    }

    public function testMissingConfig(): void
    {
        $this->expectException(ConfigurationNotFoundException::class);

        
use Shopware\Core\Test\Stub\SystemConfigService\StaticSystemConfigService;

/** * @internal * * @covers \Shopware\Core\System\UsageData\Approval\ApprovalDetector */
class ApprovalDetectorTest extends TestCase
{
    public function testNeedsApprovalReturnsThePassedInParameter(): void
    {
        $approvalDetector = new ApprovalDetector(false, new StaticSystemConfigService());

        static::assertFalse($approvalDetector->needsApprovalRequest());

        $approvalDetector = new ApprovalDetector(true, new StaticSystemConfigService());

        static::assertTrue($approvalDetector->needsApprovalRequest());
    }

    public function testApprovalIsNotRequestedIfConfigValueIsNotSet(): void
    {
        $approvalDetector = new ApprovalDetector(true, new StaticSystemConfigService());

        
$paymentHandlerRegistry = $this->createMock(PaymentHandlerRegistry::class);
        $paymentHandlerRegistry->expects(static::once())->method('getPaymentMethodHandler')->with($transaction->getPaymentMethodId())->willReturn($paymentHandler);

        $initialStateIdLoader = $this->createMock(InitialStateIdLoader::class);
        $initialStateIdLoader->expects(static::once())->method('get')->willReturn(OrderTransactionStates::STATE_OPEN);

        $processor = new PaymentTransactionChainProcessor(
            $this->createMock(TokenFactoryInterfaceV2::class),
            $orderRepository,
            $this->createMock(RouterInterface::class),
            $paymentHandlerRegistry,
            new StaticSystemConfigService([]),
            $initialStateIdLoader,
            $paymentStructFactory,
            $eventDispatcher,
        );

        static::assertNull($processor->process('orderId', $requestDataBag$context));
    }
}


        $subscriber->salesChannelLoaded($event);

        static::assertSame($expected$entity->get('cmsPageId'));
    }

    public static function resolveCmsPageIdProviderWithLoadedEventProvider(): \Generator
    {
        yield 'It does not set cms page id if already given' => [
            (new ProductEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => 'own-id']),
            new StaticSystemConfigService([self::CONFIG => 'config-id']),
            'own-id',
        ];

        yield 'It does not set if no default is given' => [
            (new ProductEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => null]),
            new StaticSystemConfigService(),
            null,
        ];

        yield 'It sets cms page id if none is given and default is provided' => [
            (new ProductEntity())->assign(['id' => Uuid::randomHex(), 'cmsPageId' => null]),
            

class SortingProcessorTest extends TestCase
{
    /** * @dataProvider prepareProvider * * @param FieldSorting[] $expected */
    public function testPrepare(string $requested, array $expected): void
    {
        $processor = new SortingListingProcessor(
            new StaticSystemConfigService([
                'core.listing.defaultSorting' => 'foo',
            ]),
            new StaticEntityRepository([$this->buildSortings()])
        );

        $processor->prepare(
            new Request(['order' => $requested]),
            $criteria = new Criteria(),
            $this->createMock(SalesChannelContext::class)
        );

        
->willReturn((new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT));

        $frwService = $this->createFirstRunWizardService(
            systemConfigService: $systemConfigService,
        );

        static::assertFalse($frwService->frwShouldRun());
    }

    public function testFrwShouldNotRunIfStatusIsFailedAndFailureCountIsAboveThreshold(): void
    {
        $systemConfigService = new StaticSystemConfigService([
            'core.frw.failureCount' => 4,
            'core.frw.completedAt' => '',
            'core.frw.failedAt' => (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);

        $frwService = $this->createFirstRunWizardService(
            systemConfigService: $systemConfigService,
        );

        static::assertFalse($frwService->frwShouldRun());
    }

    
use Shopware\Tests\Unit\Common\Stubs\SystemConfigService\StaticSystemConfigService;

/** * @internal * * @covers \Shopware\Storefront\Theme\SeedingThemePathBuilder */
class SeedingThemePathBuilderTest extends TestCase
{
    public function testAssemblePathDoesNotChangeWithoutChangedSeed(): void
    {
        $pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $path = $pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme');

        static::assertEquals($path$pathBuilder->assemblePath(TestDefaults::SALES_CHANNEL, 'theme'));
    }

    public function testAssembledPathAfterSavingIsTheSameAsPreviouslyGenerated(): void
    {
        $pathBuilder = new SeedingThemePathBuilder(new StaticSystemConfigService());

        $generatedPath = $pathBuilder->generateNewPath(TestDefaults::SALES_CHANNEL, 'theme', 'foo');

        
$this->createMock(SnippetFinderInterface::class),
            [],
            $this->createMock(KnownIpsCollectorInterface::class),
            $this->createMock(Connection::class),
            $this->createMock(EventDispatcherInterface::class),
            '',
            new StaticEntityRepository([$collection]),
            $this->createMock(EntityRepository::class),
            $this->createMock(HtmlSanitizer::class),
            $this->createMock(DefinitionInstanceRegistry::class),
            $this->createMock(ParameterBagInterface::class),
            new StaticSystemConfigService([
                'core.systemWideLoginRegistration.isCustomerBoundToSalesChannel' => $isCustomerBoundToSalesChannel,
            ])
        );
    }
}
private StaticSystemConfigService $config;

    private MockObject&EventDispatcherInterface $eventDispatcher;

    private ProductReviewSaveRoute $route;

    protected function setUp(): void
    {
        $this->repository = $this->createMock(EntityRepository::class);
        $this->validator = $this->createMock(DataValidator::class);
        $this->config = new StaticSystemConfigService([
            'test' => [
                'core.listing.showReview' => true,
                'core.basicInformation.email' => 'noreply@example.com',
            ],
        ]);
        $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class);

        $this->route = new ProductReviewSaveRoute(
            $this->repository,
            $this->validator,
            $this->config,
            
$commandTester->execute([
            'key' => $key,
            '--salesChannelId' => TestDefaults::SALES_CHANNEL,
            '--format' => $format,
        ]);

        return trim($commandTester->getDisplay());
    }

    private function getConfigGetCommand(): ConfigGet
    {
        $systemConfigService = new StaticSystemConfigService([]);

        $systemConfigService->set('foo.bar.testString', 'test', TestDefaults::SALES_CHANNEL);
        $systemConfigService->set('foo.bar.testInt', 123, TestDefaults::SALES_CHANNEL);
        $systemConfigService->set('foo.bar.testBoolTrue', true, TestDefaults::SALES_CHANNEL);
        $systemConfigService->set('foo.bar.testBoolFalse', false, TestDefaults::SALES_CHANNEL);

        return new ConfigGet($systemConfigService);
    }
}
/** * @internal * * @covers \Shopware\Core\Checkout\Customer\SalesChannel\RegisterRoute */
#[Package('checkout')] class RegisterRouteTest extends TestCase
{
    public function testAccountType(): void
    {
        $systemConfigService = new StaticSystemConfigService([
            TestDefaults::SALES_CHANNEL => [
                'core.loginRegistration.showAccountTypeSelection' => true,
                'core.loginRegistration.passwordMinLength' => '8',
            ],
            'core.systemWideLoginRegistration.isCustomerBoundToSalesChannel' => true,
        ]);

        $result = $this->createMock(EntitySearchResult::class);
        $customerEntity = new CustomerEntity();
        $customerEntity->setDoubleOptInRegistration(false);
        $customerEntity->setId('customer-1');
        
Home | Imprint | This part of the site doesn't use cookies.