164 lines
5.7 KiB
PHP
164 lines
5.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Domain\Models\Entities;
|
|
|
|
use Domain\Models\Entities\Brand;
|
|
use Domain\Models\ValueObjects\Brand\BrandCode;
|
|
use Domain\Models\ValueObjects\Brand\BrandId;
|
|
use Domain\Models\ValueObjects\Brand\BrandName;
|
|
use Ramsey\Uuid\Uuid;
|
|
use Shared\Models\ValueObjects\Email;
|
|
use Shared\Models\ValueObjects\PicturePath;
|
|
use Shared\Models\ValueObjects\Rcs;
|
|
|
|
covers(Brand::class);
|
|
|
|
describe('brand', function (): void {
|
|
it('creates a brand', function (): void {
|
|
// GIVEN
|
|
$id = BrandId::generate();
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logo = new PicturePath('files/picture.jpg');
|
|
$rcs = new Rcs('RCS PARIS 111 222 333');
|
|
$contact = new Email('contact@example.com');
|
|
|
|
// WHEN
|
|
$brand = Brand::hydrate($id, $code, $name, $logo, $rcs, $contact);
|
|
|
|
// THEN
|
|
expect($brand->id())->toBe($id)
|
|
->and($brand->code)->toBe($code)
|
|
->and($brand->name)->toBe($name)
|
|
->and($brand->logo)->toBe($logo)
|
|
->and($brand->rcs)->toBe($rcs)
|
|
->and($brand->contact)->toBe($contact);
|
|
});
|
|
|
|
it('creates a new brand with a freshly generated id', function (): void {
|
|
// GIVEN
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logo = new PicturePath('files/picture.jpg');
|
|
$rcs = new Rcs('RCS PARIS 111 222 333');
|
|
$contact = new Email('contact@example.com');
|
|
|
|
// WHEN
|
|
$brand = Brand::create($code, $name, $logo, $rcs, $contact);
|
|
|
|
// THEN
|
|
expect($brand->id())->toBeInstanceOf(BrandId::class)
|
|
->and($brand->code)->toBe($code)
|
|
->and($brand->name)->toBe($name)
|
|
->and($brand->logo)->toBe($logo)
|
|
->and($brand->rcs)->toBe($rcs)
|
|
->and($brand->contact)->toBe($contact);
|
|
});
|
|
|
|
it('generates a different id for each created brand', function (): void {
|
|
// GIVEN
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logo = new PicturePath('files/picture.jpg');
|
|
$rcs = new Rcs('RCS PARIS 111 222 333');
|
|
$contact = new Email('contact@example.com');
|
|
|
|
// WHEN
|
|
$first = Brand::create($code, $name, $logo, $rcs, $contact);
|
|
$second = Brand::create($code, $name, $logo, $rcs, $contact);
|
|
|
|
// THEN
|
|
expect($first->id()->equals($second->id()))->toBeFalse();
|
|
});
|
|
|
|
it('updates a brand logo', function (): void {
|
|
// GIVEN
|
|
$id = BrandId::generate();
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logoOld = new PicturePath('files/picture-old.jpg');
|
|
$logoNew = new PicturePath('files/picture-new.jpg');
|
|
$rcs = new Rcs('RCS PARIS 111 222 333');
|
|
$contact = new Email('contact@example.com');
|
|
$brand = Brand::hydrate($id, $code, $name, $logoOld, $rcs, $contact);
|
|
|
|
// WHEN
|
|
$brand = $brand->changeLogo($logoNew);
|
|
|
|
// THEN
|
|
expect($brand->id())->toBe($id)
|
|
->and($brand->code)->toBe($code)
|
|
->and($brand->name)->toBe($name)
|
|
->and($brand->logo)->toBe($logoNew)
|
|
->and($brand->rcs)->toBe($rcs)
|
|
->and($brand->contact)->toBe($contact);
|
|
});
|
|
|
|
it('updates a brand rcs', function (): void {
|
|
// GIVEN
|
|
$id = BrandId::generate();
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logo = new PicturePath('files/picture.jpg');
|
|
$rcsOld = new Rcs('RCS PARIS 111 222 333');
|
|
$rcsNew = new Rcs('RCS NANTES 444 555 666');
|
|
$contact = new Email('contact@example.com');
|
|
$brand = Brand::hydrate($id, $code, $name, $logo, $rcsOld, $contact);
|
|
|
|
// WHEN
|
|
$brand = $brand->changeRcs($rcsNew);
|
|
|
|
// THEN
|
|
expect($brand->id())->toBe($id)
|
|
->and($brand->code)->toBe($code)
|
|
->and($brand->name)->toBe($name)
|
|
->and($brand->logo)->toBe($logo)
|
|
->and($brand->rcs)->toBe($rcsNew)
|
|
->and($brand->contact)->toBe($contact);
|
|
});
|
|
|
|
it('updates a brand contact', function (): void {
|
|
// GIVEN
|
|
$id = BrandId::generate();
|
|
$code = new BrandCode('AAA01');
|
|
$name = new BrandName('Name');
|
|
$logo = new PicturePath('files/picture.jpg');
|
|
$rcs = new Rcs('RCS PARIS 111 222 333');
|
|
$contactOld = new Email('contact-old@example.com');
|
|
$contactNew = new Email('contact-new@example.com');
|
|
$brand = Brand::hydrate($id, $code, $name, $logo, $rcs, $contactOld);
|
|
|
|
// WHEN
|
|
$brand = $brand->changeContact($contactNew);
|
|
|
|
// THEN
|
|
expect($brand->id())->toBe($id)
|
|
->and($brand->code)->toBe($code)
|
|
->and($brand->name)->toBe($name)
|
|
->and($brand->logo)->toBe($logo)
|
|
->and($brand->rcs)->toBe($rcs)
|
|
->and($brand->contact)->toBe($contactNew);
|
|
});
|
|
|
|
it('returns the creation date extracted from the id', function (): void {
|
|
// GIVEN
|
|
$expected = new \DateTimeImmutable('2024-06-15 12:34:56.789000', new \DateTimeZone('UTC'));
|
|
$id = new BrandId(Uuid::uuid7($expected));
|
|
$brand = Brand::hydrate(
|
|
$id,
|
|
new BrandCode('AAA01'),
|
|
new BrandName('Name'),
|
|
new PicturePath('files/picture.jpg'),
|
|
new Rcs('RCS PARIS 111 222 333'),
|
|
new Email('contact@example.com'),
|
|
);
|
|
|
|
// WHEN
|
|
$result = $brand->createdAt();
|
|
|
|
// THEN
|
|
expect($result->format('Y-m-d H:i:s.v'))->toBe($expected->format('Y-m-d H:i:s.v'));
|
|
});
|
|
});
|