diff --git a/.github/workflows/test.Dockerfile b/.github/workflows/test.Dockerfile index a7acaf1..f89f0cd 100644 --- a/.github/workflows/test.Dockerfile +++ b/.github/workflows/test.Dockerfile @@ -1,5 +1,7 @@ ARG PHP_VERSION=latest +ARG CODE_COVERAGE=false FROM php:${PHP_VERSION}-cli-alpine +ARG CODE_COVERAGE WORKDIR /workdir @@ -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 + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3834e5..c6b4a1b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,46 +13,61 @@ 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' @@ -60,10 +75,10 @@ jobs: - 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 }} @@ -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 @@ -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' || '' }}' diff --git a/composer.json b/composer.json index 5749337..2ae8e4b 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index bd87684..291742f 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -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 diff --git a/src/EnumMap.php b/src/EnumMap.php index 9aa1b24..eae61ba 100644 --- a/src/EnumMap.php +++ b/src/EnumMap.php @@ -42,7 +42,7 @@ class EnumMap implements ArrayAccess, Countable, IteratorAggregate * @param null|iterable, 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( diff --git a/src/EnumSet.php b/src/EnumSet.php index be3cd07..42e34b3 100644 --- a/src/EnumSet.php +++ b/src/EnumSet.php @@ -86,7 +86,7 @@ class EnumSet implements IteratorAggregate, Countable * @param iterable>|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( diff --git a/tests/MabeEnumTest/EnumSerializableTraitTest.php b/tests/MabeEnumTest/EnumSerializableTraitTest.php index 17da462..5694a3c 100644 --- a/tests/MabeEnumTest/EnumSerializableTraitTest.php +++ b/tests/MabeEnumTest/EnumSerializableTraitTest.php @@ -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, []); } } diff --git a/tests/MabeEnumTest/EnumTest.php b/tests/MabeEnumTest/EnumTest.php index 1d04271..5156fde 100644 --- a/tests/MabeEnumTest/EnumTest.php +++ b/tests/MabeEnumTest/EnumTest.php @@ -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, []); } }