mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
Replace dbname suffix by explicit test database names
This commit is contained in:
parent
cbd37b2fe2
commit
163c3773cb
4 changed files with 19 additions and 9 deletions
3
.env.test
Normal file
3
.env.test
Normal file
|
@ -0,0 +1,3 @@
|
|||
DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag_test.sqlite?charset=utf8
|
||||
#DATABASE_URL=mysql://root:wallaroot@mariadb:3306/wallabag_test?charset=utf8mb4
|
||||
#DATABASE_URL=postgres://wallabag:wallapass@postgres:5432/wallabag_test?charset=utf8
|
|
@ -4,7 +4,6 @@ imports:
|
|||
|
||||
parameters:
|
||||
fosuser_registration: true
|
||||
wallabag_dbname_suffix: '_test'
|
||||
database_url: '%env(resolve:DATABASE_URL)%'
|
||||
domain_name: '%env(DOMAIN_NAME)%'
|
||||
|
||||
|
@ -25,7 +24,6 @@ web_profiler:
|
|||
|
||||
doctrine:
|
||||
dbal:
|
||||
dbname_suffix: '%wallabag_dbname_suffix%' # for MySQL and PostgreSQL
|
||||
use_savepoints: true
|
||||
|
||||
orm:
|
||||
|
|
|
@ -1 +1 @@
|
|||
DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag%wallabag_dbname_suffix%.sqlite?charset=utf8
|
||||
DATABASE_URL=sqlite:///%kernel.project_dir%/data/db/wallabag.sqlite?charset=utf8
|
||||
|
|
|
@ -41,11 +41,18 @@ class InstallCommandTest extends WallabagTestCase
|
|||
$connection = $this->getTestClient()->getContainer()->get(ManagerRegistry::class)->getConnection();
|
||||
|
||||
$this->originalDatabaseUrl = $this->getTestClient()->getContainer()->getParameter('database_url');
|
||||
$dbnameSuffix = $this->getTestClient()->getContainer()->getParameter('wallabag_dbname_suffix');
|
||||
$tmpDatabaseName = 'wallabag_' . bin2hex(random_bytes(5));
|
||||
$tmpDatabaseName = 'wallabag_test_' . bin2hex(random_bytes(5));
|
||||
|
||||
if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {
|
||||
$tmpDatabaseUrl = str_replace('wallabag' . $dbnameSuffix . '.sqlite', $tmpDatabaseName . $dbnameSuffix . '.sqlite', $this->originalDatabaseUrl);
|
||||
$tmpDatabaseName = $this->getTestClient()->getContainer()->getParameter('kernel.project_dir') . '/data/db/' . $tmpDatabaseName . '.sqlite';
|
||||
|
||||
/** @see \Doctrine\DBAL\Tools\DsnParser::parse */
|
||||
$url = preg_replace('#^((?:pdo-)?sqlite3?):///#', '$1://localhost/', $this->originalDatabaseUrl);
|
||||
|
||||
$tmpDatabaseUrl = (string) (new Uri($url))->withPath($tmpDatabaseName);
|
||||
|
||||
// Add back the leading "/" that was removed by withPath, and remove the "localhost" part
|
||||
$tmpDatabaseUrl = str_replace('//localhost', '///', $tmpDatabaseUrl);
|
||||
} else {
|
||||
$tmpDatabaseUrl = (string) (new Uri($this->originalDatabaseUrl))->withPath($tmpDatabaseName);
|
||||
}
|
||||
|
@ -54,8 +61,7 @@ class InstallCommandTest extends WallabagTestCase
|
|||
|
||||
if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) {
|
||||
// PostgreSQL requires that the database exists before connecting to it
|
||||
$tmpTestDatabaseName = $tmpDatabaseName . $dbnameSuffix;
|
||||
$connection->executeQuery('CREATE DATABASE ' . $tmpTestDatabaseName);
|
||||
$connection->executeQuery('CREATE DATABASE ' . $tmpDatabaseName);
|
||||
}
|
||||
|
||||
// The environnement has been changed, recreate the client in order to update connection
|
||||
|
@ -72,7 +78,10 @@ class InstallCommandTest extends WallabagTestCase
|
|||
if ($connection->getDatabasePlatform() instanceof SqlitePlatform) {// Remove the real environnement variable
|
||||
$_ENV['DATABASE_URL'] = $_SERVER['DATABASE_URL'] = $this->originalDatabaseUrl;
|
||||
|
||||
$databasePath = parse_url($databaseUrl, \PHP_URL_PATH);
|
||||
/** @see \Doctrine\DBAL\Tools\DsnParser::parse */
|
||||
$url = preg_replace('#^((?:pdo-)?sqlite3?):///#', '$1://localhost/', $databaseUrl);
|
||||
|
||||
$databasePath = parse_url($url, \PHP_URL_PATH);
|
||||
|
||||
if (file_exists($databasePath)) {
|
||||
unlink($databasePath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue