StaticEntityRepository example



    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);

        

        $this->firstRunWizardService = $this->createMock(FirstRunWizardService::class);
    }

    public function testStartFrw(): void
    {
        $this->firstRunWizardService->expects(static::once())
            ->method('startFrw');

        $frwController = new FirstRunWizardController(
            $this->firstRunWizardService,
            new StaticEntityRepository([]),
            new StaticEntityRepository([]),
        );

        $response = $frwController->frwStart($this->createContext());

        static::assertSame(SymfonyResponse::HTTP_OK, $response->getStatusCode());
    }

    public function testTryingToStartFrwFails(): void
    {
        $exceptionMessage = 'frwService::frwStart failed';
        
$this->salesChannelContextService = $this->createMock(SalesChannelContextService::class);
    }

    public function testGenerateUserRecoveryUserNotFound(): void
    {
        $userEmail = 'nonexistent@example.com';
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
        $recoveryEntity = new UserRecoveryEntity();
        $recoveryEntity->setUniqueIdentifier(Uuid::randomHex());

        /** @var StaticEntityRepository<UserCollection> $userRepository */
        $userRepository = new StaticEntityRepository([
            new UserCollection([]),
        ]new UserDefinition());

        /** @var StaticEntityRepository<UserRecoveryCollection> $recoveryRepository */
        $recoveryRepository = new StaticEntityRepository([
            new UserRecoveryCollection([$recoveryEntity]),
            new UserRecoveryCollection([$recoveryEntity]),
        ]new UserRecoveryDefinition());

        /** @var StaticEntityRepository<SalesChannelCollection> $salesChannelRepository */
        $salesChannelRepository = new StaticEntityRepository([
            

    private StaticEntityRepository $appFlowEventRepository;

    protected function setUp(): void
    {
        $appFlowEvent = new AppFlowEventEntity();
        $appFlowEvent->setUniqueIdentifier(Uuid::randomHex());
        $appFlowEvent->setAware(['customerId']);
        $appFlowEvent->setName('custom.checkout.event');

        $this->appFlowEventRepository = new StaticEntityRepository([
            new EntitySearchResult(
                'app_flow_event',
                1,
                new AppFlowEventCollection([$appFlowEvent]),
                null,
                new Criteria(),
                Context::createDefaultContext(),
            ),
        ]);

        $this->triggerFlowController = new TriggerFlowController(new EventDispatcher()$this->appFlowEventRepository);
    }

class ProductPriceCalculatorTest extends TestCase
{
    private ProductPriceCalculator $calculator;

    protected function setUp(): void
    {
        $this->calculator = new ProductPriceCalculator(
            new StaticEntityRepository([
                new UnitCollection([(
                new UnitEntity())->assign(['id' => Defaults::CURRENCY, 'translated' => ['name' => 'test']])]),
            ]),
            new QuantityPriceCalculator(
                new GrossPriceCalculator(new TaxCalculator()new CashRounding()),
                new NetPriceCalculator(new TaxCalculator()new CashRounding())
            )
        );
    }

    /** * @dataProvider priceWillBeCalculated */

#[Package('buyers-experience')] class SalesChannelCreateStorefrontCommandTest extends TestCase
{
    /** * @param array<IdSearchResult> $idsSearchResult * * @dataProvider dataProviderTestExecuteCommandSuccessful */
    public function testExecuteCommandSuccessful(?string $snippetSetId = null, ?string $isoCode = null, array $idsSearchResult = []): void
    {
        $snippetSetRepository = new StaticEntityRepository($idsSearchResult);

        $foundSnippetSetId = $snippetSetId;
        if (!$foundSnippetSetId) {
            /** @var IdSearchResult $idSearchResult */
            foreach ($idsSearchResult as $idSearchResult) {
                $foundSnippetSetId = $idSearchResult->firstId() ?: $foundSnippetSetId;
            }
        }

        $mockSalesChannelCreator = $this->createMock(SalesChannelCreator::class);

        

class AppLifecycleTest extends TestCase
{
    public function testInstallNotCompatibleApp(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/manifest.xml');
        $manifest->getMetadata()->assign(['compatibility' => '~7.0.0']);

        $appRepository = $this->createMock(EntityRepository::class);
        $appRepository->expects(static::never())->method('upsert');

        $appLifecycle = $this->getAppLifecycle(new StaticEntityRepository([])new StaticEntityRepository([]), null, $this->createMock(AppLoader::class));

        static::expectException(AppException::class);
        static::expectExceptionMessage('App test is not compatible with this Shopware version');
        $appLifecycle->install($manifest, false, Context::createDefaultContext());
    }

    public function testUpdateNotCompatibleApp(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/manifest.xml');
        $manifest->getMetadata()->assign(['compatibility' => '~7.0.0']);

        

    public function testCriteriaWithUpdateProducts(array $ids, array $filters, Criteria $criteria): void
    {
        $context = Context::createDefaultContext();

        $connection = $this->createMock(Connection::class);
        $connection
            ->expects(static::once())
            ->method('fetchAllAssociative')
            ->willReturn($filters);

        $repository = new StaticEntityRepository([
            function DCriteria $actualCriteria, Context $actualContext) use ($criteria$context$ids): array {
                static::assertEquals($criteria$actualCriteria);
                static::assertEquals($context$actualContext);

                return $ids;
            },
        ]);

        $updater = new ProductStreamUpdater(
            $connection,
            new ProductDefinition(),
            
$this->configureRegistry([
            'Media' => $mediaDefinition = $this->getMediaDefinition([]),
        ]);

        $id1 = Uuid::randomHex();
        $id2 = Uuid::randomHex();

        $media1 = $this->createMedia($id1);
        $media2 = $this->createMedia($id2);

        /** @var StaticEntityRepository<MediaCollection> $repo */
        $repo = new StaticEntityRepository(
            [
                function DCriteria $criteria, Context $context) use ($id1$id2) {
                    $filters = $criteria->getFilters();

                    self::assertCount(0, $filters);

                    return [$id1$id2];
                },
                function DCriteria $criteria, Context $context) use ($id1$id2$media1$media2) {
                    static::assertSame([$id1$id2]$criteria->getIds());

                    
'core.loginRegistration.showAccountTypeSelection' => true,
                'core.loginRegistration.passwordMinLength' => '8',
            ],
            'core.systemWideLoginRegistration.isCustomerBoundToSalesChannel' => true,
        ]);

        $customerEntity = new CustomerEntity();
        $customerEntity->setDoubleOptInRegistration(false);
        $customerEntity->setId('customer-1');
        $customerEntity->setGuest(false);

        $customerRepository = new StaticEntityRepository([
            new EntitySearchResult(
                'customer',
                1,
                new EntityCollection([$customerEntity]),
                null,
                new Criteria(),
                Context::createDefaultContext(),
            ),
        ]new CustomerDefinition());

        $definition = new DataValidationDefinition('address.create');

        
'fields' => [
                ['type' => 'media', 'value' => $mediaId1],
            ],
        ];
        $themeConfig2 = [
            'fields' => [
                ['type' => 'media', 'value' => $mediaId2],
                ['type' => 'media', 'value' => $mediaId3],
            ],
        ];

        $themeRepository = new StaticEntityRepository([
            function DCriteria $criteria, Context $context) use ($themeId1$themeId2) {
                return new IdSearchResult(2, [['primaryKey' => $themeId1, 'data' => []]['primaryKey' => $themeId2, 'data' => []]]$criteria$context);
            },
        ]);

        $themeConfigMap = [
            $themeId1 => $themeConfig1,
            $themeId2 => $themeConfig2,
        ];

        $themeService = $this->createMock(ThemeService::class);
        
/** * @internal * * @covers \Shopware\Storefront\Theme\ConfigLoader\DatabaseAvailableThemeProvider */
#[Package('storefront')] class DatabaseAvailableThemeProviderTest extends TestCase
{
    public function testThemeProviderThrowsOnGetDecorated(): void
    {
        $themeProvider = new DatabaseAvailableThemeProvider(new StaticEntityRepository([]));

        static::expectException(DecorationPatternException::class);
        $themeProvider->getDecorated();
    }

    public function testLoadThrowsExceptionInNextMajorWhenCalledWithOnlyOneParameter(): void
    {
        $themeProvider = new DatabaseAvailableThemeProvider(new StaticEntityRepository([new SalesChannelCollection()]));

        static::expectException(\RuntimeException::class);
        $themeProvider->load(Context::createDefaultContext());
    }
$requestData->add([
            'email' => 'test@example.com',
            'option' => 'direct',
            'firstName' => 'Y',
            'lastName' => 'Tran',
        ]);

        $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);
        

class PluginUpdateAllCommandTest extends TestCase
{
    public function testNoUpdates(): void
    {
        $pluginService = $this->createMock(PluginService::class);
        $pluginService->expects(static::once())->method('refreshPlugins');

        $pluginRepository = new StaticEntityRepository([new PluginCollection([
            $this->createPlugin('Test'),
            $this->createPlugin('Test2'),
        ])]);

        $pluginLifecycleService = $this->createMock(PluginLifecycleService::class);
        $pluginLifecycleService->expects(static::never())->method('updatePlugin');

        $command = new PluginUpdateAllCommand($pluginService$pluginRepository$pluginLifecycleService);
        $command->setHelperSet(new HelperSet());

        $tester = new CommandTester($command);
        
/** * @internal * * @covers \Shopware\Core\Framework\MessageQueue\ScheduledTask\Scheduler\TaskRunner */
class TaskRunnerTest extends TestCase
{
    public function testNonExistingTask(): void
    {
        /** @var StaticEntityRepository<ScheduledTaskCollection> $scheduledTaskRepository */
        $scheduledTaskRepository = new StaticEntityRepository([new ScheduledTaskCollection()]);
        $taskRunner = new TaskRunner([]$scheduledTaskRepository);

        $this->expectException(MessageQueueException::class);
        $this->expectExceptionMessage('Cannot find scheduled task by name "non-existing-task"');
        $taskRunner->runSingleTask('non-existing-task', Context::createDefaultContext());
    }

    public function testRunTaskTriggersHandler(): void
    {
        $handler = new TestTaskHandler();
        $handler2 = new TestTask2Handler();
        
Home | Imprint | This part of the site doesn't use cookies.