Skip to content

Commit 6a69c56

Browse files
authored
Refactor development environment (#260)
1 parent 4508fbe commit 6a69c56

12 files changed

Lines changed: 47 additions & 82 deletions

File tree

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ trim_trailing_whitespace = true
1313
[*.md]
1414
trim_trailing_whitespace = false
1515

16-
[*.yml]
16+
[{*.yml,*.yaml}]
1717
indent_size = 2

.gitignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,5 @@ vendor
1414
# composer lock files
1515
composer.lock
1616

17-
# PHPUnit
18-
.phpunit.result.cache
19-
coverage.html
20-
21-
# PHP CS Fixer
22-
/.php-cs-fixer.cache
23-
/.php-cs-fixer.php
17+
# local environment variables
18+
/.env.local

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
return ConfigBuilder::build()
1616
->setRiskyAllowed(true)
1717
->setParallelConfig(ParallelConfigFactory::detect())
18+
->setCacheFile(__DIR__ . '/runtime/cache/.php-cs-fixer.cache')
1819
->setRules([
1920
'@Yiisoft/Core' => true,
2021
'@Yiisoft/Core:risky' => true,

Makefile

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,47 @@
1-
export COMPOSE_PROJECT_NAME=yii-queue
1+
.DEFAULT_GOAL := help
22

3-
help: ## Display help information
4-
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
3+
PHP_VERSION ?= 8.5
4+
-include .env.local
55

6-
build: ## Build an image from a docker-compose file. Params: {{ v=8.1 }}. Default latest PHP 8.1
7-
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml up -d --build
6+
DOCKER_RUN := docker run --rm -it \
7+
--init \
8+
--user $(shell id -u):$(shell id -g) \
9+
--env YII_INSIDE_CONTAINER=true \
10+
--env COMPOSER_CACHE_DIR=/app/runtime/cache/composer \
11+
--env HISTFILE=/app/runtime/.docker_shell_history \
12+
--workdir /app \
13+
--volume $(CURDIR):/app \
14+
ghcr.io/yiisoft-contrib/php-dev:$(PHP_VERSION)
815

9-
down: ## Stop and remove containers, networks
10-
docker-compose -f tests/docker/docker-compose.yml down
16+
RUN := $(if $(YII_INSIDE_CONTAINER),,$(DOCKER_RUN))
1117

12-
sh: ## Enter the container with the application
13-
docker exec -it queue-php sh
18+
shell: ## Open a shell inside the container.
19+
@if [ -n "$$YII_INSIDE_CONTAINER" ]; then \
20+
echo "You are already inside a container."; \
21+
exit 1; \
22+
fi
23+
$(RUN) bash
1424

15-
test: ## Run tests. Params: {{ v=8.1 }}. Default latest PHP 8.1
16-
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull queue-php
17-
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php vendor/bin/phpunit --debug
18-
make down
25+
composer: ## Run Composer command: `make composer ARGS=start`
26+
$(RUN) composer $(ARGS)
1927

20-
mutation-test: ## Run mutation tests. Params: {{ v=8.1 }}. Default latest PHP 8.1
21-
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull queue-php
22-
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
23-
make down
28+
test: phpunit
29+
phpunit: ## [test] Run PHPUnit tests: `make phpunit ARGS="--filter=TestName"`
30+
$(RUN) ./vendor/bin/phpunit $(ARGS)
2431

25-
coverage: ## Run code coverage. Params: {{ v=8.1 }}. Default latest PHP 8.1
26-
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run queue-php vendor/bin/phpunit --coverage-clover coverage.xml
27-
make down
32+
mutation: infection
33+
infection: ## [infection] Run mutation testing with Infection.
34+
$(RUN) ./vendor/bin/roave-infection-static-analysis-plugin --threads=max --ignore-msi-with-no-mutations --only-covered
2835

29-
static-analyze: ## Run code static analyze. Params: {{ v=8.1 }}. Default latest PHP 8.1
30-
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)
31-
make down
36+
psalm: ## Run Psalm static analysis: `make psalm ARGS="--show-info=true"`
37+
$(RUN) ./vendor/bin/psalm $(if $(ARGS),$(ARGS),--php-version=$(PHP_VERSION))
38+
39+
cs-fix: php-cs-fixer
40+
php-cs-fixer: ## [cs-fix] Fix code style with PHP-CS-Fixer: `make php-cs-fixer ARGS="--dry-run"`
41+
$(RUN) ./vendor/bin/php-cs-fixer fix $(ARGS)
42+
43+
coverage: ## Generate code coverage report in HTML
44+
$(RUN) ./vendor/bin/phpunit --coverage-html=runtime/coverage
45+
46+
help: ## This help.
47+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

composer.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"phpunit/phpunit": "^10.5.45",
5454
"rector/rector": "^2.0.11",
5555
"roave/infection-static-analysis-plugin": "^1.35",
56-
"spatie/phpunit-watcher": "^1.24",
5756
"vimeo/psalm": "^5.26.1 || ^6.10",
5857
"yiisoft/code-style": "^1.0",
5958
"yiisoft/test-support": "^3.0.2",
@@ -92,10 +91,5 @@
9291
"composer/package-versions-deprecated": true,
9392
"yiisoft/config": false
9493
}
95-
},
96-
"scripts": {
97-
"cs-fix": "php-cs-fixer fix",
98-
"test": "phpunit --testdox --no-interaction",
99-
"test-watch": "phpunit-watcher watch"
10094
}
10195
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
bootstrap="vendor/autoload.php"
5-
cacheDirectory="vendor/.phpunit.cache"
5+
cacheDirectory="runtime/cache/phpunit"
66
requireCoverageMetadata="false"
77
beStrictAboutCoverageMetadata="true"
88
beStrictAboutOutputDuringTests="true"

psalm.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
88
xmlns="https://getpsalm.org/schema/config"
99
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10-
cacheDirectory="vendor/.psalm-cache"
10+
cacheDirectory="runtime/cache/psalm"
1111
>
1212
<projectFiles>
1313
<directory name="src" />

runtime/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
.gitignore

tests/docker/docker-compose.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/docker/php/Dockerfile

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)