From 8d3f575c037f337de4fcee81eb2ae1ececc5b533 Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Fri, 5 Jan 2024 00:41:13 +0100 Subject: [PATCH] Make tests use dev database config --- app/AppKernel.php | 28 +++++++-------------- app/config/config_test.yml | 3 +-- app/config/parameters_test.yml | 12 +++------ app/config/tests/parameters_test.mysql.yml | 11 +------- app/config/tests/parameters_test.pgsql.yml | 11 +------- app/config/tests/parameters_test.sqlite.yml | 10 +------- 6 files changed, 16 insertions(+), 59 deletions(-) diff --git a/app/AppKernel.php b/app/AppKernel.php index b684f2f95..314b34390 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -100,22 +100,12 @@ class AppKernel extends Kernel $loader->load(function (ContainerBuilder $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 = ''; - - if ($isTest) { - $prefix = 'test_'; - } - - switch ($container->getParameter($prefix . 'database_driver')) { + switch ($container->getParameter('database_driver')) { case 'pdo_mysql': $scheme = 'mysql'; break; @@ -126,18 +116,18 @@ class AppKernel extends Kernel $scheme = 'sqlite'; break; 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) { - $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($prefix . 'database_password', (string) $container->getParameter($prefix . 'database_password')); - $container->setParameter($prefix . 'database_port', (string) $container->getParameter($prefix . 'database_port')); - $container->setParameter($prefix . 'database_socket', (string) $container->getParameter($prefix . 'database_socket')); + $container->setParameter('database_user', (string) $container->getParameter('database_user')); + $container->setParameter('database_password', (string) $container->getParameter('database_password')); + $container->setParameter('database_port', (string) $container->getParameter('database_port')); + $container->setParameter('database_socket', (string) $container->getParameter('database_socket')); } } diff --git a/app/config/config_test.yml b/app/config/config_test.yml index d685451be..4ea1c0a48 100644 --- a/app/config/config_test.yml +++ b/app/config/config_test.yml @@ -4,7 +4,6 @@ imports: - { resource: services_test.yml } 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 framework: @@ -24,7 +23,7 @@ web_profiler: doctrine: dbal: - url: '%env(resolve:TEST_DATABASE_URL)%' + dbname_suffix: '_test' # for MySQL and PostgreSQL orm: metadata_cache_driver: diff --git a/app/config/parameters_test.yml b/app/config/parameters_test.yml index 360fa7471..551092d74 100644 --- a/app/config/parameters_test.yml +++ b/app/config/parameters_test.yml @@ -1,11 +1,5 @@ parameters: - test_database_driver: pdo_sqlite - test_database_host: 127.0.0.1 - test_database_port: null - test_database_name: null - test_database_user: null - test_database_password: null - test_database_path: "%env(TEST_DATABASE_PATH)%" + # Using an environment variable in order to avoid the error "attempt to write a readonly database" + # when the schema is dropped then recreate + database_path: "%env(TEST_DATABASE_PATH)%" env(TEST_DATABASE_PATH): "%kernel.project_dir%/data/db/wallabag_test.sqlite" - test_database_socket: null - test_database_charset: utf8 diff --git a/app/config/tests/parameters_test.mysql.yml b/app/config/tests/parameters_test.mysql.yml index 4f057fd1e..6e1a87b79 100644 --- a/app/config/tests/parameters_test.mysql.yml +++ b/app/config/tests/parameters_test.mysql.yml @@ -1,11 +1,2 @@ parameters: - test_database_driver: pdo_mysql - 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 + env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4 diff --git a/app/config/tests/parameters_test.pgsql.yml b/app/config/tests/parameters_test.pgsql.yml index b91ae6f34..8a3d0498e 100644 --- a/app/config/tests/parameters_test.pgsql.yml +++ b/app/config/tests/parameters_test.pgsql.yml @@ -1,11 +1,2 @@ parameters: - test_database_driver: pdo_pgsql - 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 + env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8 diff --git a/app/config/tests/parameters_test.sqlite.yml b/app/config/tests/parameters_test.sqlite.yml index b1e53a266..ac76d61ec 100644 --- a/app/config/tests/parameters_test.sqlite.yml +++ b/app/config/tests/parameters_test.sqlite.yml @@ -1,13 +1,5 @@ parameters: - test_database_driver: pdo_sqlite - test_database_host: localhost - test_database_port: - test_database_name: ~ - test_database_user: ~ - test_database_password: ~ + env(DATABASE_URL): sqlite://:@localhost/%env(TEST_DATABASE_PATH)%?charset=utf8 # Using an environment variable in order to avoid the error "attempt to write a readonly database" # 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" - test_database_socket: null - test_database_charset: utf8