create(); $order = Order::query()->forceCreate([ 'id' => UuidHelper::v7()->toString(), 'shop_id' => $shop->id, 'reference' => new OrderReference(UuidHelper::v7()), '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(UuidHelper::v7()), 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)) ->and($dto->toArray())->toBe([ 'id' => (int) $line->id, 'order_id' => (string) $line->order_id, 'product_name' => 'Terrine de Foie Gras de Canard mi-cuit 500g', 'product_inco_id' => '999', 'product_brand_label' => ProductBrand::loue->label(), 'is_variable_weight' => false, 'price_kg_ttc' => '3938', 'quantity' => 2, 'unit_price' => '1969', 'unit_tax' => '108', 'unit_discount' => '0', 'tax_rate' => TaxRate::TVA_5_5->value, 'unit_price_ttc' => '2077', 'unit_price_discounted_ht' => '1969', 'total_ttc' => '4154', 'total_ht' => '3938', 'total_tax' => '216', 'total_discount' => '0', 'total_gross_ht' => '3938', ]); }); });