laporan: tampilkan deskripsi pelanggaran di kolom jenis (web+PDF); TEST GUARD: blokir test bila DB bukan *_test (cegah RefreshDatabase menghancurkan produksi saat config ter-cache)
This commit is contained in:
+21
-1
@@ -3,8 +3,28 @@
|
||||
namespace Tests;
|
||||
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
//
|
||||
/**
|
||||
* Pengaman: pastikan test HANYA boleh jalan di database test.
|
||||
*
|
||||
* Jika konfigurasi ter-cache (config:cache) membuat test menunjuk ke
|
||||
* database produksi, RefreshDatabase akan menghancurkan data asli —
|
||||
* guard ini menghentikan suite sebelum itu terjadi.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$dbName = config('database.connections.'.config('database.default').'.database');
|
||||
|
||||
if (! str_ends_with((string) $dbName, '_test')) {
|
||||
throw new \RuntimeException(
|
||||
"TEST DIBLOKIR: database aktif '{$dbName}' bukan database test (harus berakhiran _test). ".
|
||||
'Jalankan `php artisan config:clear` lalu ulangi test.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user