Browse Source

[TOOLS][PHPStan][TESTS][Docker] Rework testing Docker container into a more generic tooling container. Keep services up and run coverage and phpstan as commands, for performance and ease of use

v3
Hugo Sales 1 month ago
parent
commit
9d7f43cd28
Signed by: someonewithpc <hugo@hsal.es> GPG Key ID: 7D0C7EAFC9D835A0
12 changed files with 30 additions and 21 deletions
  1. +10
    -4
      Makefile
  2. +3
    -5
      bin/pre-commit
  3. +1
    -0
      docker-compose.yaml.default
  4. +1
    -0
      docker/php/docker-compose.fragment.sh
  5. +0
    -11
      docker/testing/coverage.sh
  6. +0
    -0
      docker/tooling/Dockerfile
  7. +7
    -0
      docker/tooling/coverage.sh
  8. +0
    -0
      docker/tooling/db.env
  9. +3
    -1
      docker/tooling/docker-compose.yaml
  10. +5
    -0
      docker/tooling/phpstan.sh
  11. +0
    -0
      docker/tooling/social.env
  12. +0
    -0
      docker/tooling/xdebug.ini

+ 10
- 4
Makefile View File

@@ -24,8 +24,14 @@ psql-shell: .PHONY
database-force-schema-update:
docker exec -it $(strip $(DIR))_php_1 sh -c "/var/www/social/bin/console doctrine:schema:update --dump-sql --force"

test: .PHONY
cd docker/testing && docker-compose run php; docker-compose down
tooling-docker: .PHONY
@cd docker/tooling && docker-compose up -d > /dev/null 2>&1

stop-test: .PHONY
cd docker/testing && docker-compose down
test: tooling-docker
docker exec tooling_php_1 /var/tooling/coverage.sh

phpstan: tooling-docker
docker exec tooling_php_1 /var/tooling/phpstan.sh

stop-tooling: .PHONY
cd docker/tooling && docker-compose down

+ 3
- 5
bin/pre-commit View File

@@ -9,11 +9,9 @@ if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null);
echo "Running php-cs-fixer on edited files"
for staged in ${staged_files}; do
# work only with existing files
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$'
then
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then
# use php-cs-fixer and get flag of correction
if "${root}/bin/php-cs-fixer" -q fix "${staged}"
then
if "${root}/bin/php-cs-fixer" -q fix "${staged}"; then
git add "${staged}" # execute git add directly
fi
fi
@@ -29,7 +27,7 @@ fi

if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then
echo "Running phpstan"
"${root}/vendor/bin/phpstan" --memory-limit=2G analyse src tests components plugins
make phpstan
fi

# Only commit if there wasn't an error


+ 1
- 0
docker-compose.yaml.default View File

@@ -55,6 +55,7 @@ services:
- ./docker/social/install.sh:/var/entrypoint.d/social_install.sh
# Main files
- .:/var/www/social
- /var/www/social/docker
env_file:
- ./docker/social/social.env
- ./docker/db/db.env


+ 1
- 0
docker/php/docker-compose.fragment.sh View File

@@ -32,6 +32,7 @@ cat <<EOF
- ./docker/social/install.sh:/var/entrypoint.d/social_install.sh
# Main files
- .:/var/www/social
- /var/www/social/docker # exclude docker folder
env_file:
- ./docker/social/social.env
- ./docker/db/db.env


+ 0
- 11
docker/testing/coverage.sh View File

@@ -1,11 +0,0 @@
#!/bin/sh

cd /var/www/social || exit 65

yes yes | php bin/console doctrine:fixtures:load || exit 65

if runuser -u www-data -- vendor/bin/simple-phpunit -vvv --coverage-html .test_coverage_report; then
exit 64
else
exit 65
fi

docker/testing/Dockerfile → docker/tooling/Dockerfile View File


+ 7
- 0
docker/tooling/coverage.sh View File

@@ -0,0 +1,7 @@
#!/bin/sh

cd /var/www/social || exit 1

yes yes | php bin/console doctrine:fixtures:load || exit 1

runuser -u www-data -- vendor/bin/simple-phpunit -vvv --coverage-html .test_coverage_report

docker/testing/db.env → docker/tooling/db.env View File


docker/testing/docker-compose.yaml → docker/tooling/docker-compose.yaml View File

@@ -11,9 +11,11 @@ services:
- ../php/entrypoint.sh:/entrypoint.sh
- ../db/wait_for_db.sh:/wait_for_db.sh
- ../social/install.sh:/var/entrypoint.d/0_social_install.sh
- ./coverage.sh:/var/entrypoint.d/8_coverage.sh
- ./coverage.sh:/var/tooling/coverage.sh
- ./phpstan.sh:/var/tooling/phpstan.sh
# Main files
- ../../:/var/www/social
- /var/www/social/docker # exclude docker folder
- ./xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
env_file:
- social.env

+ 5
- 0
docker/tooling/phpstan.sh View File

@@ -0,0 +1,5 @@
#!/usr/bin/env sh

cd /var/www/social || exit 1

vendor/bin/phpstan --ansi --no-interaction --memory-limit=2G analyse src tests components plugins

docker/testing/social.env → docker/tooling/social.env View File


docker/testing/xdebug.ini → docker/tooling/xdebug.ini View File


Loading…
Cancel
Save