From 0d9d207f3aef04e006d6a6d2e0ee72815f609ca3 Mon Sep 17 00:00:00 2001 From: yoanm Date: Sun, 2 Apr 2023 12:52:38 +0200 Subject: [PATCH] Move CI to GitHub (#24) --- .editorconfig | 16 ++ .gitattributes | 19 ++ .github/.editorconfig | 3 + .github/workflows/CI.yml | 251 ++++++++++++++++++ .remarkignore | 1 + .remarkrc | 6 + .scrutinizer.yml | 176 ++++++------ .travis.yml | 41 --- Makefile | 76 +++--- README.md | 29 +- behat.yml | 35 ++- codecov.yml | 12 + composer.json | 23 +- .../Infra/JsonRpcParamsValidatorTest.php | 12 +- 14 files changed, 509 insertions(+), 191 deletions(-) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/.editorconfig create mode 100644 .github/workflows/CI.yml create mode 100644 .remarkignore create mode 100644 .remarkrc delete mode 100644 .travis.yml create mode 100644 codecov.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ef4466c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,16 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 + +[Makefile] +indent_style = tab +indent_size = 8 + +[{*.yml,*.yaml}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..500a7cf --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# Ignore all test and documentation for archive +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/.editorconfig export-ignore +/codecov.yml export-ignore +/.remarkrc export-ignore +/.remarkignore export-ignore +/behat.yml export-ignore +/phpunit.xml.dist export-ignore +/phpcs.xml.dist export-ignore +/CODE_OF_CONDUCT.md export-ignore +/CONTRIBUTING.md export-ignore +/Makefile export-ignore +/tests export-ignore +/features export-ignore +/docs export-ignore diff --git a/.github/.editorconfig b/.github/.editorconfig new file mode 100644 index 0000000..e3ed7d1 --- /dev/null +++ b/.github/.editorconfig @@ -0,0 +1,3 @@ +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..c706207 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,251 @@ +name: 'CI' +on: # Build any PRs and main branch changes + workflow_dispatch: # Allows to run the workflow manually from the Actions tab + pull_request: + types: + - opened + - edited + - synchronize + push: + branches: [ master ] + schedule: + - cron: '0 0 1 * *' # Every month + +concurrency: + group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}" + cancel-in-progress: true + +env: + TEST_OUTPUT_STYLE: pretty + COMPOSER_OPTIONS: --optimize-autoloader + CODACY_CACHE_PATH: ~/.cache/codacy + CODACY_BIN: ~/.cache/codacy/codacy.sh + +jobs: + tests: + name: UTs & FTs - Symfony ${{ matrix.symfony-version }} + runs-on: ubuntu-latest + env: + COVERAGE_TYPE: none + strategy: + fail-fast: true + max-parallel: 4 + matrix: + include: + # Bare minimum => Lowest versions allowed by composer config + - symfony-version: '4.4' + php-version: '8.0' + composer-flag: --prefer-lowest + # Up to date versions => Latest versions allowed by composer config + - symfony-version: '5.4' + php-version: '8.2' + # Late symfony migration => Lowest symfony version with latest minor php version allowed by composer config + - symfony-version: '4.4' + php-version: '8.2' + composer-flag: --prefer-lowest + # Late php migration => Latest symfony version with lowest minor php version allowed by composer config + - symfony-version: '5.4' + php-version: '8.0' + # Symfony 6.0 latest + - symfony-version: '6.0' + php-version: '8.2' + # Symfony 6.0 lowest + - symfony-version: '6.0' + php-version: '8.0' + composer-flag: --prefer-lowest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Enable coverage + if: ${{ matrix.php-version == '8.2' }} + run: | + echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV + echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php-version }}' + tools: composer + coverage: ${{ env.COVERAGE_TYPE }} + env: + # Always use latest available patch for the version + update: true + + - name: Setup cache + id: cache + uses: actions/cache@v3 + with: + path: | + ~/.composer + ./vendor + ${{ env.CODACY_CACHE_PATH }} + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }} + + - name: Download codacy binary + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ + && chmod +x ${{ env.CODACY_BIN }} \ + && ${{ env.CODACY_BIN }} download + + - name: Build + run: | + SF_VERSION=${{ matrix.symfony-version }} + # Issue with ParamterBag below 4.4.30 => https://github.com/symfony/symfony/commit/3eca446b21607ea1c7a865ece2dd8254c33679cc + test '${{ matrix.symfony-version }}' = '4.4' && test '${{ matrix.php-version }}' = '8.2' && SF_VERSION=4.4.30 + composer require -W ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \ + symfony/validator:^$SF_VERSION \ + && composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \ + && make build + + - name: Tests + run: make test-unit && make test-functional + + # Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false + # And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context + - name: Upload coverages to Codacy + if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-params-symfony-validator-sdk') && env.COVERAGE_TYPE == 'xdebug' }} + run: ${{ env.CODACY_BIN }} report -r build/coverage-phpunit/unit.clover -r build/coverage-behat/clover.xml -r build/coverage-phpunit/functional.clover -t ${{ secrets.CODACY_PROJECT_TOKEN }} --partial + + # See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-params-symfony-validator-sdk + - name: Upload unit tests coverage to codecov + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + uses: codecov/codecov-action@v3 + with: + file: "build/coverage-phpunit/unit.clover" + name: "unit-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}" + flags: "unit-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}" + fail_ci_if_error: true + move_coverage_to_trash: false + verbose: ${{ runner.debug == '1' }} + + - name: Upload functional tests coverage to codecov + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + uses: codecov/codecov-action@v3 + with: + files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover" + name: "functional-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}" + flags: "functional-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}" + fail_ci_if_error: true + move_coverage_to_trash: false + verbose: ${{ runner.debug == '1' }} + + static-checks: + name: Static checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP 8.2 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 # Latest supported + tools: composer + coverage: none + env: + # Always use latest available patch for the version + update: true + + - name: Setup cache + id: cache + uses: actions/cache@v3 + with: + path: | + ~/.composer + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }} + + - name: Build + run: make build + + - name: ComposerRequireChecker + uses: docker://webfactory/composer-require-checker:4.5.0 + + - name: Dependencies check + if: ${{ github.event_name == 'pull_request' }} + uses: actions/dependency-review-action@v1 + + finalize-codacy-coverage-report: + runs-on: ubuntu-latest + name: Finalize Codacy coverage report + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-params-symfony-validator-sdk' }} + needs: [ tests ] + steps: + - name: Setup cache + id: cache + uses: actions/cache@v3 + with: + path: | + ${{ env.CODACY_CACHE_PATH }} + key: codacy-final + + - name: Download codacy binary + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ + && chmod +x ${{ env.CODACY_BIN }} \ + && ${{ env.CODACY_BIN }} download + + - name: Finalize reporting + run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }} + + nightly-tests: + name: Nightly - Symfony ${{ matrix.symfony-version }} + runs-on: ubuntu-latest + env: + COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+' + continue-on-error: true + needs: [ static-checks, tests ] + strategy: + fail-fast: false + max-parallel: 4 + matrix: + php-version: + - '8.3' # Current php dev version + symfony-version: + - '4.4' # Lowest LTS + - '5.4' # Latest LTS + - '6.0' # Current major version + include: + - symfony-version: '6.3' # Next symfony minor version to manage with latest supported PHP version + php-version: '8.2' + + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php-version }}' + tools: composer + coverage: none + env: + # Always use latest available patch for the version + update: true + + - name: Setup cache + id: cache + uses: actions/cache@v3 + with: + path: | + ~/.composer + ./vendor + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ hashFiles('composer.json') }} + + - name: Build + run: | + composer config minimum-stability dev \ + && composer require -W ${{ env.COMPOSER_OPTIONS }} \ + symfony/validator:^${{ matrix.symfony-version }} \ + && composer update ${{ env.COMPOSER_OPTIONS }} \ + && make build + + - name: Test + run: make test-unit && make test-functional diff --git a/.remarkignore b/.remarkignore new file mode 100644 index 0000000..22d0d82 --- /dev/null +++ b/.remarkignore @@ -0,0 +1 @@ +vendor diff --git a/.remarkrc b/.remarkrc new file mode 100644 index 0000000..0527df5 --- /dev/null +++ b/.remarkrc @@ -0,0 +1,6 @@ +{ + "plugins": [ + "remark-preset-lint-consistent", + "remark-preset-lint-recommended" + ] +} diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 2604357..b579dd2 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,88 +1,98 @@ build_failure_conditions: - - 'project.metric_change("scrutinizer.quality", < -0.30)' - - 'elements.rating(<= D).exists' # No classes/methods with a rating of D or worse - - 'issues.severity(>= MAJOR).exists' # New major or higher severity issues - - 'project.metric("scrutinizer.quality", < 9)' # Code Quality Rating drops below 9 - - 'project.metric("scrutinizer.test_coverage", < 1)' # Code Coverage must alway be 100% - - 'patches.label("Doc Comments").exists' # No doc comments patches allowed - - 'patches.label("Spacing").exists' # No spacing patches allowed - - 'patches.label("Bug").exists' # No bug patches allowed - - 'issues.label("coding-style").exists' # No coding style issues allowed + - 'project.metric_change("scrutinizer.quality", < -0.30)' + - 'elements.rating(<= D).exists' # No classes/methods with a rating of D or worse + - 'issues.severity(>= MAJOR).exists' # New major or higher severity issues + - 'project.metric("scrutinizer.quality", < 9)' # Code Quality Rating drops below 9 + - 'project.metric("scrutinizer.test_coverage", < 1)' # Code Coverage must alway be 100% + - 'patches.label("Doc Comments").exists' # No doc comments patches allowed + - 'patches.label("Spacing").exists' # No spacing patches allowed + - 'patches.label("Bug").exists' # No bug patches allowed + - 'issues.label("coding-style").exists' # No coding style issues allowed build: - dependencies: - override: - - make build - tests: - stop_on_failure: true - override: - - - command: make coverage - idle_timeout: 1200 - coverage: - file: 'build/coverage/clover.xml' - format: 'php-clover' - - php-scrutinizer-run --enable-security-analysis - - make codestyle - - composer global require maglnet/composer-require-checker && composer-require-checker check composer.json - cache: - directories: - - ~/.composer - - vendor + dependencies: + override: + - command: make build + title: Build deps + idle_timeout: 240 + tests: + stop_on_failure: true + override: + - command: make codestyle + title: Code style + - command: make scrutinizer-phpunit + idle_timeout: 1200 + coverage: + file: 'build/coverage-phpunit/scrutinizer.xml' + format: 'php-clover' + - command: make scrutinizer-behat + idle_timeout: 1200 + coverage: + file: 'build/coverage-behat/clover.xml' + format: 'php-clover' + - command: php-scrutinizer-run --enable-security-analysis + title: Scrutinizer checks - environment: - variables: - CI: 'true' - TEST_OUTPUT_STYLE: 'pretty' - COMPOSER_OPTIONS: '--optimize-autoloader' - COVERAGE_OUTPUT_STYLE: 'clover' - COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml' - PHPCS_DISABLE_WARNING: "true" - php: - version: "7.3" - timezone: UTC - postgresql: false - redis: false + cache: + directories: + - ~/.composer + - vendor + + environment: + variables: + CI: 'true' + TEST_OUTPUT_STYLE: 'pretty' + COMPOSER_OPTIONS: '--optimize-autoloader' + COVERAGE_OUTPUT_STYLE: 'clover' + COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml' + PHPCS_DISABLE_WARNING: 'true' + php: + version: "8.2" + ini: + memory_limit: "-1" + timezone: UTC + postgresql: false + redis: false filter: - paths: - - src/* + paths: + - src/* checks: - php: - code_rating: true - duplication: true - no_debug_code: true - check_method_contracts: - verify_interface_like_constraints: true - verify_documented_constraints: true - verify_parent_constraints: true - simplify_boolean_return: true - return_doc_comments: true - return_doc_comment_if_not_inferrable: true - remove_extra_empty_lines: true - properties_in_camelcaps: true - phpunit_assertions: true - parameters_in_camelcaps: true - parameter_doc_comments: true - param_doc_comment_if_not_inferrable: true - overriding_parameter: true - no_trailing_whitespace: true - no_short_variable_names: - minimum: '3' - no_short_method_names: - minimum: '3' - no_long_variable_names: - maximum: '20' - no_goto: true - naming_conventions: - local_variable: '^[a-z][a-zA-Z0-9]*$' - abstract_class_name: ^Abstract|Factory$ - utility_class_name: 'Utils?$' - constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$' - property_name: '^[a-z][a-zA-Z0-9]*$' - method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$' - parameter_name: '^[a-z][a-zA-Z0-9]*$' - interface_name: '^[A-Z][a-zA-Z0-9]*Interface$' - type_name: '^[A-Z][a-zA-Z0-9]*$' - exception_name: '^[A-Z][a-zA-Z0-9]*Exception$' - isser_method_name: '^(?:is|has|should|may|supports)' - more_specific_types_in_doc_comments: true - fix_doc_comments: false + php: + code_rating: true + duplication: true + no_debug_code: true + check_method_contracts: + verify_interface_like_constraints: true + verify_documented_constraints: true + verify_parent_constraints: true + simplify_boolean_return: true + return_doc_comments: true + return_doc_comment_if_not_inferrable: true + remove_extra_empty_lines: true + properties_in_camelcaps: true + phpunit_assertions: true + parameters_in_camelcaps: true + parameter_doc_comments: true + param_doc_comment_if_not_inferrable: true + overriding_parameter: true + no_trailing_whitespace: true + no_short_variable_names: + minimum: '3' + no_short_method_names: + minimum: '3' + no_long_variable_names: + maximum: '20' + no_goto: true + naming_conventions: + local_variable: '^[a-z][a-zA-Z0-9]*$' + abstract_class_name: ^Abstract|Factory$ + utility_class_name: 'Utils?$' + constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$' + property_name: '^[a-z][a-zA-Z0-9]*$' + method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$' + parameter_name: '^[a-z][a-zA-Z0-9]*$' + interface_name: '^[A-Z][a-zA-Z0-9]*Interface$' + type_name: '^[A-Z][a-zA-Z0-9]*$' + exception_name: '^[A-Z][a-zA-Z0-9]*Exception$' + isser_method_name: '^(?:is|has|should|may|supports)' + more_specific_types_in_doc_comments: true + fix_doc_comments: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3d5fe81..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ -language: php - -php: - - 7.2 - - 7.3 - - 7.4 - -env: - global: - - CI: 'true' - - TEST_OUTPUT_STYLE: 'pretty' - - PHPCS_REPORT_STYLE: 'full' - - COMPOSER_OPTIONS: '--optimize-autoloader' - jobs: - - SYMFONY_VERSION: '~4.0' - - SYMFONY_VERSION: '~5.0' - -jobs: - fast_finish: true - -before_install: - # remove xdebug to speed up build - - phpenv config-rm xdebug.ini || true - -install: - - composer require symfony/validator:$SYMFONY_VERSION - - make build -script: - - make test-technical - - make test-functional - -cache: - directories: - - $HOME/.composer - - vendor - -branches: - except: - - /.*\-dev$/ - - /.*\-patch(\-\d+)?$/ - - /^dev-.*$/ diff --git a/Makefile b/Makefile index 24c8bd3..fdbc8a1 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ COLOR_ENABLED ?= true TEST_OUTPUT_STYLE ?= dot -COVERAGE_OUTPUT_STYLE ?= html ## DIRECTORY AND FILE BUILD_DIRECTORY ?= build -REPORTS_DIRECTORY ?= ${BUILD_DIRECTORY}/reports -COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage -BEHAT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/behat-coverage -COVERAGE_CLOVER_FILE_PATH ?= ${COVERAGE_DIRECTORY}/clover.xml +REPORTS_DIRECTORY ?= ${BUILD_DIRECTORY}/reports # Codestyle +BEHAT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage-behat +PHPUNIT_COVERAGE_DIRECTORY ?= ${BUILD_DIRECTORY}/coverage-phpunit +PHPUNIT_UNIT_COVERAGE_FILE_PATH ?= ${PHPUNIT_COVERAGE_DIRECTORY}/unit.clover +PHPUNIT_FUNCTIONAL_COVERAGE_FILE_PATH ?= ${PHPUNIT_COVERAGE_DIRECTORY}/functional.clover ## Commands options ### Composer @@ -39,14 +39,21 @@ else BEHAT_OUTPUT_STYLE_OPTION ?= --format progress endif -ifeq ("${COVERAGE_OUTPUT_STYLE}","clover") - PHPUNIT_COVERAGE_OPTION ?= --coverage-clover ${COVERAGE_CLOVER_FILE_PATH} -else +ifdef COVERAGE_OUTPUT_STYLE + export XDEBUG_MODE=coverage ifeq ("${COVERAGE_OUTPUT_STYLE}","html") - PHPUNIT_COVERAGE_OPTION ?= --coverage-html ${COVERAGE_DIRECTORY} - else - PHPUNIT_COVERAGE_OPTION ?= --coverage-text - endif + PHPUNIT_COVERAGE_OPTION ?= --coverage-html ${PHPUNIT_COVERAGE_DIRECTORY} + PHPUNIT_FUNCTIONAL_COVERAGE_OPTION ?= --coverage-html ${PHPUNIT_COVERAGE_DIRECTORY} + BEHAT_COVERAGE_OPTION ?= --profile coverage-html + else ifeq ("${COVERAGE_OUTPUT_STYLE}","clover") + PHPUNIT_COVERAGE_OPTION ?= --coverage-clover ${PHPUNIT_UNIT_COVERAGE_FILE_PATH} + PHPUNIT_FUNCTIONAL_COVERAGE_OPTION ?= --coverage-clover ${PHPUNIT_FUNCTIONAL_COVERAGE_FILE_PATH} + BEHAT_COVERAGE_OPTION ?= --profile coverage-clover + else + PHPUNIT_COVERAGE_OPTION ?= --coverage-text + PHPUNIT_FUNCTIONAL_COVERAGE_OPTION ?= --coverage-text + BEHAT_COVERAGE_OPTION ?= --profile coverage + endif endif ifneq ("${PHPCS_REPORT_FILE}","") @@ -71,39 +78,36 @@ install: configure: # Project tests -test: - make test-functional - make test-technical - make codestyle +test: test-functional test-unit codestyle -test-technical: - ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} --testsuite technical +ifdef PHPUNIT_COVERAGE_OPTION +test-unit: create-build-directories +endif +test-unit: + ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} ${PHPUNIT_COVERAGE_OPTION} --testsuite technical +ifdef BEHAT_COVERAGE_OPTION +test-functional: create-build-directories +else ifdef PHPUNIT_FUNCTIONAL_COVERAGE_OPTION +test-functional: create-build-directories +endif test-functional: - ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} --testsuite functional - ./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets + ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} ${PHPUNIT_FUNCTIONAL_COVERAGE_OPTION} --testsuite functional + ./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} ${BEHAT_COVERAGE_OPTION} --no-snippets -codestyle: create-reports-directory +codestyle: create-build-directories ./vendor/bin/phpcs ${PHPCS_DISABLE_WARNING_OPTION} --standard=phpcs.xml.dist ${PHPCS_COLOR_OPTION} ${PHPCS_REPORT_FILE_OPTION} --report=${PHPCS_REPORT_STYLE} -coverage: create-coverage-directory - ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} ${PHPUNIT_COVERAGE_OPTION} +scrutinizer-phpunit: + XDEBUG_MODE=coverage ./vendor/bin/phpunit ${PHPUNIT_COLOR_OPTION} ${PHPUNIT_OUTPUT_STYLE_OPTION} --coverage-clover build/coverage-phpunit/scrutinizer.xml -behat-coverage: create-behat-coverage-directory - composer required leanphp/behat-code-coverage - ./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --no-snippets --profile coverage +scrutinizer-behat: + XDEBUG_MODE=coverage ./vendor/bin/behat ${BEHAT_COLOR_OPTION} ${BEHAT_OUTPUT_STYLE_OPTION} --profile coverage-clover --no-snippets # Internal commands -create-coverage-directory: - mkdir -p ${COVERAGE_DIRECTORY} - -create-behat-coverage-directory: - mkdir -p ${BEHAT_COVERAGE_DIRECTORY} - -create-reports-directory: - mkdir -p ${REPORTS_DIRECTORY} - +create-build-directories: + mkdir -p ${PHPUNIT_COVERAGE_DIRECTORY} ${BEHAT_COVERAGE_DIRECTORY} ${REPORTS_DIRECTORY} -.PHONY: build install configure test test-technical test-functional codestyle coverage behat-coverage create-coverage-directory create-behat-coverage-directory create-reports-directory +.PHONY: build install configure test test-unit test-functional codestyle create-build-directories scrutinizer-behat scrutinizer-phpunit .DEFAULT: build diff --git a/README.md b/README.md index 9fa2210..619e8f1 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ # JSON-RPC params symfony validator -[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=yoanm/php-jsonrpc-params-symfony-validator-sdk)](https://dependabot.com) +[![License](https://img.shields.io/github/license/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) +[![Code size](https://img.shields.io/github/languages/code-size/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) +[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\&repo=yoanm/php-jsonrpc-params-symfony-validator-sdk)](https://dependabot.com) +[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg?label=Scrutinizer\&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/build-status/master) +[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/?branch=master) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/8f39424add044b43a70bdb238e2f48db)](https://www.codacy.com/gh/yoanm/php-jsonrpc-params-symfony-validator-sdk/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=yoanm/php-jsonrpc-params-symfony-validator-sdk\&utm_campaign=Badge_Grade) -[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-params-symfony-validator-sdk.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-params-symfony-validator-sdk/?branch=master) +[![CI](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/php-jsonrpc-params-symfony-validator-sdk/actions/workflows/CI.yml) +[![codecov](https://codecov.io/gh/yoanm/php-jsonrpc-params-symfony-validator-sdk/branch/master/graph/badge.svg?token=NHdwEBUFK5)](https://codecov.io/gh/yoanm/php-jsonrpc-params-symfony-validator-sdk) +[![Symfony Versions](https://img.shields.io/badge/Symfony-v4.4%20%2F%20v5.4%2F%20v6.x-8892BF.svg?logo=github)](https://symfony.com/) -[![Travis Build Status](https://img.shields.io/travis/com/yoanm/php-jsonrpc-params-symfony-validator-sdk/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/php-jsonrpc-params-symfony-validator-sdk) [![Travis Symfony Versions](https://img.shields.io/badge/Symfony-v4%20%2F%20v5-8892BF.svg?logo=travis)](https://php.net/) +[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk) +[![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk) -[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/jsonrpc-params-symfony-validator-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-params-symfony-validator-sdk) Simple JSON-RPC params validator that use Symfony validator component @@ -16,18 +23,20 @@ See [yoanm/jsonrpc-params-symfony-constraint-doc-sdk](https://github.com/yoanm/p ## Versions -- Symfony v3/4 - PHP >=7.1 : `^v1.0` -- Symfony v4/5 - PHP >=7.2 : `^v2.0` +* Symfony v3/4 - PHP >=7.1 : `^v1.0` +* Symfony v4/5 - PHP >=7.2 : `^v2.0` -⚠️⚠️ `v0.2.0` is replaced by `v1.0.0` ! ⚠️⚠️ + ⚠️⚠️ `v0.2.0` is replaced by `v1.0.0` ! ⚠️⚠️ -⚠️⚠️ `v0.3.0` was badly taggued, used `v2.0.0` instead ! ⚠️⚠️ + ⚠️⚠️ `v0.3.0` was badly taggued, used `v2.0.0` instead ! ⚠️⚠️ + +* Symfony v4.4/5.4/6.0 - PHP ^8.0 : `^v2.1` ## How to use In order to be validated, a JSON-RPC method must : - - Implements `JsonRpcMethodInterface` from [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk) - - Implements [`MethodWithValidatedParamsInterface`](./src/Infra/JsonRpcParamsValidator.php) +* Implements `JsonRpcMethodInterface` from [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk) +* Implements [`MethodWithValidatedParamsInterface`](./src/Infra/JsonRpcParamsValidator.php) ### With [`yoanm/jsonrpc-server-sdk`](https://github.com/yoanm/php-jsonrpc-server-sdk) Create the validator and inject it into request handler : diff --git a/behat.yml b/behat.yml index a417e91..f67f364 100644 --- a/behat.yml +++ b/behat.yml @@ -1,4 +1,11 @@ default: + extensions: + DVDoug\Behat\CodeCoverage\Extension: + filter: + include: + directories: + 'src': ~ + reports: [] # No reports suites: default: contexts: @@ -6,15 +13,19 @@ default: - Tests\Functional\BehatContext\FeatureContext: ~ coverage: extensions: - LeanPHP\Behat\CodeCoverage\Extension: - drivers: - - local - filter: - whitelist: - include: - directories: - 'src': ~ - report: - format: html - options: - target: build/behat-coverage + DVDoug\Behat\CodeCoverage\Extension: + reports: + text: + showColors: true +coverage-html: + extensions: + DVDoug\Behat\CodeCoverage\Extension: + reports: + html: + target: build/coverage-behat +coverage-clover: + extensions: + DVDoug\Behat\CodeCoverage\Extension: + reports: + clover: + target: build/coverage-behat/clover.xml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..ad6143e --- /dev/null +++ b/codecov.yml @@ -0,0 +1,12 @@ +coverage: + range: "80...100" + +flags: + nightly: + joined: false + +comment: + show_carryforward_flags: true + +github_checks: + annotations: true diff --git a/composer.json b/composer.json index 61705fe..4160bdf 100644 --- a/composer.json +++ b/composer.json @@ -31,14 +31,23 @@ "yoanm/jsonrpc-params-symfony-constraint-doc-sdk": "To generate payload documentation from validation constraints" }, "require": { - "php": ">=7.2", - "yoanm/jsonrpc-server-sdk": "^3.0", - "symfony/validator": "^4.0 || ^5.0" + "php": "^8.0", + "symfony/validator": "^4.4 || ^5.4 || ^6.0", + "yoanm/jsonrpc-server-sdk": "^3.0" }, "require-dev": { - "behat/behat": "~3.0", - "squizlabs/php_codesniffer": "3.*", - "phpunit/phpunit": "^7.0 || ^8.0", - "yoanm/php-unit-extended": "^1.0" + "behat/behat": "^3.9.0", + "dvdoug/behat-code-coverage": "^5.0", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.6", + "squizlabs/php_codesniffer": "^3.5", + "yoanm/php-unit-extended": "^2.0" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "phpstan/extension-installer": true + } } } diff --git a/tests/Functional/Infra/JsonRpcParamsValidatorTest.php b/tests/Functional/Infra/JsonRpcParamsValidatorTest.php index 17e706a..2ee8ea4 100644 --- a/tests/Functional/Infra/JsonRpcParamsValidatorTest.php +++ b/tests/Functional/Infra/JsonRpcParamsValidatorTest.php @@ -3,9 +3,11 @@ use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Symfony\Component\Validator\Constraints\Collection; use Symfony\Component\Validator\ConstraintViolationInterface; +use Symfony\Component\Validator\ConstraintViolationList; use Symfony\Component\Validator\Validator\ValidatorInterface; use Yoanm\JsonRpcParamsSymfonyValidator\Domain\MethodWithValidatedParamsInterface; use Yoanm\JsonRpcParamsSymfonyValidator\Infra\JsonRpcParamsValidator; @@ -20,6 +22,8 @@ */ class JsonRpcParamsValidatorTest extends TestCase { + use ProphecyTrait; + /** @var JsonRpcParamsValidator */ private $validator; /** @var ValidatorInterface|ObjectProphecy */ @@ -71,7 +75,7 @@ public function testShouldCallSfValidator() ; $this->sfValidator->validate($paramList, $paramConstraint->reveal()) - ->willReturn([]) + ->willReturn(new ConstraintViolationList()) ->shouldBeCalled() ; @@ -96,7 +100,11 @@ public function testShouldNormalizeViolations() $violation2 = $this->prophesize(ConstraintViolationInterface::class); /** @var ConstraintViolationInterface|ObjectProphecy $violation3 */ $violation3 = $this->prophesize(ConstraintViolationInterface::class); - $sfViolationList = [$violation1->reveal(), $violation2->reveal(), $violation3->reveal()]; + $sfViolationList = new ConstraintViolationList([ + $violation1->reveal(), + $violation2->reveal(), + $violation3->reveal() + ]); $expectedNormalizedErrorList = [ [ 'path' => 'path1', pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy