58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Migrations;
|
|
|
|
use App\Domains\Core\Client\Models\Client;
|
|
use App\Domains\Ticketing\Event\Models\Event;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Tests\TestCase;
|
|
|
|
class AddClientIdToEventsTest extends TestCase
|
|
{
|
|
public function test_event_client_overrides_the_tenant_client_when_configured(): void
|
|
{
|
|
Schema::create('clients', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('code');
|
|
$table->string('name');
|
|
});
|
|
Schema::create('tenants', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->foreignId('client_id');
|
|
$table->string('codigo');
|
|
});
|
|
Schema::create('events', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('tenant_code');
|
|
$table->string('title');
|
|
$table->timestamps();
|
|
});
|
|
|
|
DB::table('clients')->insert([
|
|
['id' => 10, 'code' => 'tenant-client', 'name' => 'Tenant Client'],
|
|
['id' => 11, 'code' => 'event-client', 'name' => 'Event Client'],
|
|
]);
|
|
DB::table('tenants')->insert(['id' => 20, 'client_id' => 10, 'codigo' => 'tenant']);
|
|
DB::table('events')->insert([
|
|
'id' => 30,
|
|
'tenant_code' => 'tenant',
|
|
'title' => 'Event',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$migration = require database_path('migrations/2026_09_28_000000_add_client_id_to_events.php');
|
|
$migration->up();
|
|
|
|
$event = Event::query()->findOrFail(30);
|
|
$this->assertSame(10, $event->effectiveClient()->id);
|
|
|
|
$event->update(['client_id' => 11]);
|
|
|
|
$this->assertSame(11, $event->fresh()->effectiveClient()->id);
|
|
$this->assertTrue(Client::query()->findOrFail(11)->events()->whereKey(30)->exists());
|
|
}
|
|
}
|