create(); $order = Order::forceCreate([ 'id' => Uuid::uuid7()->toString(), 'shop_id' => $shop->id, 'reference' => new OrderReference(Uuid::uuid7()), 'status' => OrderStatus::VALIDATED->value, 'total' => Money::EUR(4154), 'employee' => new OrderEmployee(new Matricule('8888001'), 'Jean', 'Dupont', new ShopperEstablishmentCode('FAC01'), new ShopperSiteCode('SITE'), new ShopperServiceCode('101')), 'delivery_address' => new DeliveryAddress('Shop Name', 'Address', '75000', 'Paris'), 'pickup_day' => Date::now()->toDateString(), ]); $orderLineProduct = new OrderLineProduct( incoId: new IncoId(999), originalId: new ProductId(Uuid::uuid7()), name: 'Terrine de Foie Gras de Canard mi-cuit 500g', weight: new ProductWeight(500, false), brand: ProductBrand::loue, orderUnit: OrderUnit::PCE, price: Money::EUR(1969), discountedPrice: Money::EUR(1969), priceKgTtc: Money::EUR(3938), taxRate: TaxRate::TVA_5_5, picture: null, ); $line = new OrderLine(); $line->order()->associate($order); $line->product = $orderLineProduct; $line->quantity = 2; $line->unit_price = Money::EUR(1969); $line->unit_tax = Money::EUR(108); $line->unit_discount = Money::EUR(0); $line->tax_rate = TaxRate::TVA_5_5; $line->total_ttc = Money::EUR(4154); $line->total_ht = Money::EUR(3938); $line->total_tax = Money::EUR(216); $line->total_discount = Money::EUR(0); $line->save(); // WHEN $dto = OrderLineDto::fromModel($line); // THEN expect($line->unitPriceTtc)->toEqual(Money::EUR(2077)) ->and($dto->id)->toBe((int) $line->id) ->and($dto->order_id)->toBe((string) $line->order_id) ->and($dto->product_name)->toBe('Terrine de Foie Gras de Canard mi-cuit 500g') ->and($dto->product_inco_id)->toBe('999') ->and($dto->product_brand_label)->toBe(ProductBrand::loue->label()) ->and($dto->is_variable_weight)->toBeFalse() ->and($dto->price_kg_ttc)->toEqual(Money::EUR(3938)) ->and($dto->quantity)->toBe(2) ->and($dto->unit_price)->toEqual(Money::EUR(1969)) ->and($dto->unit_tax)->toEqual(Money::EUR(108)) ->and($dto->unit_discount)->toEqual(Money::EUR(0)) ->and($dto->tax_rate)->toBe(TaxRate::TVA_5_5) ->and($dto->unit_price_ttc)->toEqual(Money::EUR(2077)) ->and($dto->unitPriceTtc)->toEqual(Money::EUR(2077)) ->and($dto->total_ht)->toEqual(Money::EUR(3938)) ->and($dto->total_tax)->toEqual(Money::EUR(216)) ->and($dto->total_ttc)->toEqual(Money::EUR(4154)); }); });