Skip to content

Commit a67f3ce

Browse files
committed
Unit tests
1 parent 05032bf commit a67f3ce

17 files changed

+2493
-1788
lines changed

Makefile

+60-26
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,98 @@ SHELL=bash
33

44
.PHONY: *
55

6-
DOCKER_CGROUP:=$(shell cat /proc/1/cgroup | grep docker | wc -l)
7-
COMPOSER_CACHE_DIR:=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer/cache)
8-
9-
ifneq ("$(wildcard /.dockerenv)","")
10-
IN_DOCKER:=TRUE
11-
else ifneq ("$(DOCKER_CGROUP)","0")
12-
IN_DOCKER:=TRUE
6+
COMPOSER_SHOW_EXTENSION_LIST=$(shell composer show -t | grep -o "\-\-\(ext-\).\+" | sort | uniq | cut -d- -f4- | tr -d '\n' | grep . | sed '/^$$/d' | xargs | sed -e 's/ /, /g' | tr -cd '[:alnum:],' | sed 's/.$$//')
7+
SLIM_DOCKER_IMAGE=$(shell php -r 'echo count(array_intersect(["gd", "vips"], explode(",", "${COMPOSER_SHOW_EXTENSION_LIST}"))) > 0 ? "" : "-slim";')
8+
PHP_VERSION:=$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN), 2)), 2)[0]);")
9+
CONTAINER_NAME=$(shell echo "ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine${SLIM_DOCKER_IMAGE}-dev")
10+
COMPOSER_CACHE_DIR=$(shell composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)
11+
COMPOSER_CONTAINER_CACHE_DIR=$(shell docker run --rm -it ${CONTAINER_NAME} composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)
12+
13+
ifneq ("$(wildcard /.you-are-in-a-wyrihaximus.net-php-docker-image)","")
14+
IN_DOCKER=TRUE
1315
else
14-
IN_DOCKER:=FALSE
16+
IN_DOCKER=FALSE
1517
endif
1618

1719
ifeq ("$(IN_DOCKER)","TRUE")
1820
DOCKER_RUN:=
1921
else
20-
PHP_VERSION:=$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN), 2)), 2)[0]);")
2122
DOCKER_RUN:=docker run --rm -it \
2223
-v "`pwd`:`pwd`" \
23-
-v "${COMPOSER_CACHE_DIR}:/home/app/.composer/cache" \
24+
-v "${COMPOSER_CACHE_DIR}:${COMPOSER_CONTAINER_CACHE_DIR}" \
2425
-w "`pwd`" \
25-
-e "FORCE_GENERATION=$$FORCE_GENERATION" \
26-
"ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine-slim-dev"
26+
${CONTAINER_NAME}
27+
endif
28+
29+
ifneq (,$(findstring icrosoft,$(shell cat /proc/version)))
30+
THREADS=1
31+
else
32+
THREADS=$(shell nproc)
2733
endif
2834

29-
all: ## Runs everything ###
30-
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)
35+
all: ## Runs everything ####
36+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "####" | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE)
3137

3238
syntax-php: ## Lint PHP syntax
33-
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor ./src ./tests
39+
$(DOCKER_RUN) vendor/bin/parallel-lint --exclude vendor .
3440

35-
cs-fix: ## Fix any automatically fixable code style issues
36-
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(shell nproc) --standard=./etc/qa/phpcs.xml -vvv
41+
cs-fix: ## Fix any automatically fixable code style issues ###
42+
$(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN) vendor/bin/phpcbf --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml -vvvv
3743

3844
cs: ## Check the code for code style issues
39-
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(shell nproc) --standard=./etc/qa/phpcs.xml
45+
$(DOCKER_RUN) vendor/bin/phpcs --parallel=$(THREADS) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml
4046

4147
stan: ## Run static analysis (PHPStan)
4248
$(DOCKER_RUN) vendor/bin/phpstan analyse src tests --level max --ansi -c ./etc/qa/phpstan.neon
4349

4450
psalm: ## Run static analysis (Psalm)
45-
$(DOCKER_RUN) vendor/bin/psalm --threads=$(shell nproc) --shepherd --stats --config=./etc/qa/psalm.xml
51+
$(DOCKER_RUN) vendor/bin/psalm --threads=$(THREADS) --shepherd --stats --config=./etc/qa/psalm.xml
4652

4753
unit-testing: ## Run tests
48-
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml
54+
$(DOCKER_RUN) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
4955
$(DOCKER_RUN) test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
5056

57+
unit-testing-raw: ## Run tests ####
58+
php vendor/phpunit/phpunit/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
59+
test -n "$(COVERALLS_REPO_TOKEN)" && test -n "$(COVERALLS_RUN_LOCALLY)" && test -f ./var/tests-unit-clover-coverage.xml && ./vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
60+
5161
mutation-testing: ## Run mutation testing
52-
$(DOCKER_RUN) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads=$(shell nproc) --ignore-msi-with-no-mutations || (cat ./var/infection.log && false)
62+
$(DOCKER_RUN) vendor/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)
63+
64+
mutation-testing-raw: ## Run mutation testing ####
65+
php vendor/roave/infection-static-analysis-plugin/bin/roave-infection-static-analysis-plugin --ansi --log-verbosity=all --threads=$(THREADS) --psalm-config etc/qa/psalm.xml || (cat ./var/infection.log && false)
66+
67+
composer-require-checker: ## Ensure we require every package used in this package directly
68+
$(DOCKER_RUN) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=./etc/qa/composer-require-checker.json
69+
70+
composer-unused: ## Ensure we don't require any package we don't use in this package directly
71+
$(DOCKER_RUN) vendor/bin/composer-unused --ansi --configuration=./etc/qa/composer-unused.php
72+
73+
composer-install: ## Install dependencies
74+
$(DOCKER_RUN) composer install --no-progress --ansi --no-interaction --prefer-dist -o
5375

5476
backward-compatibility-check: ## Check code for backwards incompatible changes
55-
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check || true
77+
$(MAKE) backward-compatibility-check-raw || true
78+
79+
backward-compatibility-check-raw: ## Check code for backwards incompatible changes, doesn't ignore the failure ###
80+
$(DOCKER_RUN) vendor/bin/roave-backward-compatibility-check
81+
82+
shell: ## Provides Shell access in the expected environment ####
83+
$(DOCKER_RUN) bash
84+
85+
install: ## Install dependencies ####
86+
$(DOCKER_RUN) composer install
87+
88+
update: ## Update dependencies ####
89+
$(DOCKER_RUN) composer update -W
5690

57-
shell: ## Provides Shell access in the expected environment ###
58-
$(DOCKER_RUN) ash
91+
outdated: ## Show outdated dependencies ####
92+
$(DOCKER_RUN) composer outdated
5993

60-
task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands run when running `make (|all)` ###
94+
task-list-ci: ## CI: Generate a JSON array of jobs to run, matches the commands run when running `make (|all)` ####
6195
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | grep -v "###" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | jq --raw-input --slurp -c 'split("\n")| .[0:-1]'
6296

63-
help: ## Show this help ###
97+
help: ## Show this help ####
6498
@printf "\033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
6599
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d '#'
66100

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"openapi-tools/generator-hydrator": "dev-main",
2424
"openapi-tools/generator-schema": "dev-main",
2525
"openapi-tools/generator-templates": "dev-main",
26-
"wyrihaximus/test-utilities": "^5.6"
26+
"wyrihaximus/test-utilities": "^6.0.10"
2727
},
2828
"minimum-stability": "dev",
2929
"prefer-stable": true,

0 commit comments

Comments
 (0)