54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
// HARD override: never let tests touch the dev MySQL — even if
|
|
// phpunit.xml env section is ignored by the runner.
|
|
putenv('DB_CONNECTION=sqlite');
|
|
putenv('DB_DATABASE=:memory:');
|
|
$_ENV['DB_CONNECTION'] = 'sqlite';
|
|
$_ENV['DB_DATABASE'] = ':memory:';
|
|
$_SERVER['DB_CONNECTION'] = 'sqlite';
|
|
$_SERVER['DB_DATABASE'] = ':memory:';
|
|
|
|
parent::setUp();
|
|
|
|
// Belt-and-braces: force the resolved config to sqlite memory.
|
|
config([
|
|
'database.default' => 'sqlite',
|
|
'database.connections.sqlite' => [
|
|
'driver' => 'sqlite',
|
|
'url' => null,
|
|
'database' => ':memory:',
|
|
'prefix' => '',
|
|
'foreign_key_constraints' => true,
|
|
],
|
|
]);
|
|
|
|
// Provide a dummy {wsId} so route('dashboard') etc. generate URLs.
|
|
// Real test workspaces get created per-test via actingAsWithWorkspace().
|
|
\Illuminate\Support\Facades\URL::defaults(['wsId' => 'test-workspace']);
|
|
}
|
|
|
|
/** Helper: log in a user with a fresh workspace bound. */
|
|
protected function actingAsWithWorkspace(\App\Models\User $user = null): \App\Models\User
|
|
{
|
|
$user ??= \App\Models\User::factory()->create(['email_verified_at' => now()]);
|
|
$workspace = \App\Models\Workspace::factory()->create([
|
|
'owner_user_id' => $user->id,
|
|
'public_id' => 'test-workspace',
|
|
]);
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
$this->actingAs($user);
|
|
app()->instance('currentWorkspace', $workspace);
|
|
|
|
return $user;
|
|
}
|
|
}
|