51 lines
1.8 KiB
PHP
51 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\App\Dto;
|
|
|
|
use App\Dto\DiscountDto;
|
|
use Domain\Enums\DiscountType;
|
|
use Domain\Models\ValueObjects\DiscountValue;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
describe('DiscountDto', function (): void {
|
|
it('creates a DTO from constructor and serializes to array', function (): void {
|
|
// GIVEN
|
|
$dateStart = Carbon::parse('2026-06-01 10:00:00');
|
|
$dateEnd = Carbon::parse('2026-06-30 20:00:00');
|
|
$value = DiscountValue::fromPercentage(20);
|
|
|
|
// WHEN
|
|
$dto = new DiscountDto(
|
|
id: 42,
|
|
type: DiscountType::PERCENT,
|
|
value: $value,
|
|
is_old_price_displayed: true,
|
|
date_start: $dateStart,
|
|
date_end: $dateEnd,
|
|
);
|
|
|
|
// THEN
|
|
expect($dto->id)->toBe(42)
|
|
->and($dto->type)->toBe(DiscountType::PERCENT)
|
|
->and($dto->value)->toBe($value)
|
|
->and($dto->is_old_price_displayed)->toBeTrue()
|
|
->and($dto->date_start)->toEqual($dateStart)
|
|
->and($dto->date_end)->toEqual($dateEnd)
|
|
->and($dto->getRouteKey())->toBe(42)
|
|
->and($dto->getRouteKeyName())->toBe('id')
|
|
->and($dto->resolveRouteBinding(42))->toBeNull()
|
|
->and($dto->resolveChildRouteBinding('child', 'val', 'field'))->toBeNull()
|
|
->and($dto->toArray())->toBe([
|
|
'id' => 42,
|
|
'type' => DiscountType::PERCENT->value(),
|
|
'value' => 20,
|
|
'is_old_price_displayed' => true,
|
|
'date_start' => $dateStart,
|
|
'date_end' => $dateEnd,
|
|
'created_at' => null,
|
|
'updated_at' => null,
|
|
]);
|
|
});
|
|
});
|