addArrayExtension example

public function testStockDataIsAppliedFromStorage(): void
    {
        $stockStorage = $this->createMock(AbstractStockStorage::class);
        $subscriber = new LoadProductStockSubscriber($stockStorage);

        $ids = new IdsCollection();

        $p1 = (new SalesChannelProductEntity())->assign(['id' => $ids->get('product-1')]);
        $p2 = (new SalesChannelProductEntity())->assign(['id' => $ids->get('product-2')]);

        $stock1 = new StockData($ids->get('product-1'), 10, false, 5, null, null);
        $stock1->addArrayExtension('extra', ['arbitrary-data1' => 'foo']);
        $stock2 = new StockData($ids->get('product-2'), 12, true);

        $stockStorage->expects(static::once())
            ->method('load')
            ->willReturn(new StockDataCollection([$stock1$stock2]));

        $event = new SalesChannelEntityLoadedEvent(
            $this->createMock(SalesChannelProductDefinition::class),
            [$p1$p2],
            $this->createMock(SalesChannelContext::class)
        );

        
/** * @internal * * @covers \Shopware\Core\Content\Product\Stock\StockData */
class StockDataTest extends TestCase
{
    public function testAccessors(): void
    {
        $stock = new StockData('12345', 10, true, 2, 5, true);
        $stock->addArrayExtension('extraData', ['foo' => 'bar']);

        static::assertEquals('12345', $stock->productId);
        static::assertEquals(10, $stock->stock);
        static::assertTrue($stock->available);
        static::assertEquals(2, $stock->minPurchase);
        static::assertEquals(5, $stock->maxPurchase);
        static::assertTrue($stock->isCloseout);

        static::assertInstanceOf(ArrayStruct::class$stock->getExtension('extraData'));
        static::assertEquals(['foo' => 'bar']$stock->getExtension('extraData')->all());
    }

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