tests: gemeinsamer Testhelfer, DB_URL-Guard vor RefreshDatabase, Larastan voller Scope ohne Meldung (Umsetzungsaudit 29.09.: Q-01, Q-02; 02.10.: O02)
- makeCustomerForShowPhase8a() nach tests/Pest.php — die Suite läuft damit auch parallel (--parallel) und dateiweise grün - phpunit.xml leert DB_URL, der Guard in TestCase::setUpTraits() bricht bei gesetzter url ab, bevor RefreshDatabase eine Verbindung öffnet - HasUniqueSlug ohne widersprüchliche @var-Annotation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
80536ab998
commit
3dbc3fa673
6 changed files with 74 additions and 34 deletions
|
|
@ -4,9 +4,6 @@ use App\Enums\Portal;
|
|||
use App\Enums\PressReleaseClassification;
|
||||
use App\Enums\PressReleaseContentTier;
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\Contact;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\User;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
|
|
@ -18,35 +15,6 @@ beforeEach(function (): void {
|
|||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
});
|
||||
|
||||
/**
|
||||
* @return array{customer: User, company: Company, contact: Contact, category: Category, pr: PressRelease}
|
||||
*/
|
||||
function makeCustomerForShowPhase8a(array $prAttributes = []): array
|
||||
{
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$company = Company::factory()->presseecho()->create();
|
||||
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
||||
|
||||
$contact = Contact::factory()->for($company)->create([
|
||||
'portal' => $company->portal->value,
|
||||
]);
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$pr = PressRelease::factory()->create(array_merge([
|
||||
'user_id' => $customer->id,
|
||||
'company_id' => $company->id,
|
||||
'category_id' => $category->id,
|
||||
'portal' => $company->portal->value,
|
||||
'status' => 'draft',
|
||||
], $prAttributes));
|
||||
|
||||
$pr->contacts()->sync([$contact->id]);
|
||||
|
||||
return compact('customer', 'company', 'contact', 'category', 'pr');
|
||||
}
|
||||
|
||||
function makeAdminForShowPhase8a(): User
|
||||
{
|
||||
$admin = User::factory()->create(['is_active' => true]);
|
||||
|
|
|
|||
|
|
@ -33,3 +33,24 @@ test('the database guard rejects anything but sqlite in memory', function () {
|
|||
config()->set('database.default', 'sqlite');
|
||||
}
|
||||
});
|
||||
|
||||
test('the database guard rejects a url override on the sqlite connection', function () {
|
||||
/** @var TestCase $this */
|
||||
$guard = fn () => $this->assertTestDatabaseIsInMemorySqlite();
|
||||
|
||||
// Laravel löst `url` erst beim Verbindungsaufbau auf und überschreibt
|
||||
// damit Treiber und Datenbank — die rohen sqlite/:memory:-Werte allein
|
||||
// beweisen nichts (Umsetzungsaudit 02.10.2026, O02). Nur Config, keine
|
||||
// Verbindung: der Guard muss vorher abbrechen.
|
||||
try {
|
||||
config()->set('database.connections.sqlite.url', 'mysql://root:secret@127.0.0.1:3306/pressekonto');
|
||||
|
||||
expect($guard)->toThrow(RuntimeException::class, 'DB_URL');
|
||||
} finally {
|
||||
config()->set('database.connections.sqlite.url', null);
|
||||
}
|
||||
});
|
||||
|
||||
test('phpunit neutralises DB_URL for the whole run', function () {
|
||||
expect(config('database.connections.sqlite.url'))->toBeEmpty();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Category;
|
||||
use App\Models\Company;
|
||||
use App\Models\Contact;
|
||||
use App\Models\Plan;
|
||||
use App\Models\PressRelease;
|
||||
use App\Models\User;
|
||||
use App\Services\CurrentPortalContext;
|
||||
use App\Support\WebPageCache;
|
||||
|
|
@ -86,3 +90,38 @@ function webPageCacheKey(string $key): string
|
|||
{
|
||||
return 'web.g'.WebPageCache::generation().'.'.substr($key, strlen('web.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Kunde (Rolle customer, Owner einer Presseecho-Firma) mit Kontakt, Kategorie
|
||||
* und einer Entwurfs-PM. Gemeinsam genutzt von den Phase-8a-/8i-Tests und dem
|
||||
* Widerrufsverzicht-Test — deshalb hier und nicht in einer einzelnen Testdatei,
|
||||
* sonst scheitern die Nutzer im Einzel- oder Parallellauf.
|
||||
*
|
||||
* @param array<string, mixed> $prAttributes
|
||||
* @return array{customer: User, company: Company, contact: Contact, category: Category, pr: PressRelease}
|
||||
*/
|
||||
function makeCustomerForShowPhase8a(array $prAttributes = []): array
|
||||
{
|
||||
$customer = User::factory()->create(['is_active' => true]);
|
||||
$customer->assignRole('customer');
|
||||
|
||||
$company = Company::factory()->presseecho()->create();
|
||||
$customer->companies()->attach($company->id, ['role' => 'owner']);
|
||||
|
||||
$contact = Contact::factory()->for($company)->create([
|
||||
'portal' => $company->portal->value,
|
||||
]);
|
||||
$category = Category::factory()->create();
|
||||
|
||||
$pr = PressRelease::factory()->create(array_merge([
|
||||
'user_id' => $customer->id,
|
||||
'company_id' => $company->id,
|
||||
'category_id' => $category->id,
|
||||
'portal' => $company->portal->value,
|
||||
'status' => 'draft',
|
||||
], $prAttributes));
|
||||
|
||||
$pr->contacts()->sync([$contact->id]);
|
||||
|
||||
return compact('customer', 'company', 'contact', 'category', 'pr');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,16 @@ abstract class TestCase extends BaseTestCase
|
|||
$default = (string) DB::getDefaultConnection();
|
||||
$connection = (array) config('database.connections.'.$default, []);
|
||||
|
||||
// Eine gesetzte `url` überschreibt Treiber und Datenbank erst beim
|
||||
// Verbindungsaufbau — dann wären die geprüften Rohwerte wertlos
|
||||
// (Umsetzungsaudit 02.10.2026, O02).
|
||||
if (! empty($connection['url'])) {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Tests laufen mit DB_URL-Override auf „%s“ — die Verbindung würde nicht SQLite :memory: sein. DB_URL für Tests leeren.',
|
||||
$default,
|
||||
));
|
||||
}
|
||||
|
||||
if ($default !== 'sqlite' || ($connection['driver'] ?? null) !== 'sqlite' || ($connection['database'] ?? null) !== ':memory:') {
|
||||
throw new RuntimeException(sprintf(
|
||||
'Tests laufen gegen „%s“ (%s) statt SQLite :memory: — vermutlich liegt ein Config-Cache. `php artisan config:clear` und erneut starten.',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue