Merge pull request #9765 from open-sausages/pulls/4/test-setup-confusion

Warn on database misconfiguration in test runs
This commit is contained in:
Ingo Schommer 2021-01-14 09:18:14 +13:00 committed by GitHub
commit 5f7239fc3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View File

@ -270,8 +270,10 @@ class CoreKernel implements Kernel
$databaseConfig = DB::getConfig();
// Gracefully fail if no DB is configured
if (empty($databaseConfig['database'])) {
$msg = 'Silverstripe Framework requires a "database" key in DB::getConfig(). ' .
'Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?';
$this->detectLegacyEnvironment();
$this->redirectToInstaller();
$this->redirectToInstaller($msg);
}
}
@ -311,14 +313,17 @@ class CoreKernel implements Kernel
}
/**
* If missing configuration, redirect to install.php
* If missing configuration, redirect to install.php if it exists.
* Otherwise show a server error to the user.
*
* @param string $msg Optional message to show to the user on an installed project (install.php missing).
*/
protected function redirectToInstaller()
protected function redirectToInstaller($msg = '')
{
// Error if installer not available
if (!file_exists(Director::publicFolder() . '/install.php')) {
throw new HTTPResponse_Exception(
'SilverStripe Framework requires database configuration defined via .env',
$msg,
500
);
}

View File

@ -1023,7 +1023,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase implements TestOnly
$flush = array_key_exists('flush', $request->getVars());
// Custom application
$app->execute($request, function (HTTPRequest $request) {
$res = $app->execute($request, function (HTTPRequest $request) {
// Start session and execute
$request->getSession()->init($request);
@ -1037,6 +1037,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase implements TestOnly
$controller->pushCurrent();
$controller->doInit();
}, $flush);
if ($res && $res->isError()) {
throw new LogicException($res->getBody());
}
} else {
// Allow flush from the command line in the absence of HTTPApplication's special sauce
$flush = false;