- 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>
56 lines
2.3 KiB
PHP
56 lines
2.3 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Der Guard gegen eine falsch aufgelöste Testdatenbank (Config-Cache →
|
|
* Dev-DB) muss greifen, BEVOR RefreshDatabase etwas anfasst. Laravel ruft
|
|
* setUpTraits() vor allen Datenbank-Traits auf; dort hängt der Guard
|
|
* (Umsetzungsaudit 25.09.2026, N22).
|
|
*/
|
|
test('the database guard runs in setUpTraits, ahead of RefreshDatabase', function () {
|
|
$method = new ReflectionMethod(TestCase::class, 'setUpTraits');
|
|
$source = implode('', array_slice(file($method->getFileName()), $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1));
|
|
|
|
expect($method->getDeclaringClass()->getName())->toBe(TestCase::class)
|
|
->and(strpos($source, 'assertTestDatabaseIsInMemorySqlite'))->toBeLessThan(strpos($source, 'parent::setUpTraits'))
|
|
->and(in_array(RefreshDatabase::class, class_uses_recursive(static::class), true))->toBeTrue();
|
|
});
|
|
|
|
test('the database guard rejects anything but sqlite in memory', function () {
|
|
/** @var TestCase $this */
|
|
$guard = fn () => $this->assertTestDatabaseIsInMemorySqlite();
|
|
|
|
$guard();
|
|
|
|
try {
|
|
config()->set('database.default', 'mysql');
|
|
|
|
expect($guard)->toThrow(RuntimeException::class, 'statt SQLite :memory:');
|
|
} finally {
|
|
// Sonst räumt RefreshDatabase gegen die falsche Verbindung auf.
|
|
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();
|
|
});
|