Skip to content

Commit 2189a74

Browse files
committed
ci: support testing against mysql, sqlserver, pgsql using Makefile
1 parent 07e3337 commit 2189a74

File tree

5 files changed

+112
-21
lines changed

5 files changed

+112
-21
lines changed

.env.example

+23-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1+
#
12
# https://docs.docker.com/compose/reference/envvars/#compose_project_name
23
# With custom namespace provided, it will be used to prefix all services
34
# in Docker network for current project
5+
#
46
COMPOSE_PROJECT_NAME=laravel-cycle-orm-adapter
57
APP_ENV=production
68

7-
DB_CONNECTION=pgsql
8-
DB_HOST=pgsql
9-
DB_PORT=5432
10-
11-
DB_DATABASE=default
12-
DB_USERNAME=root
13-
DB_PASSWORD=password
9+
#
10+
# You can override default .envs from config/cycle.php here
11+
#
12+
DB_CONNECTION=memory
13+
DB_PASSWORD=wZ8__DMu5_GZjRL
14+
# DB_CONNECTION=pgsql
15+
# DB_HOST=pgsql
16+
# DB_PORT=5432
17+
# DB_DATABASE=default
18+
# DB_USERNAME=cycle
1419

1520
DB_MYSQL_FORWARD_PORT=13306
1621
DB_PGSQL_FORWARD_PORT=15432
22+
DB_SQLSERVER_FORWARD_PORT=11434
1723

1824
XDEBUG_MODE=coverage
25+
26+
CYCLE_ADAPTER_QUEUE_INTEGRATION=false
27+
CYCLE_ADAPTER_SESSION_INTEGRATION=false
28+
CYCLE_ADAPTER_CACHE_INTEGRATION=false
29+
30+
CYCLE_ATTRIBUTES_CACHE=true
31+
CYCLE_ATTRIBUTES_CACHE_DRIVER=array
32+
33+
CYCLE_SCHEMA_CACHE=true
34+
CYCLE_SCHEMA_CACHE_DRIVER=array

Makefile

+17-1
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,26 @@ infect-ci: ## Runs infection – mutation testing framework with github output (
264264
$(APP_COMPOSER) infect:ci
265265
.PHONY: lint-infect-ci
266266

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

271+
test-pgsql: ## Run project php-unit and pest tests over pgsql database
272+
$(APP_COMPOSER) test:pgsql
273+
.PHONY: test-pgsql
274+
275+
test-mysql: ## Run project php-unit and pest tests over mysql database
276+
$(APP_COMPOSER) test:mysql
277+
.PHONY: test-mysql
278+
279+
test-sqlite: ## Run project php-unit and pest tests over sqlite in-file database
280+
$(APP_COMPOSER) test:sqlite
281+
.PHONY: test-sqlite
282+
283+
test-sqlserver: ## Run project php-unit and pest tests over mssql (sqlserver) database
284+
$(APP_COMPOSER) test:sqlserver
285+
.PHONY: test-sqlserver
286+
271287
test-cc: ## Run project php-unit and pest tests in coverage mode and build report
272288
$(APP_COMPOSER) test:cc
273289
.PHONY: test-cc

composer.json

+23
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@
164164
"test:cc": [
165165
"@putenv XDEBUG_MODE=coverage",
166166
"php vendor/bin/pest --coverage --coverage-clover=.build/phpunit/logs/clover.xml --color=always"
167+
],
168+
"test:mysql": [
169+
"@putenv XDEBUG_MODE=coverage",
170+
"@putenv DB_CONNECTION=mysql",
171+
"@putenv DB_HOST=mysql",
172+
"php vendor/bin/pest --color=always"
173+
],
174+
"test:pgsql": [
175+
"@putenv XDEBUG_MODE=coverage",
176+
"@putenv DB_CONNECTION=pgsql",
177+
"@putenv DB_HOST=pgsql",
178+
"php vendor/bin/pest --color=always"
179+
],
180+
"test:sqlite": [
181+
"@putenv XDEBUG_MODE=coverage",
182+
"@putenv DB_CONNECTION=sqlite",
183+
"php vendor/bin/pest --color=always"
184+
],
185+
"test:sqlserver": [
186+
"@putenv XDEBUG_MODE=coverage",
187+
"@putenv DB_CONNECTION=sqlserver",
188+
"@putenv DB_HOST=sqlserver",
189+
"php vendor/bin/pest --color=always"
167190
]
168191
}
169192
}

config/cycle.php

+9-8
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
*/
8888
'databases' => [
8989
'default' => [
90-
'driver' => env('DB_CONNECTION', 'sqlite'),
90+
'driver' => env('DB_CONNECTION', 'memory'),
9191
],
9292
],
9393

@@ -111,7 +111,7 @@
111111

112112
'sqlite' => new Config\SQLiteDriverConfig(
113113
connection: new Config\SQLite\FileConnectionConfig(
114-
database: env('DB_DATABASE', database_path('database.sqlite'))
114+
database: database_path(env('DB_DATABASE', 'database')) . '.sqlite'
115115
),
116116
driver: Driver\SQLite\SQLiteDriver::class,
117117
reconnect: true,
@@ -127,10 +127,10 @@
127127

128128
'pgsql' => new Config\PostgresDriverConfig(
129129
connection: new Config\Postgres\TcpConnectionConfig(
130-
database: env('DB_DATABASE', 'wod'),
130+
database: env('DB_DATABASE', 'default'),
131131
host: env('DB_HOST', '127.0.0.1'),
132132
port: env('DB_PORT', 5432),
133-
user: env('DB_USERNAME', 'wod'),
133+
user: env('DB_USERNAME', 'cycle'),
134134
password: env('DB_PASSWORD', '')
135135
),
136136
schema: Config\PostgresDriverConfig::DEFAULT_SCHEMA,
@@ -148,10 +148,10 @@
148148

149149
'mysql' => new Config\MySQLDriverConfig(
150150
connection: new Config\MySQL\TcpConnectionConfig(
151-
database: env('DB_DATABASE', 'wod'),
151+
database: env('DB_DATABASE', 'default'),
152152
host: env('DB_HOST', '127.0.0.1'),
153153
port: env('DB_PORT', 3306),
154-
user: env('DB_USERNAME', 'wod'),
154+
user: env('DB_USERNAME', 'cycle'),
155155
password: env('DB_PASSWORD', '')
156156
),
157157
driver: Driver\MySQL\MySQLDriver::class,
@@ -168,10 +168,11 @@
168168

169169
'sqlserver' => new Config\SQLServerDriverConfig(
170170
connection: new Config\SQLServer\TcpConnectionConfig(
171-
database: env('DB_DATABASE', 'wod'),
171+
database: env('DB_DATABASE', 'tempdb'),
172172
host: env('DB_HOST', '127.0.0.1'),
173173
port: env('DB_PORT', 1433),
174-
user: env('DB_USERNAME', 'wod'),
174+
trustServerCertificate: true,
175+
user: env('DB_USERNAME', 'SA'),
175176
password: env('DB_PASSWORD', '')
176177
),
177178
driver: Driver\SQLServer\SQLServerDriver::class,

docker-compose.yaml

+40-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ services:
2626
env_file:
2727
- .env
2828
environment:
29-
POSTGRES_USER: ${DB_USERNAME}
29+
POSTGRES_USER: ${DB_USERNAME:-cycle}
3030
POSTGRES_PASSWORD: ${DB_PASSWORD}
31-
POSTGRES_DB: ${DB_DATABASE}
31+
POSTGRES_DB: ${DB_DATABASE:-default}
3232
volumes:
3333
- pgsql-data:/var/lib/postgresql/data:cached
34+
healthcheck:
35+
test: ['CMD', 'pg_isready', '-U', '${DB_USERNAME:-cycle}', '-d', '${DB_DATABASE:-default}']
36+
interval: 3s
37+
timeout: 1s
38+
retries: 10
3439

3540
mysql:
3641
image: mysql:latest
@@ -44,18 +49,48 @@ services:
4449
- .env
4550
environment:
4651
MYSQL_ROOT_HOST: '%'
47-
MYSQL_USER: ${DB_USERNAME}
52+
MYSQL_USER: ${DB_USERNAME:-cycle}
53+
MYSQL_PASSWORD: ${DB_PASSWORD}
4854
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
49-
MYSQL_DATABASE: ${DB_DATABASE}
55+
MYSQL_DATABASE: ${DB_DATABASE:-default}
5056
volumes:
5157
- mysql-data:/var/lib/mysql:cached
52-
command: --default-authentication-plugin=mysql_native_password
58+
healthcheck:
59+
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost']
60+
interval: 3s
61+
timeout: 1s
62+
retries: 10
63+
64+
sqlserver:
65+
image: mcr.microsoft.com/mssql/server:2022-latest
66+
platform: linux/amd64
67+
container_name: ${COMPOSE_PROJECT_NAME}-sqlserver
68+
restart: on-failure
69+
networks:
70+
- default
71+
ports:
72+
- '${DB_SQLSERVER_FORWARD_PORT:-11434}:1433'
73+
env_file:
74+
- .env
75+
environment:
76+
SA_PASSWORD: ${DB_PASSWORD}
77+
ACCEPT_EULA: 'Y'
78+
volumes:
79+
- sqlserver-data:/var/opt/mssql
80+
healthcheck:
81+
test:
82+
['CMD', '/opt/mssql-tools/bin/sqlcmd', '-S', 'localhost', '-U', 'SA', '-P', '${DB_PASSWORD}', '-l', '30', '-Q', 'SELECT 1']
83+
interval: 3s
84+
timeout: 1s
85+
retries: 10
5386

5487
volumes:
5588
pgsql-data:
5689
name: ${COMPOSE_PROJECT_NAME}-pgsql-data
5790
mysql-data:
5891
name: ${COMPOSE_PROJECT_NAME}-mysql-data
92+
sqlserver-data:
93+
name: ${COMPOSE_PROJECT_NAME}-sqlserver-data
5994

6095
networks:
6196
default:

0 commit comments

Comments
 (0)