mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-06 15:14:13 +00:00
Backport of InvoiceShelf/InvoiceShelf#704 to 2.x. Fixes InvoiceShelf/docker#79. A fresh install using the shipped docker-compose.mysql.yml cannot get past the database step, because that compose file sets DB_CONNECTION=mariadb. getDatabaseEnvironment() switched on sqlite, pgsql and mysql with no arm for mariadb and no default, so it answered {"config":[]}. The wizard renders <component :is="database_connection">, which resolves to nothing, so the step came out blank — and nothing reached the log, because the app never errored, it just replied with nothing. Adds the mariadb arm plus a default, so an unrecognised driver is echoed back with server defaults rather than producing an unrenderable response. MariaDB is registered as an alias of the MySQL form, whose fields are identical, and offered in each driver picker. Tested against the original controller, where three of the new cases fail with "Failed asserting that null is identical to 'mariadb'".
59 lines
2.0 KiB
PHP
59 lines
2.0 KiB
PHP
<?php
|
|
|
|
use function Pest\Laravel\getJson;
|
|
|
|
/**
|
|
* The setup wizard picks which form to render from `database_connection` in this
|
|
* response. When the switch had no arm for the requested driver it returned an
|
|
* empty config, so step 3 rendered blank with no way to continue and nothing in
|
|
* the log — the app never errored, it just answered with nothing.
|
|
*
|
|
* That is what InvoiceShelf/docker#79 hit: the shipped docker-compose.mysql.yml
|
|
* sets DB_CONNECTION=mariadb, so a fresh install using the official compose file
|
|
* could not get past the database step.
|
|
*/
|
|
test('the database config endpoint answers with a usable config for every supported driver', function (string $connection) {
|
|
$response = getJson("/api/v1/installation/database/config?connection={$connection}");
|
|
|
|
$response->assertOk();
|
|
|
|
expect($response->json('config.database_connection'))->toBe($connection);
|
|
})->with([
|
|
'mysql',
|
|
'mariadb',
|
|
'pgsql',
|
|
'sqlite',
|
|
]);
|
|
|
|
test('sqlite is told where its database file lives', function () {
|
|
$response = getJson('/api/v1/installation/database/config?connection=sqlite');
|
|
|
|
$response->assertOk();
|
|
|
|
expect($response->json('config.database_name'))->not->toBeEmpty();
|
|
});
|
|
|
|
test('server-based drivers are given a host and port to prefill', function (string $connection) {
|
|
$response = getJson("/api/v1/installation/database/config?connection={$connection}");
|
|
|
|
expect($response->json('config.database_host'))->not->toBeEmpty()
|
|
->and($response->json('config.database_port'))->not->toBeEmpty();
|
|
})->with([
|
|
'mysql',
|
|
'mariadb',
|
|
'pgsql',
|
|
]);
|
|
|
|
/**
|
|
* A driver we do not recognise must still produce something the wizard can
|
|
* render, rather than the empty config that caused #79.
|
|
*/
|
|
test('an unrecognised driver still returns a renderable config', function () {
|
|
$response = getJson('/api/v1/installation/database/config?connection=cockroach');
|
|
|
|
$response->assertOk();
|
|
|
|
expect($response->json('config.database_connection'))->toBe('cockroach')
|
|
->and($response->json('config'))->not->toBeEmpty();
|
|
});
|