Files
shopit-back/tests/Feature/Migrations/AddSlugsToEventsTest.php

38 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature\Migrations;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class AddSlugsToEventsTest extends TestCase
{
public function test_it_backfills_unique_slugs_per_tenant(): void
{
Schema::create('events', function (Blueprint $table): void {
$table->id();
$table->string('tenant_code');
$table->string('title');
});
DB::table('events')->insert([
['id' => 1, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'],
['id' => 2, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'],
['id' => 3, 'tenant_code' => 'other', 'title' => 'Gran Fiesta'],
['id' => 4, 'tenant_code' => 'acme', 'title' => '---'],
]);
$migration = require database_path('migrations/2026_09_22_010000_add_slugs_to_events.php');
$migration->up();
$this->assertSame([
1 => 'gran-fiesta',
2 => 'gran-fiesta-2',
3 => 'gran-fiesta',
4 => 'evento-4',
], DB::table('events')->orderBy('id')->pluck('slug', 'id')->all());
}
}