102 lines
4.3 KiB
PHP
102 lines
4.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Dto\OrderLineDto;
|
||
|
|
use Domain\Enums\TaxRate;
|
||
|
|
use Money\Money;
|
||
|
|
|
||
|
|
describe('OrderLineDto', function (): void {
|
||
|
|
it('instantiates correctly with flattened properties and exposes unitPriceTtc', function (): void {
|
||
|
|
// GIVEN
|
||
|
|
$id = 42;
|
||
|
|
$orderId = '018f6c40-1234-7123-8123-123456789012';
|
||
|
|
$productName = 'Terrine de Foie Gras';
|
||
|
|
$productIncoId = '12345';
|
||
|
|
$productBrandLabel = 'LDC';
|
||
|
|
$isVariableWeight = false;
|
||
|
|
$priceKgTtc = Money::EUR(3938);
|
||
|
|
$quantity = 2;
|
||
|
|
$unitPrice = Money::EUR(1969);
|
||
|
|
$unitTax = Money::EUR(108);
|
||
|
|
$unitDiscount = Money::EUR(0);
|
||
|
|
$taxRate = TaxRate::TVA_5_5;
|
||
|
|
$unitPriceTtc = Money::EUR(2077);
|
||
|
|
$totalHt = Money::EUR(3938);
|
||
|
|
$totalTax = Money::EUR(216);
|
||
|
|
$totalDiscount = Money::EUR(0);
|
||
|
|
$totalTtc = Money::EUR(4154);
|
||
|
|
$unitPriceDiscountedHt = Money::EUR(1969);
|
||
|
|
$totalGrossHt = Money::EUR(3938);
|
||
|
|
|
||
|
|
// WHEN
|
||
|
|
$dto = new OrderLineDto(
|
||
|
|
id: $id,
|
||
|
|
order_id: $orderId,
|
||
|
|
product_name: $productName,
|
||
|
|
product_inco_id: $productIncoId,
|
||
|
|
product_brand_label: $productBrandLabel,
|
||
|
|
is_variable_weight: $isVariableWeight,
|
||
|
|
price_kg_ttc: $priceKgTtc,
|
||
|
|
quantity: $quantity,
|
||
|
|
unit_price: $unitPrice,
|
||
|
|
unit_tax: $unitTax,
|
||
|
|
unit_discount: $unitDiscount,
|
||
|
|
tax_rate: $taxRate,
|
||
|
|
unit_price_ttc: $unitPriceTtc,
|
||
|
|
total_ht: $totalHt,
|
||
|
|
total_tax: $totalTax,
|
||
|
|
total_discount: $totalDiscount,
|
||
|
|
total_ttc: $totalTtc,
|
||
|
|
unitPriceDiscountedHt: $unitPriceDiscountedHt,
|
||
|
|
totalGrossHt: $totalGrossHt,
|
||
|
|
);
|
||
|
|
|
||
|
|
// THEN
|
||
|
|
expect($dto->id)->toBe($id)
|
||
|
|
->and($dto->order_id)->toBe($orderId)
|
||
|
|
->and($dto->product_name)->toBe($productName)
|
||
|
|
->and($dto->product_inco_id)->toBe($productIncoId)
|
||
|
|
->and($dto->product_brand_label)->toBe($productBrandLabel)
|
||
|
|
->and($dto->is_variable_weight)->toBe($isVariableWeight)
|
||
|
|
->and($dto->price_kg_ttc)->toBe($priceKgTtc)
|
||
|
|
->and($dto->quantity)->toBe($quantity)
|
||
|
|
->and($dto->unit_price)->toBe($unitPrice)
|
||
|
|
->and($dto->unit_tax)->toBe($unitTax)
|
||
|
|
->and($dto->unit_discount)->toBe($unitDiscount)
|
||
|
|
->and($dto->tax_rate)->toBe($taxRate)
|
||
|
|
->and($dto->unit_price_ttc)->toBe($unitPriceTtc)
|
||
|
|
->and($dto->unitPriceTtc)->toBe($unitPriceTtc)
|
||
|
|
->and($dto->unit_price_discounted_ht)->toBe($unitPriceDiscountedHt)
|
||
|
|
->and($dto->unitPriceDiscountedHt)->toBe($unitPriceDiscountedHt)
|
||
|
|
->and($dto->total_gross_ht)->toBe($totalGrossHt)
|
||
|
|
->and($dto->totalGrossHt)->toBe($totalGrossHt)
|
||
|
|
->and($dto->total_ht)->toBe($totalHt)
|
||
|
|
->and($dto->total_tax)->toBe($totalTax)
|
||
|
|
->and($dto->total_discount)->toBe($totalDiscount)
|
||
|
|
->and($dto->total_ttc)->toBe($totalTtc);
|
||
|
|
|
||
|
|
expect($dto->toArray())->toBe([
|
||
|
|
'id' => $id,
|
||
|
|
'order_id' => $orderId,
|
||
|
|
'product_name' => $productName,
|
||
|
|
'product_inco_id' => $productIncoId,
|
||
|
|
'product_brand_label' => $productBrandLabel,
|
||
|
|
'is_variable_weight' => $isVariableWeight,
|
||
|
|
'price_kg_ttc' => '3938',
|
||
|
|
'quantity' => $quantity,
|
||
|
|
'unit_price' => '1969',
|
||
|
|
'unit_tax' => '108',
|
||
|
|
'unit_discount' => '0',
|
||
|
|
'tax_rate' => $taxRate->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',
|
||
|
|
]);
|
||
|
|
});
|
||
|
|
});
|