ldc-arcadia-api/tests/Unit/Domain/Models/Entities/BrandTest.php

65 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\Entities;
use Domain\Models\Entities\Brand;
use Domain\Models\ValueObjects\Brand\ArcadiaId;
use Domain\Models\ValueObjects\Brand\BrandCode;
use Domain\Models\ValueObjects\Brand\BrandId;
use Domain\Models\ValueObjects\Brand\BrandName;
use Ramsey\Uuid\Uuid;
use Shared\DDD\Model\HasTimestampIdentifier;
covers(Brand::class);
describe('Brand Entity', function (): void {
it('creates a brand and implements HasTimestampIdentifier', function (): void {
// GIVEN
$brandCode = new BrandCode('LGL89');
$arcadiaId = new ArcadiaId(123);
$brandName = new BrandName('Arcadia Brand Name');
// WHEN
$brand = Brand::create(
name: $brandName,
code: $brandCode,
arcadiaId: $arcadiaId,
);
// THEN
expect($brand)->toBeInstanceOf(HasTimestampIdentifier::class)
->and($brand->name)->toBe($brandName)
->and($brand->code)->toBe($brandCode)
->and($brand->arcadiaId)->toBe($arcadiaId)
->and($brand->createdAt())->toBeInstanceOf(\DateTimeInterface::class)
->and($brand->createdAt()->getTimestamp())->toBeLessThanOrEqual(time());
});
it('hydrates a brand correctly', function (): void {
// GIVEN
$uuid = Uuid::uuid7();
$brandId = new BrandId($uuid);
$brandCode = new BrandCode('LGL89');
$arcadiaId = new ArcadiaId(123);
$brandName = new BrandName('Arcadia Brand Name');
// WHEN
$brand = Brand::hydrate(
id: $brandId,
name: $brandName,
code: $brandCode,
arcadiaId: $arcadiaId,
);
// THEN
expect($brand)->toBeInstanceOf(HasTimestampIdentifier::class)
->and($brand->id())->toBe($brandId)
->and($brand->name)->toBe($brandName)
->and($brand->code)->toBe($brandCode)
->and($brand->arcadiaId)->toBe($arcadiaId)
->and($brand->createdAt())->toBeInstanceOf(\DateTimeInterface::class)
->and($brand->createdAt()->getTimestamp())->toBeLessThanOrEqual(time());
});
});