EntityCollection example

public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $productStream = new ProductStreamEntity();
        $productStream->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'product_stream',
                1,
                new EntityCollection([$productStream]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new ProductStreamAdminSearchIndexer(
            $this->createMock(Connection::class),
            $this->createMock(IteratorFactory::class),
            $repository,
            100
        );
$productExportEntity->setUniqueIdentifier('TestExportEntity');
        $productExportEntity->setId('afdd4e21be6b4ad59656fb856d0375e5');

        return $productExportEntity;
    }

    private function getProductExportRepositoryMock(ProductExportEntity $productExportEntity): EntityRepository
    {
        $productEntitySearchResult = new EntitySearchResult(
            'product',
            1,
            new EntityCollection([$productExportEntity]),
            null,
            new Criteria(),
            Context::createDefaultContext()
        );

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

        return $productExportRepositoryMock;
    }

    
if ($result instanceof EntitySearchResult) {
            return $result;
        }

        if ($result instanceof EntityCollection) {
            /** @var TEntityCollection $result */
            return new EntitySearchResult($this->getDummyEntityName()$result->count()$result, null, $criteria$context);
        }

        if ($result instanceof AggregationResultCollection) {
            /** @var TEntityCollection $collection */
            $collection = new EntityCollection();

            return new EntitySearchResult($this->getDummyEntityName(), 0, $collection$result$criteria$context);
        }

        throw new \RuntimeException('Invalid mock repository configuration');
    }

    public function searchIds(Criteria $criteria, Context $context): IdSearchResult
    {
        $result = \array_shift($this->searches);
        $callable = $result;

        

                ]),
            ]),
            [
                ['group' => 'color', 'option' => 'red'],
            ],
        ];

        yield 'Test with partial entity' => [
            (new PartialEntity())->assign([
                '_uniqueIdentifier' => Uuid::randomHex(),
                'options' => new EntityCollection([
                    (new PartialEntity())->assign([
                        'id' => Uuid::randomHex(),
                        '_uniqueIdentifier' => Uuid::randomHex(),
                        'translated' => ['name' => 'red'],
                        'group' => (new PartialEntity())->assign([
                            '_uniqueIdentifier' => Uuid::randomHex(),
                            'translated' => ['name' => 'color'],
                        ]),
                    ]),
                ]),
            ]),
            [
if ($itemRounding instanceof CashRoundingConfig) {
            $order->setItemRounding($itemRounding);
        }

        if ($totalRounding instanceof CashRoundingConfig) {
            $order->setTotalRounding($totalRounding);
        }

        $searchResult = new EntitySearchResult(
            OrderDefinition::ENTITY_NAME,
            1,
            new EntityCollection([$order]),
            null,
            new Criteria(),
            Context::createDefaultContext(),
        );

        $orderRouteResponse = $this->createMock(OrderRouteResponse::class);
        $orderRouteResponse->expects(static::once())
            ->method('getOrders')
            ->willReturn($searchResult);

        $orderRoute = $this->createMock(OrderRoute::class);
        
<?php declare(strict_types=1);

use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;

use function PHPStan\Testing\assertType;

$collection = new EntityCollection(['foo' => new Entity()]);

if ($collection->has('foo')) {
    assertType(Entity::class$collection->get('foo'));
    assertType(Entity::class D '|null', $collection->get('bar'));
} else {
    assertType('null', $collection->get('foo'));
    assertType(Entity::class D '|null', $collection->get('bar'));
}

class TestBasicWithToManyExtension extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $extendable = new ArrayEntity([
            'id' => '1d23c1b015bf43fb97e89008cf42d6fe',
            'createdAt' => new \DateTime('2018-01-15T08:01:16.000+00:00'),
        ]);

        $collection = new EntityCollection([
            new ArrayEntity([
                'id' => '548faa1f7846436c85944f4aea792d96',
                'name' => 'toMany#1',
            ]),
        ]);

        $extendable->addExtension('toMany', $collection);

        return $extendable;
    }

    
public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $newsletterRecipient = new NewsletterRecipientEntity();
        $newsletterRecipient->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'newsletter_recipient',
                1,
                new EntityCollection([$newsletterRecipient]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new NewsletterRecipientAdminSearchIndexer(
            $this->createMock(Connection::class),
            $this->createMock(IteratorFactory::class),
            $repository,
            100
        );
static::assertSame('foo', $search['fullText']);
    }

    public function testSearchPartialEvent(): void
    {
        $product = new PartialEntity();
        $product->setUniqueIdentifier('test');

        $reader = $this->createMock(EntityReaderInterface::class);
        $reader
            ->method('read')
            ->willReturn(new EntityCollection([$product]));

        $eventDispatcher = new EventDispatcher();
        $event = null;
        $eventDispatcher->addListener(EntityLoadedContainerEvent::classstatic function D$inner) use (&$event): void {
            $event = $inner;
        });

        $repo = new EntityRepository(
            $this->createMock(EntityDefinition::class),
            $reader,
            $this->createMock(VersionManager::class),
            
public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $customer = new CustomerEntity();
        $customer->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'customer',
                1,
                new EntityCollection([$customer]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new CustomerAdminSearchIndexer(
            $this->createMock(Connection::class),
            $this->createMock(IteratorFactory::class),
            $repository,
            100
        );
return $this->entities->getAt($position);
    }

    /** * @return static * * @deprecated tag:v6.6.0 - reason:return-type-change - Return type will be changed to `static` */
    protected function createNew(iterable $elements = [])
    {
        if (!($elements instanceof EntityCollection)) {
            $elements = new EntityCollection($elements);
        }

        return new static(
            $this->entity,
            $elements->count(),
            $elements,
            $this->aggregations,
            $this->criteria,
            $this->context
        );
    }
}
public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $promotion = new PromotionEntity();
        $promotion->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'promotion',
                1,
                new EntityCollection([$promotion]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new PromotionAdminSearchIndexer(
            $this->createMock(Connection::class),
            $this->createMock(IteratorFactory::class),
            $repository,
            100
        );


                    return true;
                })
            );
        $order = new OrderEntity();
        $order->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'order',
                1,
                new EntityCollection([$order]),
                null,
                new Criteria(),
                Context::createDefaultContext()
            )
        );

        $persister = new OrderPersister($repository$this->orderConverter);

        $persister->persist($cart$this->getSalesChannelContext());
    }

    
public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $propertyGroup = new PropertyGroupEntity();
        $propertyGroup->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'property_group',
                1,
                new EntityCollection([$propertyGroup]),
                null,
                new Criteria(),
                $context
            )
        );

        $indexer = new PropertyGroupAdminSearchIndexer(
            $this->createMock(Connection::class),
            $this->createMock(IteratorFactory::class),
            $repository,
            100
        );
        $salesChannelContextFactory = $this->createMock(AbstractSalesChannelContextFactory::class);
        if ($salesChannelContextFactoryCreateCallable !== null) {
            $salesChannelContextFactory->method('create')->willReturnCallback($salesChannelContextFactoryCreateCallable);
        }

        $customerRepository = $this->createMock(EntityRepository::class);
        if ($customerRepositoryResultArray !== null) {
            $customerRepository->method('search')->willReturn(
                new EntitySearchResult(
                    'customer',
                    1,
                    new EntityCollection($customerRepositoryResultArray),
                    null,
                    new Criteria(),
                    Context::createDefaultContext()
                )
            );
        }

        $orderAddressRepository = $this->createMock(EntityRepository::class);
        if ($orderAddressRepositoryResultArray !== null) {
            $orderAddressRepository->method('search')->willReturn(
                new EntitySearchResult(
                    
Home | Imprint | This part of the site doesn't use cookies.