invalidQuantity example


    public function __construct(
        protected string $id,
        protected string $type,
        protected ?string $referencedId = null,
        int $quantity = 1
    ) {
        $this->uniqueIdentifier = Uuid::randomHex();
        $this->children = new LineItemCollection();

        if ($quantity < 1) {
            throw CartException::invalidQuantity($quantity);
        }
        $this->quantity = $quantity;
    }

    /** * @throws CartException */
    public static function createFromLineItem(LineItem $lineItem): self
    {
        $self = new self($lineItem->id, $lineItem->type, $lineItem->getReferencedId()$lineItem->quantity);

        
'referencedId' => $productId,
            'type' => 'nonexistenttype',
            'stackable' => 1,
            'removable' => 1,
            'quantity' => 1,
        ];

        $request = new Request([]['lineItems' => [$productId => $lineItemData]]);
        $cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);

        $exception = CartException::invalidQuantity(1);
        $this->lineItemRegistryMock->expects(static::once())
            ->method('create')
            ->with($lineItemData$this->createMock(SalesChannelContext::class))
            ->willThrowException($exception);

        $this->cartService->expects(static::never())->method('add');

        $this->translatorCallback();

        $this->controller->addLineItems($cartnew RequestDataBag($request->request->all())$request$context);
    }

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