Make tests use dev database config

This commit is contained in:
Yassine Guedidi 2024-01-05 00:41:13 +01:00
parent aa7dd67131
commit 8d3f575c03
6 changed files with 16 additions and 59 deletions

View file

@ -100,22 +100,12 @@ class AppKernel extends Kernel
$loader->load(function (ContainerBuilder $container) { $loader->load(function (ContainerBuilder $container) {
$this->processDatabaseParameters($container); $this->processDatabaseParameters($container);
if ('test' === $container->getParameter('kernel.environment')) {
$this->processDatabaseParameters($container, true);
}
}); });
} }
private function processDatabaseParameters(ContainerBuilder $container, bool $isTest = false) private function processDatabaseParameters(ContainerBuilder $container)
{ {
$prefix = ''; switch ($container->getParameter('database_driver')) {
if ($isTest) {
$prefix = 'test_';
}
switch ($container->getParameter($prefix . 'database_driver')) {
case 'pdo_mysql': case 'pdo_mysql':
$scheme = 'mysql'; $scheme = 'mysql';
break; break;
@ -126,18 +116,18 @@ class AppKernel extends Kernel
$scheme = 'sqlite'; $scheme = 'sqlite';
break; break;
default: default:
throw new \RuntimeException('Unsupported database driver: ' . $container->getParameter($prefix . 'database_driver')); throw new \RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver'));
} }
$container->setParameter($prefix . 'database_scheme', $scheme); $container->setParameter('database_scheme', $scheme);
if ('sqlite' === $scheme) { if ('sqlite' === $scheme) {
$container->setParameter($prefix . 'database_name', $container->getParameter($prefix . 'database_path')); $container->setParameter('database_name', $container->getParameter('database_path'));
} }
$container->setParameter($prefix . 'database_user', (string) $container->getParameter($prefix . 'database_user')); $container->setParameter('database_user', (string) $container->getParameter('database_user'));
$container->setParameter($prefix . 'database_password', (string) $container->getParameter($prefix . 'database_password')); $container->setParameter('database_password', (string) $container->getParameter('database_password'));
$container->setParameter($prefix . 'database_port', (string) $container->getParameter($prefix . 'database_port')); $container->setParameter('database_port', (string) $container->getParameter('database_port'));
$container->setParameter($prefix . 'database_socket', (string) $container->getParameter($prefix . 'database_socket')); $container->setParameter('database_socket', (string) $container->getParameter('database_socket'));
} }
} }

View file

@ -4,7 +4,6 @@ imports:
- { resource: services_test.yml } - { resource: services_test.yml }
parameters: parameters:
env(TEST_DATABASE_URL): '%test_database_scheme%://%test_database_user%:%test_database_password%@%test_database_host%:%test_database_port%/%test_database_name%?unix_socket=%test_database_socket%&charset=%test_database_charset%'
fosuser_registration: true fosuser_registration: true
framework: framework:
@ -24,7 +23,7 @@ web_profiler:
doctrine: doctrine:
dbal: dbal:
url: '%env(resolve:TEST_DATABASE_URL)%' dbname_suffix: '_test' # for MySQL and PostgreSQL
orm: orm:
metadata_cache_driver: metadata_cache_driver:

View file

@ -1,11 +1,5 @@
parameters: parameters:
test_database_driver: pdo_sqlite # Using an environment variable in order to avoid the error "attempt to write a readonly database"
test_database_host: 127.0.0.1 # when the schema is dropped then recreate
test_database_port: null database_path: "%env(TEST_DATABASE_PATH)%"
test_database_name: null
test_database_user: null
test_database_password: null
test_database_path: "%env(TEST_DATABASE_PATH)%"
env(TEST_DATABASE_PATH): "%kernel.project_dir%/data/db/wallabag_test.sqlite" env(TEST_DATABASE_PATH): "%kernel.project_dir%/data/db/wallabag_test.sqlite"
test_database_socket: null
test_database_charset: utf8

View file

@ -1,11 +1,2 @@
parameters: parameters:
test_database_driver: pdo_mysql env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4
test_database_host: 127.0.0.1
test_database_port: 3306
test_database_name: wallabag_test
test_database_user: root
test_database_password: root
test_database_path: ~
env(TEST_DATABASE_PATH): ~
test_database_socket: null
test_database_charset: utf8mb4

View file

@ -1,11 +1,2 @@
parameters: parameters:
test_database_driver: pdo_pgsql env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8
test_database_host: localhost
test_database_port:
test_database_name: wallabag_test
test_database_user: wallabag
test_database_password: wallabagrocks
test_database_path: ~
env(TEST_DATABASE_PATH): ~
test_database_socket: null
test_database_charset: utf8

View file

@ -1,13 +1,5 @@
parameters: parameters:
test_database_driver: pdo_sqlite env(DATABASE_URL): sqlite://:@localhost/%env(TEST_DATABASE_PATH)%?charset=utf8
test_database_host: localhost
test_database_port:
test_database_name: ~
test_database_user: ~
test_database_password: ~
# Using an environment variable in order to avoid the error "attempt to write a readonly database" # Using an environment variable in order to avoid the error "attempt to write a readonly database"
# when the schema is dropped then recreate # when the schema is dropped then recreate
test_database_path: "%env(TEST_DATABASE_PATH)%"
env(TEST_DATABASE_PATH): "%kernel.project_dir%/data/db/wallabag_test.sqlite" env(TEST_DATABASE_PATH): "%kernel.project_dir%/data/db/wallabag_test.sqlite"
test_database_socket: null
test_database_charset: utf8