buckets/tests/Unit/Traits/HasUuidTest.php

60 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit\Traits;
use App\Models\Bucket;
use App\Models\Scenario;
use App\Models\Stream;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class HasUuidTest extends TestCase
{
use RefreshDatabase;
public function test_uuid_is_auto_generated_on_creation(): void
{
$scenario = Scenario::factory()->create();
$this->assertNotNull($scenario->uuid);
$this->assertTrue(Str::isUuid($scenario->uuid));
}
public function test_uuid_is_not_overwritten_when_provided(): void
{
$customUuid = (string) Str::uuid();
$scenario = Scenario::factory()->create(['uuid' => $customUuid]);
$this->assertEquals($customUuid, $scenario->uuid);
}
public function test_route_key_name_returns_uuid(): void
{
$scenario = Scenario::factory()->create();
$this->assertEquals('uuid', $scenario->getRouteKeyName());
}
public function test_each_model_gets_a_unique_uuid(): void
{
$a = Scenario::factory()->create();
$b = Scenario::factory()->create();
$this->assertNotEquals($a->uuid, $b->uuid);
}
public function test_all_uuid_models_have_correct_route_key_name(): void
{
$scenario = Scenario::factory()->create();
$bucket = Bucket::factory()->create(['scenario_id' => $scenario->id]);
$stream = Stream::factory()->create(['scenario_id' => $scenario->id]);
$this->assertEquals('uuid', $bucket->getRouteKeyName());
$this->assertEquals('uuid', $stream->getRouteKeyName());
$this->assertTrue(Str::isUuid($bucket->uuid));
$this->assertTrue(Str::isUuid($stream->uuid));
}
}