2026-08-21 16:12:01 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace Tests\Integration\Infra\Database\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Infra\Database\Models\Brand;
|
|
|
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
covers(Brand::class);
|
|
|
|
|
|
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
|
|
2026-09-15 12:49:01 +02:00
|
|
|
beforeEach(function (): void {
|
|
|
|
|
Brand::query()->delete();
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-21 16:12:01 +02:00
|
|
|
describe('Brand Eloquent Model & Factory', function (): void {
|
|
|
|
|
it('creates and persists a Brand record with computed created_at from UUIDv7', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$expectedDate = new \DateTimeImmutable('2026-08-21 10:30:00 UTC');
|
|
|
|
|
$uuid7 = Uuid::uuid7($expectedDate)->toString();
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$brand = Brand::factory()->create([
|
|
|
|
|
'id' => $uuid7,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$retrieved = Brand::query()->find($brand->id);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($retrieved)->not->toBeNull()
|
|
|
|
|
->and($retrieved?->id)->toBe($uuid7)
|
|
|
|
|
->and($retrieved?->created_at)->toBeInstanceOf(\DateTimeImmutable::class)
|
|
|
|
|
->and($retrieved?->created_at->format('Y-m-d H:i:s'))->toBe('2026-08-21 10:30:00');
|
|
|
|
|
});
|
|
|
|
|
});
|