mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #9765 from open-sausages/pulls/4/test-setup-confusion
Warn on database misconfiguration in test runs
This commit is contained in:
commit
5f7239fc3d
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user