Merge pull request #7161 from yguedidi/make-tests-use-dev-database-config

Make tests use dev database config
This commit is contained in:
Yassine Guedidi 2024-01-08 09:45:55 +01:00 committed by GitHub
commit 4eb31d1280
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 55 deletions

View file

@ -97,5 +97,37 @@ class AppKernel extends Kernel
// $container->setParameter('container.dumper.inline_class_loader', true);
$container->addObjectResource($this);
});
$loader->load(function (ContainerBuilder $container) {
$this->processDatabaseParameters($container);
});
}
private function processDatabaseParameters(ContainerBuilder $container)
{
switch ($container->getParameter('database_driver')) {
case 'pdo_mysql':
$scheme = 'mysql';
break;
case 'pdo_pgsql':
$scheme = 'pgsql';
break;
case 'pdo_sqlite':
$scheme = 'sqlite';
break;
default:
throw new \RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver'));
}
$container->setParameter('database_scheme', $scheme);
if ('sqlite' === $scheme) {
$container->setParameter('database_name', $container->getParameter('database_path'));
}
$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'));
}
}

View file

@ -8,6 +8,7 @@ parameters:
# Allows to use the live reload feature for changes in assets
use_webpack_dev_server: false
craue_config.cache_adapter.class: Craue\ConfigBundle\CacheAdapter\SymfonyCacheComponentAdapter
env(DATABASE_URL): '%database_scheme%://%database_user%:%database_password%@%database_host%:%database_port%/%database_name%?unix_socket=%database_socket%&charset=%database_charset%'
framework:
#esi: ~
@ -48,15 +49,7 @@ twig:
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: "%database_charset%"
path: "%database_path%"
unix_socket: "%database_socket%"
url: '%env(resolve:DATABASE_URL)%'
types:
json_array: Wallabag\CoreBundle\Doctrine\JsonArrayType

View file

@ -3,6 +3,9 @@ imports:
- { resource: parameters_test.yml }
- { resource: services_test.yml }
parameters:
fosuser_registration: true
framework:
test: ~
session:
@ -20,14 +23,7 @@ web_profiler:
doctrine:
dbal:
driver: "%test_database_driver%"
host: "%test_database_host%"
port: "%test_database_port%"
dbname: "%test_database_name%"
user: "%test_database_user%"
password: "%test_database_password%"
charset: "%test_database_charset%"
path: "%env(TEST_DATABASE_PATH)%"
dbname_suffix: '_test' # for MySQL and PostgreSQL
orm:
metadata_cache_driver:

View file

@ -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_charset: utf8
fosuser_registration: true

View file

@ -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_charset: utf8mb4
fosuser_registration: true
env(DATABASE_URL): mysql://root:root@127.0.0.1:3306/wallabag?charset=utf8mb4

View file

@ -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_charset: utf8
fosuser_registration: true
env(DATABASE_URL): postgres://wallabag:wallabagrocks@localhost/wallabag?charset=utf8

View file

@ -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_charset: utf8
fosuser_registration: true