diff --git a/src/Core/CoreKernel.php b/src/Core/CoreKernel.php index d22a9b7f4..595a60cb6 100644 --- a/src/Core/CoreKernel.php +++ b/src/Core/CoreKernel.php @@ -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 ); } diff --git a/src/Dev/SapphireTest.php b/src/Dev/SapphireTest.php index b79e1e5c5..fb987006b 100644 --- a/src/Dev/SapphireTest.php +++ b/src/Dev/SapphireTest.php @@ -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;