Updated how database tests are run in travis, so that all DB engines are covered

This commit is contained in:
Alejandro Celaya 2020-05-04 19:55:03 +02:00
parent 79b8834c61
commit e747a0b250
3 changed files with 9 additions and 15 deletions

View File

@ -8,8 +8,6 @@ php:
- '7.4' - '7.4'
services: services:
- mysql
- postgresql
- docker - docker
cache: cache:
@ -26,8 +24,7 @@ install:
- composer install --no-interaction --prefer-dist - composer install --no-interaction --prefer-dist
before_script: before_script:
- mysql -e 'CREATE DATABASE shlink_test;' - docker-compose up shlink_db shlink_db_postgres shlink_db_maria shlink_db_ms -d
- psql -c 'create database shlink_test;' -U postgres
- mkdir build - mkdir build
- export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep Dockerfile) - export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep Dockerfile)

View File

@ -109,7 +109,7 @@
], ],
"test:ci": [ "test:ci": [
"@test:unit:ci", "@test:unit:ci",
"@test:db:ci", "@test:db",
"@test:api:ci" "@test:api:ci"
], ],
"test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox", "test:unit": "phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox",
@ -121,11 +121,6 @@
"@test:db:postgres", "@test:db:postgres",
"@test:db:ms" "@test:db:ms"
], ],
"test:db:ci": [
"@test:db:sqlite",
"@test:db:mysql",
"@test:db:postgres"
],
"test:db:sqlite": "APP_ENV=test phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-db.cov --testdox -c phpunit-db.xml", "test:db:sqlite": "APP_ENV=test phpdbg -qrr vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-db.cov --testdox -c phpunit-db.xml",
"test:db:mysql": "DB_DRIVER=mysql composer test:db:sqlite", "test:db:mysql": "DB_DRIVER=mysql composer test:db:sqlite",
"test:db:maria": "DB_DRIVER=maria composer test:db:sqlite", "test:db:maria": "DB_DRIVER=maria composer test:db:sqlite",
@ -152,8 +147,7 @@
"test:ci": "<fg=blue;options=bold>Runs all test suites, generating all needed reports and logs for CI envs</>", "test:ci": "<fg=blue;options=bold>Runs all test suites, generating all needed reports and logs for CI envs</>",
"test:unit": "<fg=blue;options=bold>Runs unit test suites</>", "test:unit": "<fg=blue;options=bold>Runs unit test suites</>",
"test:unit:ci": "<fg=blue;options=bold>Runs unit test suites, generating all needed reports and logs for CI envs</>", "test:unit:ci": "<fg=blue;options=bold>Runs unit test suites, generating all needed reports and logs for CI envs</>",
"test:db": "<fg=blue;options=bold>Runs database test suites on a SQLite, MySQL, MariaDB and PostgreSQL</>", "test:db": "<fg=blue;options=bold>Runs database test suites on a SQLite, MySQL, MariaDB, PostgreSQL and MsSQL</>",
"test:db:ci": "<fg=blue;options=bold>Runs database test suites on a SQLite, MySQL and PostgreSQL</>",
"test:db:sqlite": "<fg=blue;options=bold>Runs database test suites on a SQLite database</>", "test:db:sqlite": "<fg=blue;options=bold>Runs database test suites on a SQLite database</>",
"test:db:mysql": "<fg=blue;options=bold>Runs database test suites on a MySQL database</>", "test:db:mysql": "<fg=blue;options=bold>Runs database test suites on a MySQL database</>",
"test:db:maria": "<fg=blue;options=bold>Runs database test suites on a MariaDB database</>", "test:db:maria": "<fg=blue;options=bold>Runs database test suites on a MariaDB database</>",

View File

@ -20,6 +20,7 @@ $buildDbConnection = function (): array {
$driver = env('DB_DRIVER', 'sqlite'); $driver = env('DB_DRIVER', 'sqlite');
$isCi = env('TRAVIS', false); $isCi = env('TRAVIS', false);
$getMysqlHost = fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria'); $getMysqlHost = fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria');
$getCiMysqlPort = fn (string $driver) => $driver === 'mysql' ? '3307' : '3308';
$driverConfigMap = [ $driverConfigMap = [
'sqlite' => [ 'sqlite' => [
@ -29,8 +30,9 @@ $buildDbConnection = function (): array {
'mysql' => [ 'mysql' => [
'driver' => 'pdo_mysql', 'driver' => 'pdo_mysql',
'host' => $isCi ? '127.0.0.1' : $getMysqlHost($driver), 'host' => $isCi ? '127.0.0.1' : $getMysqlHost($driver),
'port' => $isCi ? $getCiMysqlPort($driver) : '3306',
'user' => 'root', 'user' => 'root',
'password' => $isCi ? '' : 'root', 'password' => 'root',
'dbname' => 'shlink_test', 'dbname' => 'shlink_test',
'charset' => 'utf8', 'charset' => 'utf8',
'driverOptions' => [ 'driverOptions' => [
@ -41,8 +43,9 @@ $buildDbConnection = function (): array {
'postgres' => [ 'postgres' => [
'driver' => 'pdo_pgsql', 'driver' => 'pdo_pgsql',
'host' => $isCi ? '127.0.0.1' : 'shlink_db_postgres', 'host' => $isCi ? '127.0.0.1' : 'shlink_db_postgres',
'port' => $isCi ? '5433' : '5432',
'user' => 'postgres', 'user' => 'postgres',
'password' => $isCi ? '' : 'root', 'password' => 'root',
'dbname' => 'shlink_test', 'dbname' => 'shlink_test',
'charset' => 'utf8', 'charset' => 'utf8',
], ],
@ -50,7 +53,7 @@ $buildDbConnection = function (): array {
'driver' => 'pdo_sqlsrv', 'driver' => 'pdo_sqlsrv',
'host' => $isCi ? '127.0.0.1' : 'shlink_db_ms', 'host' => $isCi ? '127.0.0.1' : 'shlink_db_ms',
'user' => 'sa', 'user' => 'sa',
'password' => $isCi ? '' : 'Passw0rd!', 'password' => 'Passw0rd!',
'dbname' => 'shlink_test', 'dbname' => 'shlink_test',
], ],
]; ];