Skip to content

Commit

Permalink
Merge pull request #160 from marc-mabe/php-8.2-3-4
Browse files Browse the repository at this point in the history
Fully support PHP 8.2, 8.3 and 8.4
  • Loading branch information
marc-mabe authored Nov 27, 2024
2 parents 3da42cc + 03a4a88 commit b3b3c9c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 37 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ARG PHP_VERSION=latest
ARG CODE_COVERAGE=false
FROM php:${PHP_VERSION}-cli-alpine
ARG CODE_COVERAGE

WORKDIR /workdir

Expand All @@ -10,9 +12,10 @@ ENV COMPOSER_HTACCESS_PROTECT=0
ENV COMPOSER_CACHE_DIR=/.composer

# install PHP extension pcov
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& 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 \
&& docker-php-ext-install pcov \
&& docker-php-ext-enable pcov \
&& rm -Rf /usr/src/php/ext/pcov \
&& apk del --no-cache .build-deps
RUN if [[ "${CODE_COVERAGE}" == "true" ]] ; \
then apk add --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apk del --no-cache .build-deps ; \
fi

65 changes: 40 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,72 @@ jobs:
strategy:
matrix:
include:
- PHP_VERSION: 7.1
- PHP_VERSION: "7.1"
CODE_COVERAGE: false
RUN_PHPSTAN: false
RUN_PSALM: false
RUN_BENCHMARK: false
- PHP_VERSION: 7.2
CODE_COVERAGE: true
- PHP_VERSION: "7.2"
CODE_COVERAGE: false
RUN_PHPSTAN: false
RUN_PSALM: false
RUN_BENCHMARK: true
- PHP_VERSION: 7.3
CODE_COVERAGE: true
- PHP_VERSION: "7.3"
CODE_COVERAGE: false
RUN_PHPSTAN: false
RUN_PSALM: false
RUN_BENCHMARK: false
- PHP_VERSION: 7.4
CODE_COVERAGE: true
- PHP_VERSION: "7.4"
CODE_COVERAGE: false
RUN_PHPSTAN: true
RUN_PSALM: true
RUN_PSALM: false
RUN_BENCHMARK: false
- PHP_VERSION: 8.0
CODE_COVERAGE: true
- PHP_VERSION: "8.0"
CODE_COVERAGE: false
RUN_PHPSTAN: true
RUN_PSALM: true
RUN_PSALM: false
RUN_BENCHMARK: false
- PHP_VERSION: "8.1"
CODE_COVERAGE: false
RUN_PHPSTAN: false
RUN_PSALM: false
RUN_BENCHMARK: false
- PHP_VERSION: 8.1
- PHP_VERSION: "8.2"
CODE_COVERAGE: false
RUN_PHPSTAN: false
RUN_PSALM: false
RUN_BENCHMARK: true
- PHP_VERSION: "8.3"
CODE_COVERAGE: true
RUN_PHPSTAN: true
RUN_PHPSTAN: false
RUN_PSALM: true
RUN_BENCHMARK: true
RUN_BENCHMARK: false
- PHP_VERSION: "8.4"
CODE_COVERAGE: false
RUN_PHPSTAN: true
RUN_PSALM: false
RUN_BENCHMARK: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache Docker Image
id: cache-docker-image
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: /tmp/docker-image.tar
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}
key: cache-docker-image-test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}

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

- name: Build Docker Image
if: steps.cache-docker-image.outputs.cache-hit != 'true'
run: docker build -f .github/workflows/test.Dockerfile -t 'test:${{ matrix.PHP_VERSION }}' --build-arg 'PHP_VERSION=${{ matrix.PHP_VERSION }}' .
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 }}' .

- name: Cache Composer Cache Files
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: /tmp/composer-cache-files
key: cache-composer-cache-files-${{ matrix.PHP_VERSION }}
Expand All @@ -75,12 +90,12 @@ jobs:
if [ "${{ matrix.RUN_PHPSTAN }}" != "true" ]; then composer remove --dev phpstan/phpstan --no-update --no-interaction; fi
if [ "${{ matrix.RUN_PSALM }}" != "true" ]; then composer remove --dev vimeo/psalm --no-update --no-interaction; fi
if [ "${{ matrix.RUN_BENCHMARK }}" != "true" ]; then composer remove --dev phpbench/phpbench --no-update --no-interaction; fi
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 }}
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 }}
- name: Run Unit Test
run: |
if [ "${{ matrix.CODE_COVERAGE }}" == "true" ]; then
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
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
else
docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workdir" 'test:${{ matrix.PHP_VERSION }}' php -d 'zend.assertions=1' ./vendor/bin/phpunit
fi
Expand All @@ -94,16 +109,16 @@ jobs:

- name: Run PHPStan
if: ${{ matrix.RUN_PHPSTAN }}
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/
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/

- name: Run psalm
if: ${{ matrix.RUN_PSALM }}
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
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

- name: Run benchmark
if: ${{ matrix.RUN_BENCHMARK }}
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
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

- name: Export Docker Image
if: steps.cache-docker-image.outputs.cache-hit != 'true'
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}'
run: docker save --output /tmp/docker-image.tar 'test:${{ matrix.PHP_VERSION }}${{ matrix.CODE_COVERAGE && '-xdebug' || '' }}'
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpbench/phpbench": "^0.16.10 || ^1.0.4",
"phpstan/phpstan": "^1.3.1",
"phpunit/phpunit": "^7.5.20 | ^8.5.22 | ^9.5.11",
"vimeo/psalm": "^4.17.0"
"vimeo/psalm": "^4.17.0 | ^5.26.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ parameters:
# EnumSerializableTrait
- message: '#Access to private property \$[a-z]+ of parent class MabeEnum\\Enum#'
path: %currentWorkingDirectory%/src/EnumSerializableTrait.php
- message: '#Access to an undefined static property MabeEnumTest\\TestAsset\\SerializableEnum::\$instances#'
- message: '#Access to private static property \$instances#'
path: %currentWorkingDirectory%/src/EnumSerializableTrait.php

# Tests
Expand Down
2 changes: 1 addition & 1 deletion src/EnumMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EnumMap implements ArrayAccess, Countable, IteratorAggregate
* @param null|iterable<T|null|bool|int|float|string|array<mixed>, mixed> $map Initialize map
* @throws InvalidArgumentException
*/
public function __construct(string $enumeration, iterable $map = null)
public function __construct(string $enumeration, ?iterable $map = null)
{
if (!\is_subclass_of($enumeration, Enum::class)) {
throw new InvalidArgumentException(\sprintf(
Expand Down
2 changes: 1 addition & 1 deletion src/EnumSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EnumSet implements IteratorAggregate, Countable
* @param iterable<T|null|bool|int|float|string|array<mixed>>|null $enumerators iterable list of enumerators initializing the set
* @throws InvalidArgumentException
*/
public function __construct(string $enumeration, iterable $enumerators = null)
public function __construct(string $enumeration, ?iterable $enumerators = null)
{
if (!\is_subclass_of($enumeration, Enum::class)) {
throw new InvalidArgumentException(\sprintf(
Expand Down
2 changes: 1 addition & 1 deletion tests/MabeEnumTest/EnumSerializableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function clearEnumeration($enumeration): void
}

foreach ($reflClass->getProperties(ReflectionProperty::IS_STATIC) as $reflProp) {
$reflProp->setAccessible(true);;
$reflProp->setAccessible(true);
$reflProp->setValue(null, []);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MabeEnumTest/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function resetStaticEnumProps(): void
$enumPropsRefl = $enumRefl->getProperties(ReflectionProperty::IS_STATIC);
foreach ($enumPropsRefl as $enumPropRefl) {
$enumPropRefl->setAccessible(true);
$enumPropRefl->setValue([]);
$enumPropRefl->setValue(null, []);
}
}

Expand Down

0 comments on commit b3b3c9c

Please sign in to comment.