mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-03 13:51:08 +00:00
test: add the behavioral spec suites (pilot + ten domains)
98 tests pinning observable behavior ahead of the authorship rewrite.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?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);
|
||||
});
|
||||
Reference in New Issue
Block a user