Files
InvoiceShelf/tests/Feature/PilotSpec/ZzDatabaseRefusalTest.php
T
Darko Gjorgjijoski 605d700f75 test: add the behavioral spec suites (pilot + ten domains)
98 tests pinning observable behavior ahead of the authorship rewrite.
2026-08-20 17:19:26 +02:00

38 lines
1.3 KiB
PHP

<?php
// Pilot behavioural suite — the non-empty-database refusal.
// Kept in its own file, alphabetically last: exercising the refusal swaps the
// application's active database connection for the remainder of the PHP
// process, which would poison any test file running after it.
use function Pest\Laravel\postJson;
beforeEach(function () {
Artisan::call('db:seed', ['--class' => 'DatabaseSeeder', '--force' => true]);
$this->envBackup = file_get_contents(base_path('.env'));
});
afterEach(function () {
file_put_contents(base_path('.env'), $this->envBackup);
});
it('refuses a database that already contains data, without touching the environment file', function () {
$path = storage_path('framework/testing/pilot-nonempty.sqlite');
@mkdir(dirname($path), 0775, true);
@unlink($path);
$db = new SQLite3($path);
$db->exec('CREATE TABLE users (id INTEGER PRIMARY KEY)');
$db->close();
$response = postJson('/api/v1/installation/database/config', [
'app_url' => 'http://pilot.test',
'database_connection' => 'sqlite',
'database_name' => $path,
])->assertOk()->json();
expect($response['error'])->toBe('database_should_be_empty');
expect(file_get_contents(base_path('.env')))->toBe($this->envBackup);
@unlink($path);
});