diff --git a/.editorconfig b/.editorconfig index 5e9a93ea..23e9649e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,5 +13,5 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false -[*.yml] +[{*.yml,*.yaml}] indent_size = 2 diff --git a/.gitignore b/.gitignore index 8f69c401..f23ac935 100644 --- a/.gitignore +++ b/.gitignore @@ -14,10 +14,5 @@ vendor # composer lock files composer.lock -# PHPUnit -.phpunit.result.cache -coverage.html - -# PHP CS Fixer -/.php-cs-fixer.cache -/.php-cs-fixer.php +# local environment variables +/.env.local diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 3cb52f9e..30655446 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -15,6 +15,7 @@ return ConfigBuilder::build() ->setRiskyAllowed(true) ->setParallelConfig(ParallelConfigFactory::detect()) + ->setCacheFile(__DIR__ . '/runtime/cache/.php-cs-fixer.cache') ->setRules([ '@Yiisoft/Core' => true, '@Yiisoft/Core:risky' => true, diff --git a/Makefile b/Makefile index b9500b69..cae56d4a 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,47 @@ -export COMPOSE_PROJECT_NAME=yii-queue +.DEFAULT_GOAL := help -help: ## Display help information - @fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' +PHP_VERSION ?= 8.5 +-include .env.local -build: ## Build an image from a docker-compose file. Params: {{ v=8.1 }}. Default latest PHP 8.1 - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml up -d --build +DOCKER_RUN := docker run --rm -it \ + --init \ + --user $(shell id -u):$(shell id -g) \ + --env YII_INSIDE_CONTAINER=true \ + --env COMPOSER_CACHE_DIR=/app/runtime/cache/composer \ + --env HISTFILE=/app/runtime/.docker_shell_history \ + --workdir /app \ + --volume $(CURDIR):/app \ + ghcr.io/yiisoft-contrib/php-dev:$(PHP_VERSION) -down: ## Stop and remove containers, networks - docker-compose -f tests/docker/docker-compose.yml down +RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_RUN)) -sh: ## Enter the container with the application - docker exec -it queue-php sh +shell: ## Open a shell inside the container. + @if [ -n "$$YII_INSIDE_CONTAINER" ]; then \ + echo "You are already inside a container."; \ + exit 1; \ + fi + $(RUN) bash -test: ## Run tests. Params: {{ v=8.1 }}. Default latest PHP 8.1 - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull queue-php - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php vendor/bin/phpunit --debug - make down +composer: ## Run Composer command: `make composer ARGS=start` + $(RUN) composer $(ARGS) -mutation-test: ## Run mutation tests. Params: {{ v=8.1 }}. Default latest PHP 8.1 - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull queue-php - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered - make down +test: phpunit +phpunit: ## [test] Run PHPUnit tests: `make phpunit ARGS="--filter=TestName"` + $(RUN) ./vendor/bin/phpunit $(ARGS) -coverage: ## Run code coverage. Params: {{ v=8.1 }}. Default latest PHP 8.1 - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php vendor/bin/phpunit --coverage-clover coverage.xml - make down +mutation: infection +infection: ## [infection] Run mutation testing with Infection. + $(RUN) ./vendor/bin/roave-infection-static-analysis-plugin --threads=max --ignore-msi-with-no-mutations --only-covered -static-analyze: ## Run code static analyze. Params: {{ v=8.1 }}. Default latest PHP 8.1 - PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=$(v) - make down +psalm: ## Run Psalm static analysis: `make psalm ARGS="--show-info=true"` + $(RUN) ./vendor/bin/psalm $(if $(ARGS),$(ARGS),--php-version=$(PHP_VERSION)) + +cs-fix: php-cs-fixer +php-cs-fixer: ## [cs-fix] Fix code style with PHP-CS-Fixer: `make php-cs-fixer ARGS="--dry-run"` + $(RUN) ./vendor/bin/php-cs-fixer fix $(ARGS) + +coverage: ## Generate code coverage report in HTML + $(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage + +help: ## This help. + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) diff --git a/composer.json b/composer.json index 340e37d9..2fcd4a17 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,6 @@ "phpunit/phpunit": "^10.5.45", "rector/rector": "^2.0.11", "roave/infection-static-analysis-plugin": "^1.35", - "spatie/phpunit-watcher": "^1.24", "vimeo/psalm": "^5.26.1 || ^6.10", "yiisoft/code-style": "^1.0", "yiisoft/test-support": "^3.0.2", @@ -92,10 +91,5 @@ "composer/package-versions-deprecated": true, "yiisoft/config": false } - }, - "scripts": { - "cs-fix": "php-cs-fixer fix", - "test": "phpunit --testdox --no-interaction", - "test-watch": "phpunit-watcher watch" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7fb6ebad..6f2cb314 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,7 +2,7 @@ diff --git a/runtime/.gitignore b/runtime/.gitignore new file mode 100644 index 00000000..da69449b --- /dev/null +++ b/runtime/.gitignore @@ -0,0 +1,2 @@ +* +.gitignore diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml deleted file mode 100644 index a9547789..00000000 --- a/tests/docker/docker-compose.yml +++ /dev/null @@ -1,13 +0,0 @@ -version: '3.8' - -services: - queue-php: - container_name: yii-queue-php - build: - context: ../.. - dockerfile: tests/docker/php/Dockerfile - args: - PHP_VERSION: ${PHP_VERSION:-8.1} - volumes: - - ../runtime:/app/tests/runtime - - ../..:/app diff --git a/tests/docker/php/Dockerfile b/tests/docker/php/Dockerfile deleted file mode 100644 index cd3e6270..00000000 --- a/tests/docker/php/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -# Important! Do not use this image in production! - -ARG PHP_VERSION -FROM php:${PHP_VERSION}-cli-alpine - -RUN apk add git autoconf g++ make linux-headers && \ - docker-php-ext-install pcntl && \ - pecl install xdebug pcov && \ - docker-php-ext-enable xdebug pcov - -ADD ./tests/docker/php/php.ini /usr/local/etc/php/conf.d/40-custom.ini - -COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer -ENV COMPOSER_ALLOW_SUPERUSER 1 - -WORKDIR /app -RUN git config --global --add safe.directory /app -ENTRYPOINT ["sh", "tests/docker/php/entrypoint.sh"] -CMD ["sleep", "infinity"] diff --git a/tests/docker/php/entrypoint.sh b/tests/docker/php/entrypoint.sh deleted file mode 100755 index 8faba712..00000000 --- a/tests/docker/php/entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -set -eu - -flock tests/runtime/composer-install.lock composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - -php --version -set -x -exec "$@" diff --git a/tests/docker/php/php.ini b/tests/docker/php/php.ini deleted file mode 100644 index 18fdd3e5..00000000 --- a/tests/docker/php/php.ini +++ /dev/null @@ -1,2 +0,0 @@ -opcache.enable=1 -opcache.enable_cli=1