Skip to content

Commit

Permalink
ci: support testing against mysql, sqlserver, pgsql using Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed May 26, 2024
1 parent 07e3337 commit 2189a74
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 21 deletions.
30 changes: 23 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
#
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
# With custom namespace provided, it will be used to prefix all services
# in Docker network for current project
#
COMPOSE_PROJECT_NAME=laravel-cycle-orm-adapter
APP_ENV=production

DB_CONNECTION=pgsql
DB_HOST=pgsql
DB_PORT=5432

DB_DATABASE=default
DB_USERNAME=root
DB_PASSWORD=password
#
# You can override default .envs from config/cycle.php here
#
DB_CONNECTION=memory
DB_PASSWORD=wZ8__DMu5_GZjRL
# DB_CONNECTION=pgsql
# DB_HOST=pgsql
# DB_PORT=5432
# DB_DATABASE=default
# DB_USERNAME=cycle

DB_MYSQL_FORWARD_PORT=13306
DB_PGSQL_FORWARD_PORT=15432
DB_SQLSERVER_FORWARD_PORT=11434

XDEBUG_MODE=coverage

CYCLE_ADAPTER_QUEUE_INTEGRATION=false
CYCLE_ADAPTER_SESSION_INTEGRATION=false
CYCLE_ADAPTER_CACHE_INTEGRATION=false

CYCLE_ATTRIBUTES_CACHE=true
CYCLE_ATTRIBUTES_CACHE_DRIVER=array

CYCLE_SCHEMA_CACHE=true
CYCLE_SCHEMA_CACHE_DRIVER=array
18 changes: 17 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,26 @@ infect-ci: ## Runs infection – mutation testing framework with github output (
$(APP_COMPOSER) infect:ci
.PHONY: lint-infect-ci

test: ## Run project php-unit and pest tests
test: ## Run project php-unit and pest tests against sqlite in-memory database
$(APP_COMPOSER) test
.PHONY: test

test-pgsql: ## Run project php-unit and pest tests over pgsql database
$(APP_COMPOSER) test:pgsql
.PHONY: test-pgsql

test-mysql: ## Run project php-unit and pest tests over mysql database
$(APP_COMPOSER) test:mysql
.PHONY: test-mysql

test-sqlite: ## Run project php-unit and pest tests over sqlite in-file database
$(APP_COMPOSER) test:sqlite
.PHONY: test-sqlite

test-sqlserver: ## Run project php-unit and pest tests over mssql (sqlserver) database
$(APP_COMPOSER) test:sqlserver
.PHONY: test-sqlserver

test-cc: ## Run project php-unit and pest tests in coverage mode and build report
$(APP_COMPOSER) test:cc
.PHONY: test-cc
Expand Down
23 changes: 23 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@
"test:cc": [
"@putenv XDEBUG_MODE=coverage",
"php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
],
"test:mysql": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=mysql",
"@putenv DB_HOST=mysql",
"php vendor/bin/pest --color=always"
],
"test:pgsql": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=pgsql",
"@putenv DB_HOST=pgsql",
"php vendor/bin/pest --color=always"
],
"test:sqlite": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=sqlite",
"php vendor/bin/pest --color=always"
],
"test:sqlserver": [
"@putenv XDEBUG_MODE=coverage",
"@putenv DB_CONNECTION=sqlserver",
"@putenv DB_HOST=sqlserver",
"php vendor/bin/pest --color=always"
]
}
}
17 changes: 9 additions & 8 deletions config/cycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
*/
'databases' => [
'default' => [
'driver' => env('DB_CONNECTION', 'sqlite'),
'driver' => env('DB_CONNECTION', 'memory'),
],
],

Expand All @@ -111,7 +111,7 @@

'sqlite' => new Config\SQLiteDriverConfig(
connection: new Config\SQLite\FileConnectionConfig(
database: env('DB_DATABASE', database_path('database.sqlite'))
database: database_path(env('DB_DATABASE', 'database')) . '.sqlite'
),
driver: Driver\SQLite\SQLiteDriver::class,
reconnect: true,
Expand All @@ -127,10 +127,10 @@

'pgsql' => new Config\PostgresDriverConfig(
connection: new Config\Postgres\TcpConnectionConfig(
database: env('DB_DATABASE', 'wod'),
database: env('DB_DATABASE', 'default'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 5432),
user: env('DB_USERNAME', 'wod'),
user: env('DB_USERNAME', 'cycle'),
password: env('DB_PASSWORD', '')
),
schema: Config\PostgresDriverConfig::DEFAULT_SCHEMA,
Expand All @@ -148,10 +148,10 @@

'mysql' => new Config\MySQLDriverConfig(
connection: new Config\MySQL\TcpConnectionConfig(
database: env('DB_DATABASE', 'wod'),
database: env('DB_DATABASE', 'default'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 3306),
user: env('DB_USERNAME', 'wod'),
user: env('DB_USERNAME', 'cycle'),
password: env('DB_PASSWORD', '')
),
driver: Driver\MySQL\MySQLDriver::class,
Expand All @@ -168,10 +168,11 @@

'sqlserver' => new Config\SQLServerDriverConfig(
connection: new Config\SQLServer\TcpConnectionConfig(
database: env('DB_DATABASE', 'wod'),
database: env('DB_DATABASE', 'tempdb'),
host: env('DB_HOST', '127.0.0.1'),
port: env('DB_PORT', 1433),
user: env('DB_USERNAME', 'wod'),
trustServerCertificate: true,
user: env('DB_USERNAME', 'SA'),
password: env('DB_PASSWORD', '')
),
driver: Driver\SQLServer\SQLServerDriver::class,
Expand Down
45 changes: 40 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ services:
env_file:
- .env
environment:
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_USER: ${DB_USERNAME:-cycle}
POSTGRES_PASSWORD: ${DB_PASSWORD}
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_DB: ${DB_DATABASE:-default}
volumes:
- pgsql-data:/var/lib/postgresql/data:cached
healthcheck:
test: ['CMD', 'pg_isready', '-U', '${DB_USERNAME:-cycle}', '-d', '${DB_DATABASE:-default}']
interval: 3s
timeout: 1s
retries: 10

mysql:
image: mysql:latest
Expand All @@ -44,18 +49,48 @@ services:
- .env
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_USER: ${DB_USERNAME}
MYSQL_USER: ${DB_USERNAME:-cycle}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_DATABASE: ${DB_DATABASE:-default}
volumes:
- mysql-data:/var/lib/mysql:cached
command: --default-authentication-plugin=mysql_native_password
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
interval: 3s
timeout: 1s
retries: 10

sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
platform: linux/amd64
container_name: ${COMPOSE_PROJECT_NAME}-sqlserver
restart: on-failure
networks:
- default
ports:
- '${DB_SQLSERVER_FORWARD_PORT:-11434}:1433'
env_file:
- .env
environment:
SA_PASSWORD: ${DB_PASSWORD}
ACCEPT_EULA: 'Y'
volumes:
- sqlserver-data:/var/opt/mssql
healthcheck:
test:
['CMD', '/opt/mssql-tools/bin/sqlcmd', '-S', 'localhost', '-U', 'SA', '-P', '${DB_PASSWORD}', '-l', '30', '-Q', 'SELECT 1']
interval: 3s
timeout: 1s
retries: 10

volumes:
pgsql-data:
name: ${COMPOSE_PROJECT_NAME}-pgsql-data
mysql-data:
name: ${COMPOSE_PROJECT_NAME}-mysql-data
sqlserver-data:
name: ${COMPOSE_PROJECT_NAME}-sqlserver-data

networks:
default:
Expand Down

0 comments on commit 2189a74

Please sign in to comment.