From 7ac2b82dbdb187cca0ed1f9c78c1dddda7132398 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 18 Feb 2026 16:35:22 +0300 Subject: [PATCH 1/6] Refactor development environment --- .editorconfig | 2 +- .gitignore | 8 ----- .php-cs-fixer.dist.php | 1 + Makefile | 55 ++++++++++++++++++++------------- composer.json | 6 ---- docker/.env | 2 ++ docker/.gitignore | 1 + docker/compose.yaml | 15 +++++++++ phpunit.xml.dist | 2 +- psalm.xml | 2 +- runtime/.gitignore | 2 ++ tests/docker/docker-compose.yml | 13 -------- tests/docker/php/Dockerfile | 19 ------------ tests/docker/php/entrypoint.sh | 9 ------ tests/docker/php/php.ini | 2 -- 15 files changed, 57 insertions(+), 82 deletions(-) create mode 100644 docker/.env create mode 100644 docker/.gitignore create mode 100644 docker/compose.yaml create mode 100644 runtime/.gitignore delete mode 100644 tests/docker/docker-compose.yml delete mode 100644 tests/docker/php/Dockerfile delete mode 100755 tests/docker/php/entrypoint.sh delete mode 100644 tests/docker/php/php.ini 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..e3796b81 100644 --- a/.gitignore +++ b/.gitignore @@ -13,11 +13,3 @@ vendor # composer lock files composer.lock - -# PHPUnit -.phpunit.result.cache -coverage.html - -# PHP CS Fixer -/.php-cs-fixer.cache -/.php-cs-fixer.php 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..de7c82a6 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,42 @@ -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/##//' +DOCKER_COMPOSE := docker compose \ + -f docker/compose.yaml \ + --env-file docker/.env \ + $(shell test -f docker/.env.local && echo '--env-file .env.local') +export CONTAINER_USER = $(shell id -u):$(shell id -g) -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 +RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm -i php) -down: ## Stop and remove containers, networks - docker-compose -f tests/docker/docker-compose.yml down +shell: + @if [ -n "$$YII_INSIDE_CONTAINER" ]; then \ + echo "You are already inside a container."; \ + exit 1; \ + fi + $(RUN) bash -sh: ## Enter the container with the application - docker exec -it queue-php sh +composer: ## Run Composer command: `make composer ARGS=start` + $(RUN) composer $(ARGS) -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 +test: phpunit +phpunit: + $(RUN) ./vendor/bin/phpunit $(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 +mutation: infection +infection: + $(RUN) ./vendor/bin/roave-infection-static-analysis-plugin --threads=max --ignore-msi-with-no-mutations --only-covered -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 +psalm: + $(RUN) ./vendor/bin/psalm $(ARGS) -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) +cs-fix: php-cs-fixer +php-cs-fixer: + $(RUN) ./vendor/bin/php-cs-fixer fix $(ARGS) + +coverage: + $(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage make down + +# Output the help for each task, see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +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/docker/.env b/docker/.env new file mode 100644 index 00000000..bfbeb7b4 --- /dev/null +++ b/docker/.env @@ -0,0 +1,2 @@ +# Override locally in gitignored .env.local +PHP_IMAGE_VERSION=8.5 diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 00000000..11ee7581 --- /dev/null +++ b/docker/.gitignore @@ -0,0 +1 @@ +.env.local diff --git a/docker/compose.yaml b/docker/compose.yaml new file mode 100644 index 00000000..46b9f904 --- /dev/null +++ b/docker/compose.yaml @@ -0,0 +1,15 @@ +name: yiisoft-queue + +services: + php: + image: ghcr.io/yiisoft-contrib/php-dev:${PHP_IMAGE_VERSION:?Make sure `PHP_IMAGE_VERSION` is declared in `.env`} + user: ${CONTAINER_USER:-} + environment: + YII_INSIDE_CONTAINER: true + COMPOSER_CACHE_DIR: /app/runtime/cache/composer + HISTFILE: /app/runtime/.docker_shell_history + tty: true + init: true + working_dir: /app + volumes: + - ..:/app 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 From e766525b69aa006480858e3a7850ec433cd1e346 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 18 Feb 2026 16:48:25 +0300 Subject: [PATCH 2/6] fix --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index de7c82a6..3bebf787 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,5 @@ coverage: $(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage make down -# Output the help for each task, see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html help: ## This help. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) From 1e6f2febacc7654c34a660b0b43cb8d306080a8c Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 19 Feb 2026 14:10:20 +0300 Subject: [PATCH 3/6] fix --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3bebf787..fbbfbf8a 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ DOCKER_COMPOSE := docker compose \ -f docker/compose.yaml \ --env-file docker/.env \ - $(shell test -f docker/.env.local && echo '--env-file .env.local') + $(shell test -f docker/.env.local && echo '--env-file docker/.env.local') export CONTAINER_USER = $(shell id -u):$(shell id -g) RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm -i php) From df20f3274e8c9dad5f4447608b87f5d9767e5865 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 19 Feb 2026 14:13:42 +0300 Subject: [PATCH 4/6] comments --- Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fbbfbf8a..8ed3b6da 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ export CONTAINER_USER = $(shell id -u):$(shell id -g) RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm -i php) -shell: +shell: ## Open a shell inside the container. @if [ -n "$$YII_INSIDE_CONTAINER" ]; then \ echo "You are already inside a container."; \ exit 1; \ @@ -19,21 +19,21 @@ composer: ## Run Composer command: `make composer ARGS=start` $(RUN) composer $(ARGS) test: phpunit -phpunit: +phpunit: ## [test] Run PHPUnit tests: `make phpunit ARGS="--filter=TestName"` $(RUN) ./vendor/bin/phpunit $(ARGS) mutation: infection -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 -psalm: +psalm: ## Run Psalm static analysis: `make psalm ARGS="--show-info=true"` $(RUN) ./vendor/bin/psalm $(ARGS) cs-fix: php-cs-fixer -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: +coverage: ## Generate code coverage report in HTML $(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage make down From 3677dc5cc219b6a3ed6b69863c55836e3a82797f Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 19 Feb 2026 14:24:08 +0300 Subject: [PATCH 5/6] rm compose --- docker/.env => .env | 0 .gitignore | 3 +++ Makefile | 20 +++++++++++++------- docker/.gitignore | 1 - docker/compose.yaml | 15 --------------- 5 files changed, 16 insertions(+), 23 deletions(-) rename docker/.env => .env (100%) delete mode 100644 docker/.gitignore delete mode 100644 docker/compose.yaml diff --git a/docker/.env b/.env similarity index 100% rename from docker/.env rename to .env diff --git a/.gitignore b/.gitignore index e3796b81..f23ac935 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ vendor # composer lock files composer.lock + +# local environment variables +/.env.local diff --git a/Makefile b/Makefile index 8ed3b6da..fd3af973 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,19 @@ .DEFAULT_GOAL := help -DOCKER_COMPOSE := docker compose \ - -f docker/compose.yaml \ - --env-file docker/.env \ - $(shell test -f docker/.env.local && echo '--env-file docker/.env.local') -export CONTAINER_USER = $(shell id -u):$(shell id -g) +include .env +-include .env.local -RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_COMPOSE) run --rm -i php) +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_IMAGE_VERSION) + +RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_RUN)) shell: ## Open a shell inside the container. @if [ -n "$$YII_INSIDE_CONTAINER" ]; then \ @@ -35,7 +42,6 @@ php-cs-fixer: ## [cs-fix] Fix code style with PHP-CS-Fixer: `make php-cs-fixer A coverage: ## Generate code coverage report in HTML $(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage - make down help: ## This help. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) diff --git a/docker/.gitignore b/docker/.gitignore deleted file mode 100644 index 11ee7581..00000000 --- a/docker/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.env.local diff --git a/docker/compose.yaml b/docker/compose.yaml deleted file mode 100644 index 46b9f904..00000000 --- a/docker/compose.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: yiisoft-queue - -services: - php: - image: ghcr.io/yiisoft-contrib/php-dev:${PHP_IMAGE_VERSION:?Make sure `PHP_IMAGE_VERSION` is declared in `.env`} - user: ${CONTAINER_USER:-} - environment: - YII_INSIDE_CONTAINER: true - COMPOSER_CACHE_DIR: /app/runtime/cache/composer - HISTFILE: /app/runtime/.docker_shell_history - tty: true - init: true - working_dir: /app - volumes: - - ..:/app From 6b29ac8751a4a08cdc753011d96eab14684dee3c Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 19 Feb 2026 17:47:09 +0300 Subject: [PATCH 6/6] improve --- .env | 2 -- Makefile | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index bfbeb7b4..00000000 --- a/.env +++ /dev/null @@ -1,2 +0,0 @@ -# Override locally in gitignored .env.local -PHP_IMAGE_VERSION=8.5 diff --git a/Makefile b/Makefile index fd3af973..cae56d4a 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .DEFAULT_GOAL := help -include .env +PHP_VERSION ?= 8.5 -include .env.local DOCKER_RUN := docker run --rm -it \ @@ -11,7 +11,7 @@ DOCKER_RUN := docker run --rm -it \ --env HISTFILE=/app/runtime/.docker_shell_history \ --workdir /app \ --volume $(CURDIR):/app \ - ghcr.io/yiisoft-contrib/php-dev:$(PHP_IMAGE_VERSION) + ghcr.io/yiisoft-contrib/php-dev:$(PHP_VERSION) RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_RUN)) @@ -34,7 +34,7 @@ infection: ## [infection] Run mutation testing with Infection. $(RUN) ./vendor/bin/roave-infection-static-analysis-plugin --threads=max --ignore-msi-with-no-mutations --only-covered psalm: ## Run Psalm static analysis: `make psalm ARGS="--show-info=true"` - $(RUN) ./vendor/bin/psalm $(ARGS) + $(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"`