Skip to content

Commit e7e9116

Browse files
committed
feat: упрощение тестового окружения
1 parent 1521236 commit e7e9116

14 files changed

+67
-110
lines changed

.docker/.env.dist

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
PROJECT_NAME=symfony-based-phone-checker
12
HTTP_PORT=80
23

34
PHP_VERSION=7.4

.docker/.env.testing

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ENABLE_XDEBUG=1

.docker/Makefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@ setup:
3737
@cp -n docker-compose.override.yml.dist docker-compose.override.yml
3838

3939
tests: setup
40-
@cd ./tests && make run
40+
@docker-compose -p ${PROJECT_NAME}_testing -f docker-compose.yml -f docker-compose.testing.yml up -d
41+
@docker-compose -p ${PROJECT_NAME}_testing exec -T web bash /wait-for.sh --timeout=30 localhost:80 -- echo "Webserver started"
42+
@docker-compose -p ${PROJECT_NAME}_testing exec -T php ./vendor/bin/codecept run
43+
@docker-compose -p ${PROJECT_NAME}_testing stop
4144

4245
coverage: setup
43-
@cd ./tests && make coverage
46+
@docker-compose -p ${PROJECT_NAME}_testing -f docker-compose.yml -f docker-compose.testing.yml up -d
47+
@docker-compose -p ${PROJECT_NAME}_testing exec -T web bash /wait-for.sh --timeout=30 localhost:80 -- echo "Webserver started"
48+
@docker-compose -p ${PROJECT_NAME}_testing exec -T php ./vendor/bin/codecept run --coverage --coverage-xml
49+
@docker-compose -p ${PROJECT_NAME}_testing stop
50+
51+
ci: setup
52+
@docker-compose -p ${PROJECT_NAME}_testing -f docker-compose.yml -f docker-compose.testing.yml up -d
53+
@docker-compose -p ${PROJECT_NAME}_testing exec -T web bash /wait-for.sh --timeout=30 localhost:80 -- echo "Webserver started"
54+
@docker-compose -p ${PROJECT_NAME}_testing exec -T php ./vendor/bin/grumphp run --testsuite=ci
55+
@docker-compose -p ${PROJECT_NAME}_testing stop

.docker/docker-compose.testing.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
services:
3+
web:
4+
container_name: ${PROJECT_NAME}_web_testing
5+
env_file:
6+
- ".env.testing"
7+
php:
8+
container_name: ${PROJECT_NAME}_php_testing
9+
env_file:
10+
- ".env.testing"
11+
mysql:
12+
container_name: ${PROJECT_NAME}_mysql_testing
13+
volumes:
14+
- "./data/testing/mysql:/var/lib/mysql"
15+
env_file:
16+
- ".env.testing"

.docker/nginx/start.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
echo 'Run start.sh'
33

4-
bash /wait-for.sh php:9000 -t 0 -- echo "Php fpm started"
4+
bash /wait-for.sh php:9000 --timeout=30 -- echo "Php fpm started"
55

66
nginx -g 'daemon off;'

.docker/nginx/wait-for.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Use this script to test if a given TCP host/port are available
2+
# Use this script to test if a given TCP host/port are available
33

44
WAITFORIT_cmdname=${0##*/}
55

@@ -141,16 +141,20 @@ WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
141141
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
142142
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
143143

144-
# check to see if timeout is from busybox?
144+
# Check to see if timeout is from busybox?
145145
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
146146
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
147+
148+
WAITFORIT_BUSYTIMEFLAG=""
147149
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
148-
WAITFORIT_ISBUSY=1
150+
WAITFORIT_ISBUSY=1
151+
# Check if busybox timeout uses -t flag
152+
# (recent Alpine versions don't support -t anymore)
153+
if timeout &>/dev/stdout | grep -q -e '-t '; then
149154
WAITFORIT_BUSYTIMEFLAG="-t"
150-
155+
fi
151156
else
152-
WAITFORIT_ISBUSY=0
153-
WAITFORIT_BUSYTIMEFLAG=""
157+
WAITFORIT_ISBUSY=0
154158
fi
155159

156160
if [[ $WAITFORIT_CHILD -gt 0 ]]; then

.docker/php/start.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ $ENABLE_XDEBUG == "1" ]; then
99
docker-php-ext-enable xdebug
1010
fi
1111

12-
bash /wait-for.sh mysql:3306 -t 0 -- echo "Mysql started"
12+
bash /wait-for.sh mysql:3306 --timeout=30 -- echo "Mysql started"
1313

1414
php ./bin/console doctrine:migrations:migrate --no-interaction
1515

.docker/php/wait-for.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# Use this script to test if a given TCP host/port are available
2+
# Use this script to test if a given TCP host/port are available
33

44
WAITFORIT_cmdname=${0##*/}
55

@@ -141,16 +141,20 @@ WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
141141
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
142142
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
143143

144-
# check to see if timeout is from busybox?
144+
# Check to see if timeout is from busybox?
145145
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
146146
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
147+
148+
WAITFORIT_BUSYTIMEFLAG=""
147149
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
148-
WAITFORIT_ISBUSY=1
150+
WAITFORIT_ISBUSY=1
151+
# Check if busybox timeout uses -t flag
152+
# (recent Alpine versions don't support -t anymore)
153+
if timeout &>/dev/stdout | grep -q -e '-t '; then
149154
WAITFORIT_BUSYTIMEFLAG="-t"
150-
155+
fi
151156
else
152-
WAITFORIT_ISBUSY=0
153-
WAITFORIT_BUSYTIMEFLAG=""
157+
WAITFORIT_ISBUSY=0
154158
fi
155159

156160
if [[ $WAITFORIT_CHILD -gt 0 ]]; then

.docker/tests/.env.dist

-4
This file was deleted.

.docker/tests/Makefile

-51
This file was deleted.

.docker/tests/docker-compose.override.yml.dist

-1
This file was deleted.

.docker/tests/docker-compose.yml

-25
This file was deleted.

.github/workflows/php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ jobs:
1414
run: composer install --prefer-dist --no-progress --no-suggest --no-scripts
1515

1616
- name: Grumphp
17-
run: cd .docker/tests && make up && docker-compose exec -T php ./vendor/bin/grumphp run --testsuite=ci
17+
run: cd .docker && make ci

grumphp.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ parameters:
3030
priority: 300
3131
git_commit_message:
3232
enforce_capitalized_subject: false
33-
type_scope_conventions:
34-
- types:
35-
- build
36-
- ci
37-
- chore
38-
- docs
39-
- feat
40-
- fix
41-
- perf
42-
- refactor
43-
- test
44-
- scopes: []
33+
type_scope_conventions:
34+
- types:
35+
- build
36+
- ci
37+
- chore
38+
- docs
39+
- feat
40+
- fix
41+
- perf
42+
- refactor
43+
- test
44+
- scopes: []
4545
phpstan:
4646
ignore_patterns: [src/Migrations]
4747
phplint: ~

0 commit comments

Comments
 (0)