Skip to content

Commit d08d86e

Browse files
committed
Refactored to use php attributes
1 parent 40fac2e commit d08d86e

37 files changed

+476
-348
lines changed

.gitattributes

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,3 @@
66
.gitattributes export-ignore
77
.gitignore export-ignore
88
Makefile export-ignore
9-
phpcs.xml export-ignore
10-
phpstan.neon export-ignore

.github/workflows/ci.yaml

Lines changed: 43 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
extensions: "json"
1717
cache-version: "1"
1818
composer-version: "v2"
19-
composer-install: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable"
19+
composer-options: "--no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable"
2020
coverage: "none"
2121

2222
jobs:
@@ -27,12 +27,12 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
php-version: ["8.1"]
30+
php-version: ["8.1","8.2","8.3"]
3131
operating-system: ["ubuntu-latest"]
3232

3333
steps:
3434
- name: "Checkout"
35-
uses: "actions/checkout@v2"
35+
uses: "actions/checkout@v4"
3636

3737
- name: "Setup PHP cache environment"
3838
id: "extcache"
@@ -43,7 +43,7 @@ jobs:
4343
key: "${{ env.cache-version }}"
4444

4545
- name: "Cache PHP extensions"
46-
uses: "actions/cache@v2"
46+
uses: "actions/cache@v4"
4747
with:
4848
path: "${{ steps.extcache.outputs.dir }}"
4949
key: "${{ steps.extcache.outputs.key }}"
@@ -55,27 +55,17 @@ jobs:
5555
php-version: "${{ matrix.php-version }}"
5656
extensions: "${{ env.extensions }}"
5757
tools: "composer:${{ env.composer-version }}, cs2pr"
58-
coverage: "${{ env.coverage }}"
58+
coverage: "none"
5959

6060
- name: "Setup problem matchers for PHP"
6161
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
6262

63-
- name: "Get Composer cache directory"
64-
id: "composercache"
65-
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
66-
67-
- name: "Cache PHP dependencies"
68-
uses: "actions/cache@v2"
63+
- name: "Setup composer & install dependencies"
64+
uses: "ramsey/composer-install@v2"
6965
with:
70-
path: "${{ steps.composercache.outputs.dir }}"
71-
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
72-
restore-keys: "${{ runner.os }}-composer-"
73-
74-
- name: "Validate Composer"
75-
run: "composer validate"
76-
77-
- name: "Install dependencies"
78-
run: "${{ env.composer-install }}"
66+
dependency-versions: "highest"
67+
composer-options: "${{ env.composer-options }}"
68+
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
7969

8070
- name: "Coding Standard"
8171
run: "make cs"
@@ -87,12 +77,12 @@ jobs:
8777
strategy:
8878
fail-fast: false
8979
matrix:
90-
php-version: ["8.1"]
80+
php-version: ["8.1","8.2","8.3"]
9181
operating-system: ["ubuntu-latest"]
9282

9383
steps:
9484
- name: "Checkout"
95-
uses: "actions/checkout@v2"
85+
uses: "actions/checkout@v4"
9686

9787
- name: "Setup PHP cache environment"
9888
id: "extcache"
@@ -103,7 +93,7 @@ jobs:
10393
key: "${{ env.cache-version }}"
10494

10595
- name: "Cache PHP extensions"
106-
uses: "actions/cache@v2"
96+
uses: "actions/cache@v4"
10797
with:
10898
path: "${{ steps.extcache.outputs.dir }}"
10999
key: "${{ steps.extcache.outputs.key }}"
@@ -120,19 +110,12 @@ jobs:
120110
- name: "Setup problem matchers for PHP"
121111
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
122112

123-
- name: "Get Composer cache directory"
124-
id: "composercache"
125-
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
126-
127-
- name: "Cache PHP dependencies"
128-
uses: "actions/cache@v2"
113+
- name: "Setup composer & install dependencies"
114+
uses: "ramsey/composer-install@v2"
129115
with:
130-
path: "${{ steps.composercache.outputs.dir }}"
131-
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
132-
restore-keys: "${{ runner.os }}-composer-"
133-
134-
- name: "Install dependencies"
135-
run: "${{ env.composer-install }}"
116+
dependency-versions: "highest"
117+
composer-options: "${{ env.composer-options }}"
118+
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
136119

137120
- name: "PHPStan"
138121
run: "make phpstan"
@@ -145,19 +128,12 @@ jobs:
145128
strategy:
146129
fail-fast: false
147130
matrix:
148-
php-version: ["8.1"]
131+
php-version: ["8.1","8.2","8.3"]
149132
operating-system: ["ubuntu-latest"]
150133

151134
steps:
152135
- name: "Checkout"
153-
uses: "actions/checkout@v2"
154-
155-
- name : "Setup MySQL"
156-
uses : "mirromutth/mysql-action@v1.1"
157-
with :
158-
mysql version : "5.7"
159-
mysql database : "testdb"
160-
mysql root password : "root"
136+
uses: "actions/checkout@v4"
161137

162138
- name: "Setup PHP cache environment"
163139
id: "extcache"
@@ -168,7 +144,7 @@ jobs:
168144
key: "${{ env.cache-version }}"
169145

170146
- name: "Cache PHP extensions"
171-
uses: "actions/cache@v2"
147+
uses: "actions/cache@v4"
172148
with:
173149
path: "${{ steps.extcache.outputs.dir }}"
174150
key: "${{ steps.extcache.outputs.key }}"
@@ -185,29 +161,22 @@ jobs:
185161
- name: "Setup problem matchers for PHP"
186162
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
187163

188-
- name: "Get Composer cache directory"
189-
id: "composercache"
190-
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
191-
192-
- name: "Cache PHP dependencies"
193-
uses: "actions/cache@v2"
164+
- name: "Setup composer & install dependencies"
165+
uses: "ramsey/composer-install@v2"
194166
with:
195-
path: "${{ steps.composercache.outputs.dir }}"
196-
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
197-
restore-keys: "${{ runner.os }}-composer-"
198-
199-
- name: "Install dependencies"
200-
run: "${{ env.composer-install }} ${{ matrix.composer-args }}"
167+
dependency-versions: "highest"
168+
composer-options: "${{ env.composer-options }}"
169+
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
201170

202171
- name: "Tests"
203172
run: "make tests"
204173

205-
- name: "Upload test output"
206-
if: ${{ failure() }}
207-
uses: "actions/upload-artifact@v2"
174+
- name: "Upload logs"
175+
uses: "actions/upload-artifact@v4"
208176
with:
209-
name: output
210-
path: tests/**/output
177+
name: "Logs - Tests (${{ matrix.operating-system }}, ${{ matrix.php-version }})"
178+
path: "var/log"
179+
if-no-files-found: "ignore"
211180

212181
tests-code-coverage:
213182
name: "Code tests with code coverage"
@@ -216,22 +185,15 @@ jobs:
216185

217186
strategy:
218187
matrix:
219-
php-version: ["8.1"]
188+
php-version: ["8.1","8.2","8.3"]
220189
operating-system: ["ubuntu-latest"]
221190
fail-fast: false
222191

223192
if: "github.event_name == 'push'"
224193

225194
steps:
226195
- name: "Checkout"
227-
uses: "actions/checkout@v2"
228-
229-
- name : "Setup MySQL"
230-
uses : "mirromutth/mysql-action@v1.1"
231-
with :
232-
mysql version : "5.7"
233-
mysql database : "testdb"
234-
mysql root password : "root"
196+
uses: "actions/checkout@v4"
235197

236198
- name: "Setup PHP cache environment"
237199
id: "extcache"
@@ -242,7 +204,7 @@ jobs:
242204
key: "${{ env.cache-version }}"
243205

244206
- name: "Cache PHP extensions"
245-
uses: "actions/cache@v2"
207+
uses: "actions/cache@v4"
246208
with:
247209
path: "${{ steps.extcache.outputs.dir }}"
248210
key: "${{ steps.extcache.outputs.key }}"
@@ -259,28 +221,21 @@ jobs:
259221
- name: "Setup problem matchers for PHP"
260222
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'
261223

262-
- name: "Get Composer cache directory"
263-
id: "composercache"
264-
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'
265-
266-
- name: "Cache PHP dependencies"
267-
uses: "actions/cache@v2"
224+
- name: "Setup composer & install dependencies"
225+
uses: "ramsey/composer-install@v2"
268226
with:
269-
path: "${{ steps.composercache.outputs.dir }}"
270-
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
271-
restore-keys: "${{ runner.os }}-composer-"
272-
273-
- name: "Install dependencies"
274-
run: "${{ env.composer-install }} ${{ matrix.composer-args }}"
227+
dependency-versions: "highest"
228+
composer-options: "${{ env.composer-options }}"
229+
custom-cache-key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
275230

276231
- name: "Tests"
277-
run: "make coverage"
232+
run: "make coverage-clover"
278233

279234
- name: "Coveralls.io"
280235
env:
281236
CI_NAME: github
282237
CI: true
283-
COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
238+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
284239
run: |
285-
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
286-
php php-coveralls.phar --verbose --config tests/.coveralls.yml
240+
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.3/php-coveralls.phar
241+
php php-coveralls.phar --verbose --config tools/.coveralls.yml

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.idea
2+
/var
23
/vendor
34
/composer.lock
4-
/tests/*/output
5-
/tests/tmp
65
.DS_Store

Makefile

Lines changed: 65 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,74 @@
1-
.PHONY: qa lint cs csf phpstan tests coverage
1+
_: list
22

3-
all:
4-
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
3+
# Config
54

6-
vendor: composer.json composer.lock
7-
composer install
5+
PHPCS_CONFIG=tools/phpcs.xml
6+
PHPSTAN_SRC_CONFIG=tools/phpstan.src.neon
7+
PHPSTAN_TESTS_CONFIG=tools/phpstan.tests.neon
8+
PHPUNIT_CONFIG=tools/phpunit.xml
9+
INFECTION_CONFIG=tools/infection.json
810

9-
qa: lint phpstan cs
11+
# QA
1012

11-
lint: vendor
12-
vendor/bin/parallel-lint --exclude .git --exclude vendor src tests
13+
qa: ## Check code quality - coding style and static analysis
14+
make cs & make phpstan
1315

14-
cs: vendor
15-
vendor/bin/phpcs --standard=phpcs.xml src tests
16+
cs: ## Check PHP files coding style
17+
mkdir -p var/tools/PHP_CodeSniffer
18+
$(PRE_PHP) "vendor/bin/phpcs" src tests --standard=$(PHPCS_CONFIG) --parallel=$(LOGICAL_CORES) $(ARGS)
1619

17-
csf: vendor
18-
vendor/bin/phpcbf --standard=phpcs.xml src tests
20+
csf: ## Fix PHP files coding style
21+
mkdir -p var/tools/PHP_CodeSniffer
22+
$(PRE_PHP) "vendor/bin/phpcbf" src tests --standard=$(PHPCS_CONFIG) --parallel=$(LOGICAL_CORES) $(ARGS)
1923

20-
phpstan: vendor
21-
vendor/bin/phpstan analyse -c phpstan.neon src
24+
lint:
25+
$(PRE_PHP) "vendor/bin/parallel-lint" src tests --exclude .git --exclude vendor
2226

23-
tests: vendor
24-
vendor/bin/tester -s -p php --colors 1 -C tests/cases
27+
phpstan: ## Analyse code with PHPStan
28+
mkdir -p var/tools
29+
$(PRE_PHP) "vendor/bin/phpstan" analyse -c $(PHPSTAN_SRC_CONFIG) $(ARGS)
30+
$(PRE_PHP) "vendor/bin/phpstan" analyse -c $(PHPSTAN_TESTS_CONFIG) $(ARGS)
2531

26-
coverage: vendor
27-
vendor/bin/tester -s -p php --colors 1 -C --coverage ./coverage.xml --coverage-src ./src tests/cases
32+
# Tests
33+
34+
.PHONY: tests
35+
tests: ## Run all tests
36+
$(PRE_PHP) $(PHPUNIT_COMMAND) $(ARGS)
37+
38+
coverage-clover: ## Generate code coverage in XML format
39+
$(PRE_PHP) $(PHPUNIT_COVERAGE) --coverage-clover=var/coverage/clover.xml $(ARGS)
40+
41+
coverage-html: ## Generate code coverage in HTML format
42+
$(PRE_PHP) $(PHPUNIT_COVERAGE) --coverage-html=var/coverage/html $(ARGS)
43+
44+
mutations: ## Check code for mutants
45+
make mutations-tests
46+
make mutations-infection
47+
48+
mutations-tests:
49+
mkdir -p var/coverage
50+
$(PRE_PHP) $(PHPUNIT_COVERAGE) --coverage-xml=var/coverage/xml --log-junit=var/coverage/junit.xml
51+
52+
mutations-infection:
53+
$(PRE_PHP) vendor/bin/infection \
54+
--configuration=$(INFECTION_CONFIG) \
55+
--threads=$(LOGICAL_CORES) \
56+
--coverage=../var/coverage \
57+
--skip-initial-tests \
58+
$(ARGS)
59+
60+
# Utilities
61+
62+
.SILENT: $(shell grep -h -E '^[a-zA-Z_-]+:.*?$$' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?"}; {printf "%s ", $$1}')
63+
64+
LIST_PAD=20
65+
list:
66+
awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\033[0m\n\nTargets:\n"}'
67+
grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort -u | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-$(LIST_PAD)s\033[0m %s\n", $$1, $$2}'
68+
69+
PRE_PHP=XDEBUG_MODE=off
70+
71+
PHPUNIT_COMMAND="vendor/bin/paratest" -c $(PHPUNIT_CONFIG) --runner=WrapperRunner -p$(LOGICAL_CORES)
72+
PHPUNIT_COVERAGE=php -d pcov.enabled=1 -d pcov.directory=./src $(PHPUNIT_COMMAND)
73+
74+
LOGICAL_CORES=$(shell nproc || sysctl -n hw.logicalcpu || echo 4)

0 commit comments

Comments
 (0)