getAt example

public function setEntity(string $entity): void
    {
        $this->entity = $entity;
    }

    /** * @return Entity|null */
    public function getAt(int $position)
    {
        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);
        }
if ($struct instanceof EntitySearchResult) {
            $data = $this->encodeStruct($struct$fields$data);

            if (isset($data['elements'])) {
                $entities = [];

                /** * @var int $index */
                foreach (\array_values($data['elements']) as $index => $value) {
                    $entity = $struct->getAt($index);
                    if (!$entity instanceof Struct) {
                        throw new \RuntimeException(\sprintf('Entity at index %d is not an struct', $index));
                    }

                    $entities[] = $this->encodeStruct($entity$fields$value);
                }
                $data['elements'] = $entities;
            }

            return $data;
        }

        
static::assertEquals('b', $collection->last());
    }

    public function testGetAt(): void
    {
        $collection = new TestCollection();
        static::assertFalse($collection->has(0));

        $collection->add('a');
        $collection->add('b');
        static::assertEquals('a', $collection->getAt(0));
        static::assertEquals('b', $collection->getAt(1));
    }
}

/** * @internal * * @extends Collection<string|ProductEntity|CategoryEntity> */
class TestCollection extends Collection
{
}

            ],
        ];

        $response = TaxProviderResponse::create($arrayStruct);

        static::assertNotNull($response->getLineItemTaxes());
        static::assertCount(2, $response->getLineItemTaxes());
        static::assertArrayHasKey($this->ids->get('line-item-1')$response->getLineItemTaxes());
        static::assertArrayHasKey($this->ids->get('line-item-2')$response->getLineItemTaxes());

        static::assertEquals(new CalculatedTax(1.0, 1.0, 1.0)$response->getLineItemTaxes()[$this->ids->get('line-item-1')]->getAt(0));
        static::assertEquals(new CalculatedTax(2.0, 2.0, 2.0)$response->getLineItemTaxes()[$this->ids->get('line-item-2')]->getAt(0));
        static::assertEquals(new CalculatedTax(3.0, 3.0, 3.0)$response->getLineItemTaxes()[$this->ids->get('line-item-2')]->getAt(1));

        static::assertNotNull($response->getDeliveryTaxes());
        static::assertCount(2, $response->getDeliveryTaxes());
        static::assertArrayHasKey($this->ids->get('delivery-1')$response->getDeliveryTaxes());
        static::assertArrayHasKey($this->ids->get('delivery-2')$response->getDeliveryTaxes());

        static::assertEquals(new CalculatedTax(4.0, 4.0, 4.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-1')]->getAt(0));
        static::assertEquals(new CalculatedTax(5.0, 5.0, 5.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-2')]->getAt(0));
        static::assertEquals(new CalculatedTax(6.0, 6.0, 6.0)$response->getDeliveryTaxes()[$this->ids->get('delivery-2')]->getAt(1));

        
$order = $this->orderRepository->search($criteria$this->salesChannelContext->getContext())->first();
        static::assertInstanceOf(OrderEntity::class$order);

        $lineItems = $order->getLineItems();
        static::assertNotNull($lineItems);
        $lineItems->sortByPosition();
        static::assertEquals(\count($productDownloads)$lineItems->count());
        static::assertTrue($lineItems->hasLineItemWithState(State::IS_DOWNLOAD));

        foreach ($productDownloads as $key => $downloadFiles) {
            $lineItem = $lineItems->getAt($key);
            static::assertNotNull($lineItem);
            static::assertNotNull($lineItem->getDownloads());
            static::assertEquals(\count($downloadFiles)$lineItem->getDownloads()->count());
            foreach ($lineItem->getDownloads() as $download) {
                static::assertFalse($download->isAccessGranted());

                try {
                    $request = new Request(['downloadId' => $download->getId(), 'orderId' => $orderId]);
                    $this->downloadRoute->load($request$this->salesChannelContext);

                    static::fail('Download route returned response without access granted');
                }
Home | Imprint | This part of the site doesn't use cookies.