Skip to content

Commit b3b3c9c

Browse files
authored
Merge pull request #160 from marc-mabe/php-8.2-3-4
Fully support PHP 8.2, 8.3 and 8.4
2 parents 3da42cc + 03a4a88 commit b3b3c9c

File tree

8 files changed

+55
-37
lines changed

8 files changed

+55
-37
lines changed

.github/workflows/test.Dockerfile

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
ARG PHP_VERSION=latest
2+
ARG CODE_COVERAGE=false
23
FROM php:${PHP_VERSION}-cli-alpine
4+
ARG CODE_COVERAGE
35

46
WORKDIR /workdir
57

@@ -10,9 +12,10 @@ ENV COMPOSER_HTACCESS_PROTECT=0
1012
ENV COMPOSER_CACHE_DIR=/.composer
1113

1214
# install PHP extension pcov
13-
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
14-
&& mkdir -p /usr/src/php/ext/pcov && curl -fsSL https://pecl.php.net/get/pcov | tar xvz -C /usr/src/php/ext/pcov --strip 1 \
15-
&& docker-php-ext-install pcov \
16-
&& docker-php-ext-enable pcov \
17-
&& rm -Rf /usr/src/php/ext/pcov \
18-
&& apk del --no-cache .build-deps
15+
RUN if [[ "${CODE_COVERAGE}" == "true" ]] ; \
16+
then apk add --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \
17+
&& pecl install xdebug \
18+
&& docker-php-ext-enable xdebug \
19+
&& apk del --no-cache .build-deps ; \
20+
fi
21+

.github/workflows/test.yml

+40-25
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,72 @@ jobs:
1313
strategy:
1414
matrix:
1515
include:
16-
- PHP_VERSION: 7.1
16+
- PHP_VERSION: "7.1"
1717
CODE_COVERAGE: false
1818
RUN_PHPSTAN: false
1919
RUN_PSALM: false
2020
RUN_BENCHMARK: false
21-
- PHP_VERSION: 7.2
22-
CODE_COVERAGE: true
21+
- PHP_VERSION: "7.2"
22+
CODE_COVERAGE: false
2323
RUN_PHPSTAN: false
2424
RUN_PSALM: false
2525
RUN_BENCHMARK: true
26-
- PHP_VERSION: 7.3
27-
CODE_COVERAGE: true
26+
- PHP_VERSION: "7.3"
27+
CODE_COVERAGE: false
2828
RUN_PHPSTAN: false
2929
RUN_PSALM: false
3030
RUN_BENCHMARK: false
31-
- PHP_VERSION: 7.4
32-
CODE_COVERAGE: true
31+
- PHP_VERSION: "7.4"
32+
CODE_COVERAGE: false
3333
RUN_PHPSTAN: true
34-
RUN_PSALM: true
34+
RUN_PSALM: false
3535
RUN_BENCHMARK: false
36-
- PHP_VERSION: 8.0
37-
CODE_COVERAGE: true
36+
- PHP_VERSION: "8.0"
37+
CODE_COVERAGE: false
3838
RUN_PHPSTAN: true
39-
RUN_PSALM: true
39+
RUN_PSALM: false
40+
RUN_BENCHMARK: false
41+
- PHP_VERSION: "8.1"
42+
CODE_COVERAGE: false
43+
RUN_PHPSTAN: false
44+
RUN_PSALM: false
4045
RUN_BENCHMARK: false
41-
- PHP_VERSION: 8.1
46+
- PHP_VERSION: "8.2"
47+
CODE_COVERAGE: false
48+
RUN_PHPSTAN: false
49+
RUN_PSALM: false
50+
RUN_BENCHMARK: true
51+
- PHP_VERSION: "8.3"
4252
CODE_COVERAGE: true
43-
RUN_PHPSTAN: true
53+
RUN_PHPSTAN: false
4454
RUN_PSALM: true
45-
RUN_BENCHMARK: true
55+
RUN_BENCHMARK: false
56+
- PHP_VERSION: "8.4"
57+
CODE_COVERAGE: false
58+
RUN_PHPSTAN: true
59+
RUN_PSALM: false
60+
RUN_BENCHMARK: false
4661

4762
steps:
48-
- uses: actions/checkout@v2
63+
- uses: actions/checkout@v4
4964

5065
- name: Cache Docker Image
5166
id: cache-docker-image
52-
uses: actions/cache@v2
67+
uses: actions/cache@v4
5368
with:
5469
path: /tmp/docker-image.tar
55-
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}
70+
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}
5671

5772
- name: Load Docker Image
5873
if: steps.cache-docker-image.outputs.cache-hit == 'true'
5974
run: docker load --input /tmp/docker-image.tar
6075

6176
- name: Build Docker Image
6277
if: steps.cache-docker-image.outputs.cache-hit != 'true'
63-
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
78+
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' --build-arg 'CODE_COVERAGE=${{ matrix.CODE_COVERAGE }}' .
6479

6580
- name: Cache Composer Cache Files
66-
uses: actions/cache@v2
81+
uses: actions/cache@v4
6782
with:
6883
path: /tmp/composer-cache-files
6984
key: cache-composer-cache-files-${{ matrix.PHP_VERSION }}
@@ -75,12 +90,12 @@ jobs:
7590
if [ "${{ matrix.RUN_PHPSTAN }}" != "true" ]; then composer remove --dev phpstan/phpstan --no-update --no-interaction; fi
7691
if [ "${{ matrix.RUN_PSALM }}" != "true" ]; then composer remove --dev vimeo/psalm --no-update --no-interaction; fi
7792
if [ "${{ matrix.RUN_BENCHMARK }}" != "true" ]; then composer remove --dev phpbench/phpbench --no-update --no-interaction; fi
78-
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v '/tmp/composer-cache-files:/.composer' 'test:${{ matrix.PHP_VERSION }}' composer install --no-interaction --no-progress --prefer-dist ${{ matrix.COMPOSER_EXTRA_ARGS }}
93+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v '/tmp/composer-cache-files:/.composer' 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}' composer install --no-interaction --no-progress --prefer-dist ${{ matrix.COMPOSER_EXTRA_ARGS }}
7994
8095
- name: Run Unit Test
8196
run: |
8297
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
83-
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' -d 'pcov.enabled=1' ./vendor/bin/phpunit --coverage-clover=.clover.xml
98+
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}-xdebug' php -d 'zend.assertions=1' -d 'xdebug.mode=coverage' ./vendor/bin/phpunit --coverage-clover=.clover.xml
8499
else
85100
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
86101
fi
@@ -94,16 +109,16 @@ jobs:
94109

95110
- name: Run PHPStan
96111
if: ${{ matrix.RUN_PHPSTAN }}
97-
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'memory_limit=2G' ./vendor/bin/phpstan analyse --level max src/ tests/
112+
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}' php -d 'memory_limit=2G' ./vendor/bin/phpstan analyse --level max src/ tests/
98113

99114
- name: Run psalm
100115
if: ${{ matrix.RUN_PSALM }}
101-
run: mkdir -p "$HOME/.cache/psalm" && docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v "$HOME/.cache/psalm:/.cache/psalm" 'test:${{ matrix.PHP_VERSION }}' php ./vendor/bin/psalm
116+
run: mkdir -p "$HOME/.cache/psalm" && docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" -v "$HOME/.cache/psalm:/.cache/psalm" 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}' php ./vendor/bin/psalm
102117

103118
- name: Run benchmark
104119
if: ${{ matrix.RUN_BENCHMARK }}
105-
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=-1' ./vendor/bin/phpbench run --no-interaction --revs=1 --retry-threshold=100 --progress=none
120+
run: docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}' php -d 'zend.assertions=-1' ./vendor/bin/phpbench run --no-interaction --revs=1 --retry-threshold=100 --progress=none
106121

107122
- name: Export Docker Image
108123
if: steps.cache-docker-image.outputs.cache-hit != 'true'
109-
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}'
124+
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}'

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"phpbench/phpbench": "^0.16.10 || ^1.0.4",
2525
"phpstan/phpstan": "^1.3.1",
2626
"phpunit/phpunit": "^7.5.20 | ^8.5.22 | ^9.5.11",
27-
"vimeo/psalm": "^4.17.0"
27+
"vimeo/psalm": "^4.17.0 | ^5.26.1"
2828
},
2929
"autoload": {
3030
"psr-4": {

phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ parameters:
77
# EnumSerializableTrait
88
- message: '#Access to private property \$[a-z]+ of parent class MabeEnum\\Enum#'
99
path: %currentWorkingDirectory%/src/EnumSerializableTrait.php
10-
- message: '#Access to an undefined static property MabeEnumTest\\TestAsset\\SerializableEnum::\$instances#'
10+
- message: '#Access to private static property \$instances#'
1111
path: %currentWorkingDirectory%/src/EnumSerializableTrait.php
1212

1313
# Tests

src/EnumMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class EnumMap implements ArrayAccess, Countable, IteratorAggregate
4242
* @param null|iterable<T|null|bool|int|float|string|array<mixed>, mixed> $map Initialize map
4343
* @throws InvalidArgumentException
4444
*/
45-
public function __construct(string $enumeration, iterable $map = null)
45+
public function __construct(string $enumeration, ?iterable $map = null)
4646
{
4747
if (!\is_subclass_of($enumeration, Enum::class)) {
4848
throw new InvalidArgumentException(\sprintf(

src/EnumSet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class EnumSet implements IteratorAggregate, Countable
8686
* @param iterable<T|null|bool|int|float|string|array<mixed>>|null $enumerators iterable list of enumerators initializing the set
8787
* @throws InvalidArgumentException
8888
*/
89-
public function __construct(string $enumeration, iterable $enumerators = null)
89+
public function __construct(string $enumeration, ?iterable $enumerators = null)
9090
{
9191
if (!\is_subclass_of($enumeration, Enum::class)) {
9292
throw new InvalidArgumentException(\sprintf(

tests/MabeEnumTest/EnumSerializableTraitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private function clearEnumeration($enumeration): void
108108
}
109109

110110
foreach ($reflClass->getProperties(ReflectionProperty::IS_STATIC) as $reflProp) {
111-
$reflProp->setAccessible(true);;
111+
$reflProp->setAccessible(true);
112112
$reflProp->setValue(null, []);
113113
}
114114
}

tests/MabeEnumTest/EnumTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function resetStaticEnumProps(): void
4040
$enumPropsRefl = $enumRefl->getProperties(ReflectionProperty::IS_STATIC);
4141
foreach ($enumPropsRefl as $enumPropRefl) {
4242
$enumPropRefl->setAccessible(true);
43-
$enumPropRefl->setValue([]);
43+
$enumPropRefl->setValue(null, []);
4444
}
4545
}
4646

0 commit comments

Comments
 (0)