IdSearchResult example

foreach ($data as $key => $val) {
            static::assertSame($val$address->jsonSerialize()[$key]);
        }
    }

    public function testCustomFields(): void
    {
        $addressRepository = $this->createMock(EntityRepository::class);
        $addressRepository
            ->method('searchIds')
            ->willReturn(new IdSearchResult(1, [['data' => ['address-1'], 'primaryKey' => 'address-1']]new Criteria(), Context::createDefaultContext()));

        $result = $this->createMock(EntitySearchResult::class);
        $result->method('first')
            ->willReturn(new CustomerAddressEntity());

        $addressRepository
            ->method('search')
            ->willReturn($result);

        $addressRepository
            ->method('upsert')
            
static::assertEquals('4', $result->getProduct()->getCmsPageId());
        static::assertEquals('mainVariant', $result->getProduct()->getUniqueIdentifier());
    }

    public function testLoadBestVariant(): void
    {
        $productEntity = new SalesChannelProductEntity();
        $productEntity->setCmsPageId('4');
        $productEntity->setId($this->idsCollection->create('product1'));
        $productEntity->setUniqueIdentifier('BestVariant');

        $idsSearchResult = new IdSearchResult(
            1,
            [
                [
                    'primaryKey' => $this->idsCollection->get('product1'),
                    'data' => [],
                ],
            ],
            new Criteria(),
            $this->context->getContext()
        );
        $this->productRepository->method('searchIds')
            
->method('fromArray')
            ->with(['filter' => $filter])
            ->willReturn($criteria);

        $data = [
            ['primaryKey' => ['productId' => 'product-1', 'categoryId' => 'category-1'], 'data' => []],
            ['primaryKey' => ['productId' => 'product-1', 'categoryId' => 'category-2'], 'data' => []],
            ['primaryKey' => ['productId' => 'product-2', 'categoryId' => 'category-1'], 'data' => []],
            ['primaryKey' => ['productId' => 'product-2', 'categoryId' => 'category-2'], 'data' => []],
        ];

        $ids = new IdSearchResult(4, $datanew Criteria(), Context::createDefaultContext());

        $searcher->expects(static::once())
            ->method('search')
            ->willReturn($ids);

        $service = new SyncService(
            $writer,
            $this->createMock(EventDispatcherInterface::class),
            new StaticDefinitionInstanceRegistry(
                [ProductCategoryDefinition::class],
                $this->createMock(ValidatorInterface::class),
                


        if (!\is_array($result)) {
            throw new \RuntimeException('Invalid mock repository configuration');
        }

        // flat array of ids         if (\array_key_exists(0, $result) && \is_string($result[0])) {
            $result = \array_map(fn (string $id) => ['primaryKey' => $id, 'data' => []]$result);
        }

        return new IdSearchResult(\count($result)$result$criteria$context);
    }

    /** * @experimental */
    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        $writeResults = $this->getDummyWriteResults($data, EntityWriteResult::OPERATION_INSERT, $context);
        /** @var EntityWrittenEvent $entityWrittenEvent */
        $entityWrittenEvent = $writeResults->first();

        
$criteria->setLimit(1);
        $criteria->addFilter(new EqualsFilter('product.optionIds', $this->ids->get('option1')));
        $criteria->addFilter(new EqualsFilter('product.optionIds', $this->ids->get('option2')));

        $context = Context::createDefaultContext();

        $this->productRepositoryMock->method('searchIds')->with(
            $criteria,
            $this->createMock(SalesChannelContext::class),
        )
            ->willReturn(
                new IdSearchResult(
                    2,
                    [
                        [
                            'primaryKey' => $this->ids->get('found1'),
                            'data' => [],
                        ],
                        [
                            'primaryKey' => $this->ids->get('found2'),
                            'data' => [],
                        ],
                    ],
                    
public function testValidateShippingAddressWithMixedItems(): void
    {
        $cart = new Cart('test');
        $cart->add((new LineItem('a', 'test'))->setStates([State::IS_DOWNLOAD]));
        $context = $this->createMock(SalesChannelContext::class);

        $country = new CountryEntity();
        $country->setId(Uuid::randomHex());
        $country->setActive(true);
        $country->setShippingAvailable(false);

        $idSearchResult = new IdSearchResult(
            1,
            [['data' => $country->getId(), 'primaryKey' => $country->getId()]],
            new Criteria(),
            Context::createDefaultContext()
        );
        $this->repository->method('searchIds')->willReturn($idSearchResult);

        $shippingLocation = new ShippingLocation($country, null, null);
        $context->method('getShippingLocation')->willReturn($shippingLocation);

        $errorCollection = new ErrorCollection();
        
->willReturn(new ProductCollection([$productEntity$productEntity2$productEntity3$productEntity4]));

        $searcher = $this->createMock(EntitySearcherInterface::class);
        $data = [
            'test-1' => ['data' => ['fullText' => 'foo'], 'primaryKey' => 'test-1'],
            'test-2' => ['data' => [], 'primaryKey' => 'test-2'],
            'test-3' => ['data' => [], 'primaryKey' => 'test-3'],
        ];
        $searcher
            ->expects(static::once())
            ->method('search')
            ->willReturn(new IdSearchResult(4, $datanew Criteria(), Context::createDefaultContext()));

        $aggregator = $this->createMock(EntityAggregatorInterface::class);
        $aggregator->expects(static::never())->method('aggregate');

        $repo = new EntityRepository(
            new ProductDefinition(),
            $reader,
            $this->createMock(VersionManager::class),
            $searcher,
            $aggregator,
            $eventDispatcher,
            
#[Package('core')] class ElasticsearchEntitySearchHydrator extends AbstractElasticsearchSearchHydrator
{
    public function getDecorated(): AbstractElasticsearchSearchHydrator
    {
        throw new DecorationPatternException(self::class);
    }

    public function hydrate(EntityDefinition $definition, Criteria $criteria, Context $context, array $result): IdSearchResult
    {
        if (!isset($result['hits'])) {
            return new IdSearchResult(0, []$criteria$context);
        }

        $hits = $this->extractHits($result);

        $data = [];
        foreach ($hits as $hit) {
            $id = $hit['_id'];

            $data[$id] = [
                'primaryKey' => $id,
                'data' => array_merge(
                    

        $dataBag = new DataBag();
        $dataBag->set('tos', true);
        $context = $this->createMock(SalesChannelContext::class);

        $cart = new Cart('test');
        $cart->add((new LineItem('a', 'test'))->setStates([State::IS_PHYSICAL]));

        $this->cartService->method('getCart')->willReturn($cart);
        $this->cartService->expects(static::exactly(2))->method('order');

        $idSearchResult = new IdSearchResult(0, []new Criteria(), Context::createDefaultContext());
        $this->paymentMethodRepository->method('searchIds')->willReturn($idSearchResult);

        $this->orderService->createOrder($dataBag$context);

        $cart->add((new LineItem('b', 'test'))->setStates([State::IS_DOWNLOAD]));

        try {
            $this->orderService->createOrder($dataBag$context);

            static::fail('Did not throw exception');
        } catch (\Throwable $exception) {
            


        $result = $this->createMock(EntitySearchResult::class);
        $customerEntity = new CustomerEntity();
        $customerEntity->setDoubleOptInRegistration(false);
        $customerEntity->setId('customer-1');
        $customerEntity->setGuest(false);
        $result->method('first')->willReturn($customerEntity);

        $salutationId = Uuid::randomHex();

        $idSearchResult = new IdSearchResult(
            1,
            [['data' => $salutationId, 'primaryKey' => $salutationId]],
            new Criteria(),
            Context::createDefaultContext(),
        );

        $customerRepository = $this->createMock(EntityRepository::class);
        $customerRepository->method('search')->willReturn($result);
        $customerRepository
            ->expects(static::once())
            ->method('create')
            
$customerRepository = $this->createMock(EntityRepository::class);
        $customerRepository
            ->method('update')
            ->with(static::callback(function Darray $data) use ($salutationId) {
                static::assertCount(1, $data);
                static::assertIsArray($data[0]);
                static::assertSame($data[0]['salutationId']$salutationId);

                return true;
            }));

        $idSearchResult = new IdSearchResult(
            1,
            [['data' => $salutationId, 'primaryKey' => $salutationId]],
            new Criteria(),
            Context::createDefaultContext(),
        );

        $salutationRepository = $this->createMock(EntityRepository::class);
        $salutationRepository->method('searchIds')->willReturn($idSearchResult);

        $change = new ChangeCustomerProfileRoute(
            $customerRepository,
            
$addressRepository->expects(static::once())->method('search')->willReturn(
            new EntitySearchResult(
                'customer_address',
                1,
                new EntityCollection([$address]),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $idSearchResult = new IdSearchResult(
            1,
            [['data' => $salutationId, 'primaryKey' => $salutationId]],
            new Criteria(),
            Context::createDefaultContext(),
        );

        $salutationRepository = $this->createMock(EntityRepository::class);
        $salutationRepository->method('searchIds')->willReturn($idSearchResult);

        $systemConfigService = $this->createMock(SystemConfigService::class);

        
yield 'with snippetSetId input' => [
            'snippetSetId' => 'snippetSetId',
            'isoCode' => null,
            'idSearchResult' => [],
            'exception' => null,
        ];

        yield 'with valid isoCode' => [
            'snippetSetId' => null,
            'isoCode' => 'de-DE',
            'idSearchResult' => [
                new IdSearchResult(1, [['primaryKey' => 'snippetSetId', 'data' => []]]new Criteria(), Context::createDefaultContext()),
            ],
            'exception' => null,
        ];

        yield 'with not found isoCode, use en-GB as fallback' => [
            'snippetSetId' => null,
            'isoCode' => 'nl-NL',
            'idSearchResult' => [
                new IdSearchResult(0, []new Criteria(), Context::createDefaultContext()),
                new IdSearchResult(1, [['primaryKey' => 'snippetSetId', 'data' => []]]new Criteria(), Context::createDefaultContext()),
            ],
            


        if (!\is_array($result)) {
            throw new \RuntimeException('Invalid mock repository configuration');
        }

        // flat array of ids         if (\array_key_exists(0, $result) && \is_string($result[0])) {
            $result = \array_map(fn (string $id) => ['primaryKey' => $id, 'data' => []]$result);
        }

        return new IdSearchResult(\count($result)$result$criteria$context);
    }

    /** * @experimental */
    public function create(array $data, Context $context): EntityWrittenContainerEvent
    {
        $writeResults = $this->getDummyWriteResults($data, EntityWriteResult::OPERATION_INSERT, $context);
        /** @var EntityWrittenEvent $entityWrittenEvent */
        $entityWrittenEvent = $writeResults->first();

        
yield 'test not active' => [false, true, true];
        yield 'test not shipping available' => [true, false, true];
        yield 'test not assigned for sales channel' => [true, true, false];
        yield 'test not active and not shipping available' => [false, false, true];
        yield 'test not active, not shipping available, not assigned' => [false, false, false];
        yield 'test is valid' => [true, true, true];
    }

    private function getSearchResultStub(?bool $assigned = true, ?string $id = null): IdSearchResult
    {
        if ($assigned) {
            return new IdSearchResult(0, [['primaryKey' => $id ?? Uuid::randomHex(), 'data' => []]]new Criteria(), Context::createDefaultContext());
        }

        return new IdSearchResult(0, []new Criteria(), Context::createDefaultContext());
    }

    private function getRepositoryMock(?IdSearchResult $result): EntityRepository&MockObject
    {
        $repository = $this->createMock(EntityRepository::class);

        $repository->method('searchIds')
            ->willReturn($result);

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