- MySQL Host
-
+ Database Driver
+
+ MySQL
+ SQLite
+
- MySQL Database
-
+ Database
+
-
- MySQL Username
-
-
+
@@ -70,6 +88,18 @@
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('form input').select();
+ document.querySelector('select[name="dbDriver"]').addEventListener('change', function() {
+ document.querySelectorAll('[data-group]').forEach(function(group) {
+ group.style.display = 'none';
+ });
+
+ const groups = document.querySelectorAll('[data-group="' + this.value + '"]');
+
+ groups.forEach(function(group) {
+ group.style.display = 'block';
+ });
+ });
+
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
diff --git a/framework/core/views/install/update.php b/framework/core/views/install/update.php
index 1cbbc1639..bd8a05e7e 100644
--- a/framework/core/views/install/update.php
+++ b/framework/core/views/install/update.php
@@ -8,7 +8,7 @@
diff --git a/php-packages/testing/src/integration/Extend/BeginTransactionAndSetDatabase.php b/php-packages/testing/src/integration/Extend/BeginTransactionAndSetDatabase.php
index 565164bdb..fe919da30 100644
--- a/php-packages/testing/src/integration/Extend/BeginTransactionAndSetDatabase.php
+++ b/php-packages/testing/src/integration/Extend/BeginTransactionAndSetDatabase.php
@@ -12,6 +12,7 @@ namespace Flarum\Testing\integration\Extend;
use Flarum\Extend\ExtenderInterface;
use Flarum\Extension\Extension;
use Illuminate\Contracts\Container\Container;
+use Illuminate\Database\Connection;
use Illuminate\Database\ConnectionInterface;
class BeginTransactionAndSetDatabase implements ExtenderInterface
@@ -28,8 +29,14 @@ class BeginTransactionAndSetDatabase implements ExtenderInterface
public function extend(Container $container, Extension $extension = null): void
{
+ /** @var Connection $db */
$db = $container->make(ConnectionInterface::class);
+ // SQLite requires this be done outside a transaction.
+ if ($db->getDriverName() === 'sqlite') {
+ $db->getSchemaBuilder()->disableForeignKeyConstraints();
+ }
+
$db->beginTransaction();
($this->setDbOnTestCase)($db);
diff --git a/php-packages/testing/src/integration/Setup/SetupScript.php b/php-packages/testing/src/integration/Setup/SetupScript.php
index e6d70a9ea..5b190cf94 100644
--- a/php-packages/testing/src/integration/Setup/SetupScript.php
+++ b/php-packages/testing/src/integration/Setup/SetupScript.php
@@ -21,61 +21,24 @@ class SetupScript
{
use UsesTmpDir;
- /**
- * Test database host.
- *
- * @var string
- */
- protected $host;
+ protected string $driver;
+ protected string $host;
+ protected int $port;
+ protected string $name;
+ protected string $user;
+ protected string $pass;
+ protected string $pref;
- /**
- * Test database port.
- *
- * @var int
- */
- protected $port;
-
- /**
- * Test database name.
- *
- * @var string
- */
- protected $name;
-
- /**
- * Test database username.
- *
- * @var string
- */
- protected $user;
-
- /**
- * Test database password.
- *
- * @var string
- */
- protected $pass;
-
- /**
- * Test database prefix.
- *
- * @var string
- */
- protected $pref;
-
- /**
- * @var DatabaseConfig
- */
- protected $dbConfig;
+ protected DatabaseConfig $dbConfig;
/**
* Settings to be applied during installation.
- * @var array
*/
- protected $settings = ['mail_driver' => 'log'];
+ protected array $settings = ['mail_driver' => 'log'];
public function __construct()
{
+ $this->driver = getenv('DB_DRIVER') ?: 'mysql';
$this->host = getenv('DB_HOST') ?: 'localhost';
$this->port = intval(getenv('DB_PORT') ?: 3306);
$this->name = getenv('DB_DATABASE') ?: 'flarum_test';
@@ -88,7 +51,12 @@ class SetupScript
{
$tmp = $this->tmpDir();
- echo "Connecting to database $this->name at $this->host:$this->port.\n";
+ if ($this->driver === 'sqlite') {
+ echo "Connecting to SQLite database at $this->name.\n";
+ } else {
+ echo "Connecting to database $this->name at $this->host:$this->port.\n";
+ }
+
echo "Warning: all tables will be dropped to ensure clean state. DO NOT use your production database!\n";
echo "Logging in as $this->user with password '$this->pass'.\n";
echo "Table prefix: '$this->pref'\n";
@@ -103,22 +71,31 @@ class SetupScript
echo "\nOff we go...\n";
- $this->dbConfig = new DatabaseConfig('mysql', $this->host, $this->port, $this->name, $this->user, $this->pass, $this->pref);
+ $this->dbConfig = new DatabaseConfig(
+ $this->driver,
+ $this->host,
+ $this->port,
+ $this->name,
+ $this->user,
+ $this->pass,
+ $this->pref
+ );
- echo "\nWiping DB to ensure clean state\n";
- $this->wipeDb();
- echo "Success! Proceeding to installation...\n";
+ $paths = new Paths([
+ 'base' => $tmp,
+ 'public' => "$tmp/public",
+ 'storage' => "$tmp/storage",
+ 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
+ ]);
$this->setupTmpDir();
+ $this->dbConfig->prepare($paths);
- $installation = new Installation(
- new Paths([
- 'base' => $tmp,
- 'public' => "$tmp/public",
- 'storage' => "$tmp/storage",
- 'vendor' => getenv('FLARUM_TEST_VENDOR_PATH') ?: getcwd().'/vendor',
- ])
- );
+ echo "\nWiping DB to ensure clean state\n";
+ $this->wipeDb($paths);
+ echo "Success! Proceeding to installation...\n";
+
+ $installation = new Installation($paths);
$pipeline = $installation
->configPath('config.php')
@@ -140,7 +117,7 @@ class SetupScript
echo "Installation complete\n";
}
- protected function wipeDb()
+ protected function wipeDb(Paths $paths)
{
// Reuse the connection step to include version checks
(new ConnectToDatabase($this->dbConfig, function ($db) {
@@ -149,7 +126,7 @@ class SetupScript
$builder->dropAllTables();
$builder->dropAllViews();
- }))->run();
+ }, $paths->base))->run();
}
/**
diff --git a/php-packages/testing/src/integration/TestCase.php b/php-packages/testing/src/integration/TestCase.php
index 68f2d4764..b450be491 100644
--- a/php-packages/testing/src/integration/TestCase.php
+++ b/php-packages/testing/src/integration/TestCase.php
@@ -193,7 +193,12 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
protected function populateDatabase(): void
{
- // We temporarily disable foreign key checks to simplify this process.
+ /**
+ * We temporarily disable foreign key checks to simplify this process.
+ * SQLite ignores this statement since we are inside a transaction.
+ * So we do that before starting a transaction.
+ * @see BeginTransactionAndSetDatabase
+ */
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
$databaseContent = [];