From b271d9dd89e2af041ffca71b823119d0219674a6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 12 Nov 2020 13:27:59 +1300 Subject: [PATCH 1/4] FIX Don't swallow app init errors in test setup --- src/Dev/SapphireTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; From 6306d2ede3baaf954bc6c94d2f94d8dd6342ede4 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 12 Nov 2020 13:29:12 +1300 Subject: [PATCH 2/4] More specific "database missing" error message It's misleading to imply that an .env doesn't exist when it's not what the actual check looks for. It's also poor design to hardcode an unrelated error message in a "redirect to installer" function, which only worked because this function was called from exactly one other place where this error message was correct. --- src/Core/CoreKernel.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Core/CoreKernel.php b/src/Core/CoreKernel.php index d22a9b7f4..2b25428a5 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 ); } From a3ae4922e434273d97b9db056233796d45802034 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 12 Nov 2020 15:32:26 +1300 Subject: [PATCH 3/4] Brand naming Co-authored-by: Aaron Carlino --- src/Core/CoreKernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/CoreKernel.php b/src/Core/CoreKernel.php index 2b25428a5..595a60cb6 100644 --- a/src/Core/CoreKernel.php +++ b/src/Core/CoreKernel.php @@ -270,7 +270,7 @@ 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(). ' . + $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($msg); From 92af6b3dd5cacc1c2e2dea2633987e14e3d0b7bd Mon Sep 17 00:00:00 2001 From: Maxime Rainville Date: Sun, 15 Nov 2020 23:56:54 +1300 Subject: [PATCH 4/4] FIX Update behat toast logic so it works with quotes --- tests/behat/src/CmsUiContext.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/behat/src/CmsUiContext.php b/tests/behat/src/CmsUiContext.php index 76083823c..6e5b3f084 100644 --- a/tests/behat/src/CmsUiContext.php +++ b/tests/behat/src/CmsUiContext.php @@ -85,7 +85,7 @@ class CmsUiContext implements Context } /** - * @Then /^I should see a "([^"]+)" (\w+) toast$/ + * @Then /^I should see a "(.+)" (\w+) toast$/ */ public function iShouldSeeAToast($notice, $type) { @@ -93,7 +93,7 @@ class CmsUiContext implements Context } /** - * @Then /^I should see a "([^"]+)" (\w+) toast with these actions: (.+)$/ + * @Then /^I should see a "(.+)" (\w+) toast with these actions: (.+)$/ */ public function iShouldSeeAToastWithAction($notice, $type, $actions) { @@ -110,7 +110,7 @@ class CmsUiContext implements Context /** * @param $action - * @When /^I click the "([^"]*)" toast action$/ + * @When /^I click the "(.*)" toast action$/ */ public function stepIClickTheToastAction($action) {