incoId)->toBe($incoId) ->and($product->originalId)->toBe($productId) ->and($product->name)->toBe('Product Name') ->and($product->weight)->toBe($weight) ->and($product->brand)->toBe(ProductBrand::marie) ->and($product->orderUnit)->toBe(OrderUnit::KGM) ->and($product->price->getAmount())->toBe('1000') ->and($product->discountedPrice->getAmount())->toBe('900') ->and($product->priceKgTtc->getAmount())->toBe('2000') ->and($product->taxRate)->toBe(TaxRate::TVA_5_5) ->and($product->picture)->toEqual(new StorageFilePath('pic.jpg')); }); it('throws exception if name is empty', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), '', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(100), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Product name cannot be empty'); }); it('throws exception if price is negative', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(-100), Money::EUR(100), Money::EUR(100), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Product price cannot be negative'); }); it('throws exception if discounted price is negative', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(-100), Money::EUR(100), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Product discounted price cannot be negative'); }); it('throws exception if price per kg ttc is negative', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(-100), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Price per kg TTC cannot be negative'); }); it('throws exception if discounted price is greater than price', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(150), Money::EUR(100), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Product discounted price cannot be greater than original price'); }); it('throws exception if price per kg ttc is zero', function (): void { // GIVEN // WHEN $action = fn () => new OrderLineProduct( new IncoId(1), new ProductId(UuidHelper::v7()), 'Name', new ProductWeight(1, false), ProductBrand::marie, OrderUnit::KGM, Money::EUR(100), Money::EUR(100), Money::EUR(0), TaxRate::TVA_5_5, ); // THEN expect($action)->toThrow(\DomainException::class, 'Price per kg TTC has to be positive'); }); });