diff --git a/.travis.yml b/.travis.yml index 8b232c76..a95bf67d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,6 @@ php: - '7.4' services: - - mysql - - postgresql - docker cache: @@ -17,8 +15,10 @@ cache: - $HOME/.composer/cache/files before_install: + - sudo ./data/infra/ci/install-ms-odbc.sh + - docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_ms shlink_db shlink_db_postgres shlink_db_maria + - yes | pecl install pdo_sqlsrv swoole-4.4.15 - echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - yes | pecl install swoole-4.4.15 - phpenv config-rm xdebug.ini || return 0 install: @@ -26,8 +26,7 @@ install: - composer install --no-interaction --prefer-dist before_script: - - mysql -e 'CREATE DATABASE shlink_test;' - - psql -c 'create database shlink_test;' -U postgres + - docker-compose exec shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;" - mkdir build - export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/master} --name-only | grep Dockerfile) diff --git a/CHANGELOG.md b/CHANGELOG.md index f50e81d2..0358e791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this #### Changed * [#692](https://github.com/shlinkio/shlink/issues/692) Drastically improved performance when loading visits. Specially noticeable when loading big result sets. +* [#657](https://github.com/shlinkio/shlink/issues/657) Updated how DB tests are run in travis by using docker containers which allow all engines to be covered. #### Deprecated diff --git a/composer.json b/composer.json index 39c1e6db..111b60c4 100644 --- a/composer.json +++ b/composer.json @@ -109,7 +109,7 @@ ], "test:ci": [ "@test:unit:ci", - "@test:db:ci", + "@test:db", "@test:api:ci" ], "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: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:mysql": "DB_DRIVER=mysql composer test:db:sqlite", "test:db:maria": "DB_DRIVER=maria composer test:db:sqlite", @@ -152,8 +147,7 @@ "test:ci": "Runs all test suites, generating all needed reports and logs for CI envs", "test:unit": "Runs unit test suites", "test:unit:ci": "Runs unit test suites, generating all needed reports and logs for CI envs", - "test:db": "Runs database test suites on a SQLite, MySQL, MariaDB and PostgreSQL", - "test:db:ci": "Runs database test suites on a SQLite, MySQL and PostgreSQL", + "test:db": "Runs database test suites on a SQLite, MySQL, MariaDB, PostgreSQL and MsSQL", "test:db:sqlite": "Runs database test suites on a SQLite database", "test:db:mysql": "Runs database test suites on a MySQL database", "test:db:maria": "Runs database test suites on a MariaDB database", diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index 6aad5375..0086bcd0 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -20,6 +20,7 @@ $buildDbConnection = function (): array { $driver = env('DB_DRIVER', 'sqlite'); $isCi = env('TRAVIS', false); $getMysqlHost = fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria'); + $getCiMysqlPort = fn (string $driver) => $driver === 'mysql' ? '3307' : '3308'; $driverConfigMap = [ 'sqlite' => [ @@ -29,8 +30,9 @@ $buildDbConnection = function (): array { 'mysql' => [ 'driver' => 'pdo_mysql', 'host' => $isCi ? '127.0.0.1' : $getMysqlHost($driver), + 'port' => $isCi ? $getCiMysqlPort($driver) : '3306', 'user' => 'root', - 'password' => $isCi ? '' : 'root', + 'password' => 'root', 'dbname' => 'shlink_test', 'charset' => 'utf8', 'driverOptions' => [ @@ -41,8 +43,9 @@ $buildDbConnection = function (): array { 'postgres' => [ 'driver' => 'pdo_pgsql', 'host' => $isCi ? '127.0.0.1' : 'shlink_db_postgres', + 'port' => $isCi ? '5433' : '5432', 'user' => 'postgres', - 'password' => $isCi ? '' : 'root', + 'password' => 'root', 'dbname' => 'shlink_test', 'charset' => 'utf8', ], @@ -50,7 +53,7 @@ $buildDbConnection = function (): array { 'driver' => 'pdo_sqlsrv', 'host' => $isCi ? '127.0.0.1' : 'shlink_db_ms', 'user' => 'sa', - 'password' => $isCi ? '' : 'Passw0rd!', + 'password' => 'Passw0rd!', 'dbname' => 'shlink_test', ], ]; diff --git a/data/infra/ci/install-ms-odbc.sh b/data/infra/ci/install-ms-odbc.sh new file mode 100755 index 00000000..8cd60580 --- /dev/null +++ b/data/infra/ci/install-ms-odbc.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -ex + +curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - +curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list +apt-get update +ACCEPT_EULA=Y apt-get install msodbcsql17 +apt-get install unixodbc-dev diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 00000000..3783fef2 --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,14 @@ +version: '3' + +services: + shlink_db: + environment: + MYSQL_DATABASE: shlink_test + + shlink_db_postgres: + environment: + POSTGRES_DB: shlink_test + + shlink_db_maria: + environment: + MYSQL_DATABASE: shlink_test