LanguageCollection example


        return $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getTypeId());
    }

    public function filterByTypeId(string $id): SalesChannelCollection
    {
        return $this->filter(fn (SalesChannelEntity $salesChannel) => $salesChannel->getTypeId() === $id);
    }

    public function getLanguages(): LanguageCollection
    {
        return new LanguageCollection(
            $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getLanguage())
        );
    }

    public function getCurrencies(): CurrencyCollection
    {
        return new CurrencyCollection(
            $this->fmap(fn (SalesChannelEntity $salesChannel) => $salesChannel->getCurrency())
        );
    }

    

        $languageRepository = $this->createMock(EntityRepository::class);

        $languageRepository
            ->method('search')
            ->willReturnCallback(function DCriteria $criteria) {
                static::assertTrue($criteria->hasEqualsFilter('fooo'));
                $sortings = $criteria->getSorting();
                static::assertCount(1, $sortings);
                static::assertEquals('id', $sortings[0]->getField());

                return new EntitySearchResult('foo', 0, new LanguageCollection(), null, $criteria, Context::createDefaultContext());
            });

        $dispatcher = new EventDispatcher();
        $dispatcher->addListener(ElasticsearchIndexerLanguageCriteriaEvent::classfunction DElasticsearchIndexerLanguageCriteriaEvent $event): void {
            $event->getCriteria()->addFilter(new EqualsFilter('fooo', null));
        });

        $provider = new ElasticsearchLanguageProvider(
            $languageRepository,
            $dispatcher
        );

        

class IndexMappingUpdaterTest extends TestCase
{
    public function testUpdate(): void
    {
        $language = new LanguageEntity();
        $language->setId(Uuid::randomHex());

        $languageProvider = $this->createMock(ElasticsearchLanguageProvider::class);
        $languageProvider
            ->method('getLanguages')
            ->willReturn(new LanguageCollection([$language]));

        $elasticsearchHelper = $this->createMock(ElasticsearchHelper::class);
        $elasticsearchHelper->method('getIndexName')->willReturn('index');

        $registry = new ElasticsearchRegistry([
            $this->createMock(ElasticsearchProductDefinition::class),
        ]);

        $client = $this->createMock(Client::class);
        $indicesNamespace = $this->createMock(IndicesNamespace::class);
        $indicesNamespace
            


    /** * @return StaticEntityRepository<LanguageCollection> */
    private function getLanguageRepository(): StaticEntityRepository
    {
        $language = new LanguageEntity();
        $language->setId('foo');

        // @phpstan-ignore-next-line         return new StaticEntityRepository([new LanguageCollection([$language])new LanguageCollection([$language])]);
    }

    private function getComposerPackage(): CompletePackage
    {
        $completePackage = new CompletePackage('foo', '1.0.0', '1.0.0');
        $completePackage->setAutoload([
            'psr-4' => [
                'Foo\\' => 'bar',
            ],
        ]);
        $completePackage->setExtra([
            

        ]);

        $this->connection->method('fetchAllKeyValue')->willReturn(
            [
                '' => '{{ product.translated.name }}/{{ product.productNumber }}',
            ]
        );

        $seoUrlUpdater = $this->createSeoUrlUpdater(
            [
                new LanguageCollection([]),
            ],
            [
                new SalesChannelCollection([]),
            ],
            [
                new ProductPageSeoUrlRoute(new ProductDefinition()),
            ]
        );

        $this->seoUrlPersister->expects(static::never())->method('updateSeoUrls');

        
$this->language1 = new LanguageEntity();
        $this->language1->setId(Defaults::LANGUAGE_SYSTEM);
        $this->language1->setUniqueIdentifier(Defaults::LANGUAGE_SYSTEM);

        $language2 = new LanguageEntity();
        $language2->setId('2');
        $language2->setUniqueIdentifier('2');

        $this->languageRepository
            ->method('search')
            ->willReturn(new EntitySearchResult('language', 1, new LanguageCollection([$this->language1, $language2]), null, new Criteria(), Context::createDefaultContext()));

        $this->indices = $this->createMock(IndicesNamespace::class);
        $this->client->method('indices')->willReturn($this->indices);

        parent::setUp();
    }

    public function testIterateESDisabled(): void
    {
        $this->helper = $this->createMock(ElasticsearchHelper::class);
        $indexer = $this->getIndexer();

        
new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new LanguageRouteResponse(
            new EntitySearchResult(
                'entity',
                1,
                new LanguageCollection(),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $this->cachedRoute = new CachedLanguageRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            $this->createMock(AbstractCacheTracer::class),
            
private function getLanguageCollection(array $languageEntities = []): LanguageCollection
    {
        $entities = [];

        foreach ($languageEntities as $entity) {
            $languageEntity = new LanguageEntity();
            $languageEntity->assign($entity);

            $entities[] = $languageEntity;
        }

        return new LanguageCollection($entities);
    }

    /** * @param array<string, mixed> $data */
    private function getLocaleEntity(array $data = []): LocaleEntity
    {
        $localeEntity = new LocaleEntity();

        $localeEntity->assign($data);

        
$this->productRepository->create([$builder->build()], Context::createDefaultContext());

        $criteria = new Criteria();
        $criteria->addAssociations([
            'manufacturer',
            'prices',
            'categories',
        ]);

        /** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria, Context::createDefaultContext())->first();
        $product->addExtension('test', new LanguageCollection([
            (new LanguageEntity())->assign(['id' => $this->ids->create('l1'), '_entityName' => 'language']),
        ]));
        $events = $this->entityLoadedEventFactory->create([$product], Context::createDefaultContext());

        $createdEvents = $events->getEvents()->map(fn (EntityLoadedEvent $event): string => $event->getName());
        sort($createdEvents);

        static::assertEquals([
            'category.loaded',
            'language.loaded',
            'product.loaded',
            
$client = $this->createMock(Client::class);
        $client->method('indices')->willReturn($indices);

        $definition = $this->createMock(ElasticsearchProductDefinition::class);

        $registry = $this->createMock(ElasticsearchRegistry::class);
        $registry->method('getDefinitions')->willReturn([$definition$definition]);

        $makeLanguage = fn () => (new LanguageEntity())->assign(['id' => Uuid::randomHex()]);

        $collection = new EntitySearchResult('test', 1, new LanguageCollection([$makeLanguage()$makeLanguage()$makeLanguage()]), null, new Criteria(), Context::createDefaultContext());

        $repository = $this->createMock(EntityRepository::class);
        $repository
            ->method('search')
            ->willReturn($collection);

        $esHelper = $this->createMock(ElasticsearchHelper::class);

        if (Feature::isActive('ES_MULTILINGUAL_INDEX')) {
            $esHelper->method('enabledMultilingualIndex')->willReturn(true);
        }

        
Home | Imprint | This part of the site doesn't use cookies.