91 lines
3 KiB
PHP
91 lines
3 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());
|
|
});
|
|
|
|
it('renames a brand immutably', function (): void {
|
|
// GIVEN
|
|
$brandId = new BrandId(Uuid::uuid7());
|
|
$brandCode = new BrandCode('LGL01');
|
|
$arcadiaId = new ArcadiaId('1');
|
|
$oldName = new BrandName('Le Gaulois');
|
|
$newName = new BrandName('Le Gaulois France');
|
|
|
|
$brand = Brand::hydrate(
|
|
id: $brandId,
|
|
name: $oldName,
|
|
code: $brandCode,
|
|
arcadiaId: $arcadiaId,
|
|
);
|
|
|
|
// WHEN
|
|
$renamed = $brand->rename($newName);
|
|
|
|
// THEN
|
|
expect($renamed->id())->toBe($brandId)
|
|
->and($renamed->name)->toBe($newName)
|
|
->and($renamed->code)->toBe($brandCode)
|
|
->and($renamed->arcadiaId)->toBe($arcadiaId)
|
|
->and($brand->name)->toBe($oldName);
|
|
});
|
|
});
|