diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1481d90..4c9e1d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,51 +7,59 @@ on: branches: [ main ] jobs: - build: + ci: runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.3', '8.4', '8.5' ] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: - fetch-depth: 0 # To avoid "Shallow clone detected" error in SonarCloud report + fetch-depth: 0 - - name: Validate composer.json and composer.lock - run: composer validate + #~ PHP Setup + - name: Setup PHP ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} - - name: Cache Composer dependencies + #~ Composer Cache + - name: Get Composer Cache Directory id: composer-cache - uses: actions/cache@v3 + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 with: - path: /tmp/composer-cache + path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + #~ Composer install + - name: Validate composer.json + run: composer validate - name: Install dependencies if: steps.composer-cache.outputs.cache-hit != 'true' run: make install + #~ CI part + - name: Dependencies + run: make php/deps + - name: Check Code Style - run: make phpcs + run: make php/check - name: Units Tests - run: make tests + run: make php/tests - name: Fix unit tests report path run: | sed -i 's+'$GITHUB_WORKSPACE'+/github/workspace+g' build/reports/phpunit/clover.xml sed -i 's+'$GITHUB_WORKSPACE'+/github/workspace+g' build/reports/phpunit/unit.xml - - name: PHP 7.4 Compatibility - run: make php74compatibility - - - name: PHP 8.2 Compatibility - run: make php82compatibility - - name: PHP Static Analyze - run: make analyze - - - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@v1.7 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: make php/analyze diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml new file mode 100644 index 0000000..ee46a95 --- /dev/null +++ b/.github/workflows/sonarcloud.yml @@ -0,0 +1,46 @@ +name: SonarQube + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + sonarcloud: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # To avoid "Shallow clone detected" error in SonarCloud report + + #~ PHP Setup + - name: Setup PHP 8.3 # Minimum version + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + + #~ Composer Cache + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Install dependencies + if: steps.composer-cache.outputs.cache-hit != 'true' + run: make install + + - name: Units Tests + run: make php/tests # To generate the coverage report + + - name: SonarQube Scan + uses: SonarSource/sonarqube-scan-action@v7 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..d16dbbd --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,24 @@ +setRules( + [ + '@PER-CS3x0' => true, + ] + ) + + //~ Format + ->setFormat('txt') + + //~ Cache + ->setUsingCache(true) + ->setCacheFile(__DIR__ . '/build/.php-cs-fixer.cache') + + //~ Finder + ->setFinder((new PhpCsFixer\Finder())->in( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ])) +; diff --git a/CHANGELOG.md b/CHANGELOG.md index d4bfd20..dea9e36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ---- +## [2.0.0] - 2026-01-05 +### Added +- PHP 8.5 support +### Removed +- PHP support of versions < 8.3 +### Changed +- Update Makefile +- Update CI configs +- Update dependencies + +---- + ## [1.1.0] - 2023-03-15 ### Changed - Update Makefile diff --git a/Makefile b/Makefile index bdf6201..199be3e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ -.PHONY: validate install update phpcs phpcbf php74compatibility php82compatibility phpstan analyze tests testdox ci clean +.PHONY: validate install update php/deps php/check php/fix php/min-compatibility php/max-compatibility php/phpstan php/analyze php/tests php/test php/testdox ci clean +PHP_MIN_VERSION := "8.3" +PHP_MAX_VERSION := "8.5" +COMPOSER_BIN := composer define header = @if [ -t 1 ]; then printf "\n\e[37m\e[100m \e[104m $(1) \e[0m\n"; else printf "\n### $(1)\n"; fi endef @@ -7,69 +10,71 @@ endef #~ Composer dependency validate: $(call header,Composer Validation) - @composer validate + @${COMPOSER_BIN} validate install: $(call header,Composer Install) - @composer install + @${COMPOSER_BIN} install update: $(call header,Composer Update) - @composer update + @${COMPOSER_BIN} update + @${COMPOSER_BIN} bump --dev-only composer.lock: install #~ Vendor binaries dependencies -vendor/bin/phpcbf: -vendor/bin/phpcs: -vendor/bin/phpstan: -vendor/bin/phpunit: +vendor/bin/php-cs-fixer: composer.lock +vendor/bin/phpstan: composer.lock +vendor/bin/phpunit: composer.lock #~ Report directories dependencies build/reports/phpunit: @mkdir -p build/reports/phpunit -build/reports/phpcs: - @mkdir -p build/reports/cs - build/reports/phpstan: @mkdir -p build/reports/phpstan #~ main commands -phpcs: vendor/bin/phpcs build/reports/phpcs - $(call header,Checking Code Style) - @./vendor/bin/phpcs --standard=./ci/phpcs/eureka.xml --cache=./build/cs_eureka.cache -p --report-full --report-checkstyle=./build/reports/cs/eureka.xml src/ tests/ +php/deps: composer.json + $(call header,Checking Dependencies) + @XDEBUG_MODE=off ./vendor/bin/composer-dependency-analyser --config ./ci/composer-dependency-analyser.php # for shadow, unused required dependencies and ext-* missing dependencies -phpcbf: vendor/bin/phpcbf +php/check: vendor/bin/php-cs-fixer + $(call header,Checking Code Style) + @XDEBUG_MODE=off ./vendor/bin/php-cs-fixer check +php/fix: vendor/bin/php-cs-fixer $(call header,Fixing Code Style) - @./vendor/bin/phpcbf --standard=./ci/phpcs/eureka.xml src/ tests/ + @XDEBUG_MODE=off ./vendor/bin/php-cs-fixer fix -v -php74compatibility: vendor/bin/phpstan build/reports/phpstan - $(call header,Checking PHP 7.4 compatibility) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/php74-compatibility.neon --error-format=table +php/min-compatibility: vendor/bin/phpstan build/reports/phpstan + $(call header,Checking PHP ${PHP_MIN_VERSION} compatibility) + @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/phpmin-compatibility.neon --error-format=table -php82compatibility: vendor/bin/phpstan build/reports/phpstan - $(call header,Checking PHP 8.2 compatibility) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/php82-compatibility.neon --error-format=table +php/max-compatibility: vendor/bin/phpstan build/reports/phpstan #ci + $(call header,Checking PHP ${PHP_MAX_VERSION} compatibility) + @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --configuration=./ci/phpmax-compatibility.neon --error-format=table -analyze: vendor/bin/phpstan build/reports/phpstan +php/analyze: vendor/bin/phpstan build/reports/phpstan #manual & ci $(call header,Running Static Analyze - Pretty tty format) @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --error-format=table -phpstan: vendor/bin/phpstan build/reports/phpstan - $(call header,Running Static Analyze) - @XDEBUG_MODE=off ./vendor/bin/phpstan analyse --error-format=checkstyle > ./build/reports/phpstan/phpstan.xml - -tests: vendor/bin/phpunit build/reports/phpunit +php/tests: vendor/bin/phpunit build/reports/phpunit #ci $(call header,Running Unit Tests) - @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-clover=./build/reports/phpunit/clover.xml --log-junit=./build/reports/phpunit/unit.xml --coverage-php=./build/reports/phpunit/unit.cov --coverage-html=./build/reports/coverage/ --fail-on-warning + @XDEBUG_MODE=coverage php ./vendor/bin/phpunit --testsuite=unit --coverage-clover=./build/reports/phpunit/clover.xml --log-junit=./build/reports/phpunit/unit.xml --coverage-php=./build/reports/phpunit/unit.cov --coverage-html=./build/reports/coverage/ --fail-on-warning + +php/test: php/tests + +php/integration: vendor/bin/phpunit build/reports/phpunit #manual + $(call header,Running Integration Tests) + @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --testsuite=integration --fail-on-warning -testdox: vendor/bin/phpunit $(PHP_FILES) +php/testdox: vendor/bin/phpunit #manual $(call header,Running Unit Tests (Pretty format)) - @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --fail-on-warning --testdox + @XDEBUG_MODE=coverage php -dzend_extension=xdebug.so ./vendor/bin/phpunit --testsuite=unit --fail-on-warning --testdox clean: - $(call header,Cleaning previous build) + $(call header,Cleaning previous build) #manual @if [ "$(shell ls -A ./build)" ]; then rm -rf ./build/*; fi; echo " done" -ci: clean validate install phpcs tests php74compatibility php82compatibility analyze +ci: clean validate install php/deps php/check php/tests php/integration php/min-compatibility php/max-compatibility php/analyze diff --git a/README.md b/README.md index eb37f05..9942551 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # component-template [![Current version](https://img.shields.io/packagist/v/eureka/component-template.svg?logo=composer)](https://packagist.org/packages/eureka/component-template) -[![Supported PHP version](https://img.shields.io/static/v1?logo=php&label=PHP&message=7.4%20-%208.2&color=777bb4)](https://packagist.org/packages/eureka/component-template) +[![Supported PHP version](https://img.shields.io/static/v1?logo=php&label=PHP&message=>%3D8.3&color=777bb4)](https://packagist.org/packages/eureka/component-template) ![CI](https://github.com/eureka-framework/component-template/workflows/CI/badge.svg) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=eureka-framework_component-template&metric=alert_status)](https://sonarcloud.io/dashboard?id=eureka-framework_component-template) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=eureka-framework_component-template&metric=coverage)](https://sonarcloud.io/dashboard?id=eureka-framework_component-template) @@ -53,41 +53,55 @@ NB: For the components, the `composer.lock` file is not committed. ### Testing & CI (Continuous Integration) #### Tests -You can run tests (with coverage) on your side with following command: +You can run unit tests (with coverage) on your side with following command: ```bash -make tests +make php/tests +``` + +You can run integration tests (without coverage) on your side with following command: +```bash +make php/integration ``` For prettier output (but without coverage), you can use the following command: ```bash -make testdox # run tests without coverage reports but with prettified output +make php/testdox # run tests without coverage reports but with prettified output ``` #### Code Style You also can run code style check with following commands: ```bash -make phpcs +make php/check ``` You also can run code style fixes with following commands: ```bash -make phpcbf +make php/fix +``` + +#### Check for missing explicit dependencies +You can check if any explicit dependency is missing with the following command: +```bash +make php/deps ``` #### Static Analysis To perform a static analyze of your code (with phpstan, lvl 9 at default), you can use the following command: ```bash -make analyze +make php/analyse ``` +To ensure you code still compatible with current supported version at Deezer and futures versions of php, you need to +run the following commands (both are required for full support): + Minimal supported version: ```bash -make php74compatibility +make php/min-compatibility ``` Maximal supported version: ```bash -make php82compatibility +make php/max-compatibility ``` #### CI Simulation @@ -96,7 +110,6 @@ And the last "helper" commands, you can run before commit and push, is: make ci ``` - ## License -This project is licensed under the MIT License - see the `LICENSE` file for details +This project is currently under The MIT License (MIT). See [LICENSE](LICENSE) file for more information. diff --git a/ci/composer-dependency-analyser.php b/ci/composer-dependency-analyser.php new file mode 100644 index 0000000..74bb7d1 --- /dev/null +++ b/ci/composer-dependency-analyser.php @@ -0,0 +1,10 @@ +addPathToScan(__DIR__ . '/../src', isDev: false) + ->addPathToScan(__DIR__ . '/../tests', isDev: true) +; diff --git a/ci/php74-compatibility.neon b/ci/php74-compatibility.neon deleted file mode 100644 index 21ac1aa..0000000 --- a/ci/php74-compatibility.neon +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - phpVersion: 70400 # PHP 7.4 - level: 0 - paths: - - ./../src - - ./../tests - - bootstrapFiles: - - ./../vendor/autoload.php diff --git a/ci/php81-compatibility.neon b/ci/php81-compatibility.neon deleted file mode 100644 index 4620509..0000000 --- a/ci/php81-compatibility.neon +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - phpVersion: 80100 # PHP 8.1 - level: 0 - paths: - - ./../src - - ./../tests - - bootstrapFiles: - - ./../vendor/autoload.php diff --git a/ci/php82-compatibility.neon b/ci/php82-compatibility.neon deleted file mode 100644 index 3817a02..0000000 --- a/ci/php82-compatibility.neon +++ /dev/null @@ -1,9 +0,0 @@ -parameters: - phpVersion: 80200 # PHP 8.2 - level: 0 - paths: - - ./../src - - ./../tests - - bootstrapFiles: - - ./../vendor/autoload.php diff --git a/ci/phpcs/eureka.xml b/ci/phpcs/eureka.xml deleted file mode 100644 index b9f405c..0000000 --- a/ci/phpcs/eureka.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - The coding standard for Eureka. - - - - - diff --git a/ci/phpmax-compatibility.neon b/ci/phpmax-compatibility.neon new file mode 100644 index 0000000..162415e --- /dev/null +++ b/ci/phpmax-compatibility.neon @@ -0,0 +1,10 @@ +includes: + - ./../vendor/phpstan/phpstan-phpunit/extension.neon + - ./../vendor/phpstan/phpstan-phpunit/rules.neon + +parameters: + phpVersion: 80500 + level: 0 + paths: + - ./../src + - ./../tests diff --git a/ci/phpmin-compatibility.neon b/ci/phpmin-compatibility.neon new file mode 100644 index 0000000..729fb51 --- /dev/null +++ b/ci/phpmin-compatibility.neon @@ -0,0 +1,10 @@ +includes: + - ./../vendor/phpstan/phpstan-phpunit/extension.neon + - ./../vendor/phpstan/phpstan-phpunit/rules.neon + +parameters: + phpVersion: 80300 + level: 0 + paths: + - ./../src + - ./../tests diff --git a/composer.json b/composer.json index b21a4ac..b9fb1a7 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,17 @@ }, "require": { - "php": "7.4.*||8.0.*||8.1.*||8.2.*" + "php": ">=8.3" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^1.0", - "phpstan/phpstan": "^1.10", - "phpunit/phpcov": "^8.2", - "phpunit/phpunit": "^9.6", - "squizlabs/php_codesniffer": "^3.7" + "friendsofphp/php-cs-fixer": "^3.92.4", + "phpstan/phpstan": "^2.1.33", + "phpstan/phpstan-deprecation-rules": "^2.0.3", + "phpstan/phpstan-phpunit": "^2.0.11", + "phpstan/phpstan-strict-rules": "^2.0.7", + "phpunit/phpcov": "^11.0.3", + "phpunit/phpunit": "^12.5.4", + "shipmonk/composer-dependency-analyser": "^1.8.4" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b383f89..321e2a0 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,12 @@ +includes: + - ./vendor/phpstan/phpstan-phpunit/extension.neon + - ./vendor/phpstan/phpstan-phpunit/rules.neon + - ./vendor/phpstan/phpstan-deprecation-rules/rules.neon + - ./vendor/phpstan/phpstan-strict-rules/rules.neon + - phar://phpstan.phar/conf/bleedingEdge.neon + parameters: - phpVersion: 80100 # PHP 8.1 - Current minimal version supported + phpVersion: 80300 level: max paths: - ./src diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f473078..ea6ec59 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,41 +2,27 @@ + displayDetailsOnTestsThatTriggerDeprecations="true" + cacheDirectory="build/.phpunit.cache" +> - + ./src - + - - ./tests + + ./tests/Unit + + + ./tests/Integration + diff --git a/src/DummySrc.php b/src/DummySrc.php index 2debf36..c4ff85e 100644 --- a/src/DummySrc.php +++ b/src/DummySrc.php @@ -12,10 +12,8 @@ namespace Eureka\Component\Template; /** - * DataMapper Data abstract class. + * Dummy Src code for template * * @author Romain Cottard */ -class DummySrc -{ -} +class DummySrc {} diff --git a/tests/DummyTest.php b/tests/DummyTest.php deleted file mode 100644 index 931a834..0000000 --- a/tests/DummyTest.php +++ /dev/null @@ -1,15 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Integration/.gitkeep b/tests/Integration/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/Unit/.gitkeep b/tests/Unit/.gitkeep new file mode 100644 index 0000000..e69de29