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) ->and($brand->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt())->toBeInstanceOf(DateTimeInterface::class); }); it('creates a new brand with a freshly generated id', function () use ($code, $name, $logo, $rcs, $contact): void { // GIVEN / 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) ->and($brand->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt())->toBeNull(); }); it('generates a different id for each created brand', function () use ($code, $name, $logo, $rcs, $contact): void { // GIVEN / 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 and sets updatedAt timestamp', function () use ($code, $name, $rcs, $contact): void { // GIVEN CarbonImmutable::setTestNow('2026-06-15 12:00:00 UTC'); $id = BrandId::generate(); $logoOld = new PicturePath('files/picture-old.jpg'); $logoNew = new PicturePath('files/picture-new.jpg'); $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) ->and($brand->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt()->format('Y-m-d H:i:s'))->toBe('2026-06-15 12:00:00'); }); it('updates a brand rcs and sets updatedAt timestamp', function () use ($code, $name, $logo, $contact): void { // GIVEN CarbonImmutable::setTestNow('2026-06-15 14:30:00 UTC'); $id = BrandId::generate(); $rcsOld = new Rcs('RCS PARIS 111 222 333'); $rcsNew = new Rcs('RCS NANTES 444 555 666'); $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) ->and($brand->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt()->format('Y-m-d H:i:s'))->toBe('2026-06-15 14:30:00'); }); it('updates a brand contact and sets updatedAt timestamp', function () use ($code, $name, $logo, $rcs): void { // GIVEN CarbonImmutable::setTestNow('2026-06-15 16:45:00 UTC'); $id = BrandId::generate(); $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) ->and($brand->createdAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt())->toBeInstanceOf(DateTimeInterface::class) ->and($brand->updatedAt()->format('Y-m-d H:i:s'))->toBe('2026-06-15 16:45:00'); }); it('returns the creation date extracted from the id', function () use ($code, $name, $logo, $rcs, $contact): 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, $code, $name, $logo, $rcs, $contact, ); // 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')); }); });