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/.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/dependabot.yml b/.github/dependabot.yml index b7dd1d2..a5538c7 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,7 @@ version: 2 updates: -- package-ecosystem: composer - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 10 + - package-ecosystem: composer + directory: "/" + schedule: + interval: monthly + open-pull-requests-limit: 10 diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..bdd33bf --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,250 @@ +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: + # Cache params + CACHE_VERSION: 2022061905 # To be able to create a new cache (YYYYMMDDXX) + TEST_OUTPUT_STYLE: pretty + COMPOSER_OPTIONS: --optimize-autoloader + CODACY_CACHE_PATH: ~/.cache/codacy + CODACY_BIN: ~/.cache/codacy/codacy.sh + + +#permissions: +# actions: write # Required to be able to trigger sub CI workflows + +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: + php-version: + - '8.1' # Latest supported + - '8.0' # First php 8 version + - '7.4' # Latest php 7 version + - '7.3' # Lowest supported + symfony-version: + - '4.4' # Lowest LTS + - '5.4' # Latest LTS + exclude: + # Run all symfony version only on Lowest and Latest php versions, run it only one time for others + - php-version: '8.0' + symfony-version: '4.4' + - php-version: '7.4' + symfony-version: '5.4' + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Enable coverage + if: ${{ matrix.php-version == '8.1' }} + 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@v2 + with: + path: | + ~/.composer + ./vendor + ${{ env.CODACY_CACHE_PATH }} + build/behat-code-coverage-cache + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: ${{ env.CACHE_VERSION }}-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ 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: | + composer require -W \ + symfony/http-foundation:^${{ matrix.symfony-version }} \ + symfony/http-kernel:^${{ matrix.symfony-version }} \ + symfony/config:^${{ matrix.symfony-version }} \ + symfony/dependency-injection:^${{ matrix.symfony-version }} \ + symfony/event-dispatcher:^${{ matrix.symfony-version }} \ + symfony/routing:^${{ matrix.symfony-version }} \ + && make build + + - name: Tests + run: make test-unit && make test-functional + + # See the reports at https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server + - 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 + + - 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 + + - name: Upload coverages to Codacy + if: ${{ 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 + + static-checks: + name: Static checks + runs-on: ubuntu-latest + needs: [ tests ] + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP 8.1 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 # 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@v2 + with: + path: | + ~/.composer + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: ${{ env.CACHE_VERSION }}-tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }} + + - name: Build + run: make build + + - name: ComposerRequireChecker + uses: docker://webfactory/composer-require-checker:3.2.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 + needs: [ tests ] + steps: + - name: Setup cache + id: cache + uses: actions/cache@v2 + with: + path: | + ${{ env.CODACY_CACHE_PATH }} + key: ${{ env.CACHE_VERSION }}-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, finalize-codacy-coverage-report ] + strategy: + fail-fast: false + max-parallel: 4 + # Perform tests against: + # - current php dev version with all supported symfony version + # - next Symfony minor version to manage with latest supported php version + matrix: + php-version: + - '8.2' # Current php dev version + symfony-version: + - '4.4' # Lowest LTS + - '5.4' # Latest LTS + include: + - symfony-version: '6.0' # Next symfony minor version to manage with latest supported PHP version + php-version: '8.1' + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - 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@v2 + with: + path: | + ~/.composer + ./vendor + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: ${{ env.CACHE_VERSION }}-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ hashFiles('composer.json') }} + + - name: Build + run: | + composer require -W ${{ env.COMPOSER_OPTIONS }} \ + symfony/http-foundation:^${{ matrix.symfony-version }} \ + symfony/http-kernel:^${{ matrix.symfony-version }} \ + symfony/config:^${{ matrix.symfony-version }} \ + symfony/dependency-injection:^${{ matrix.symfony-version }} \ + symfony/event-dispatcher:^${{ matrix.symfony-version }} \ + symfony/routing:^${{ matrix.symfony-version }} \ + && make build + + - name: Test + run: make test-unit && make test-functional diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 2f16f37..6e1a81c 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,98 +1,97 @@ 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: - - - command: make build - title: Build deps - idle_timeout: 240 - tests: - stop_on_failure: true - override: - - - command: make coverage - title: Coverage - idle_timeout: 1200 - coverage: - file: 'build/coverage/clover.xml' - format: 'php-clover' - - - command: make codestyle - title: Code style - - - command: composer global require maglnet/composer-require-checker && composer-require-checker check composer.json - title: Composer-require-checker - - - command: php-scrutinizer-run --enable-security-analysis - title: Scrutinizer checks + 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 - cache: - directories: - - ~/.composer - - vendor + 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' - php: - version: "7.3" - timezone: UTC - postgresql: false - redis: false + environment: + variables: + CI: 'true' + TEST_OUTPUT_STYLE: 'pretty' + COMPOSER_OPTIONS: '--optimize-autoloader' + COVERAGE_OUTPUT_STYLE: 'clover' + COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml' + php: + version: "8.1" + 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 10076e3..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/http-foundation:$SYMFONY_VERSION symfony/http-kernel:$SYMFONY_VERSION symfony/config:$SYMFONY_VERSION symfony/dependency-injection:$SYMFONY_VERSION symfony/event-dispatcher:$SYMFONY_VERSION symfony/routing:$SYMFONY_VERSION - - make build -script: - - make test-technical - - make test-functional - -cache: - directories: - - $HOME/.composer - - vendor - -branches: - except: - - /.*\-dev$/ - - /^dev-.*$/ - - /.*\-patch(\-\d+)?$/ diff --git a/CHANGELOG-3.1.md b/CHANGELOG-3.1.md new file mode 100644 index 0000000..6d1fcd9 --- /dev/null +++ b/CHANGELOG-3.1.md @@ -0,0 +1,35 @@ +# CHANGELOG for 3.1.x + +## 3.1.0 (2022-06-19) + +### PHP Versions + +* ๐Ÿ—‘๏ธ Drop PHP 7.2 support + +* โœ”๏ธ PHP 7.3 + +* โœ”๏ธ PHP 7.4 + +* ๐Ÿš€ Add PHP 8.0 + +* ๐Ÿš€ Add PHP 8.1 + +* ๐Ÿงช Set PHP 8.2 for nightly + +### Symfony Versions + +* โœ”๏ธ Symfony 4.4 + +* โœ”๏ธ Symfony 5.4 + +* ๐Ÿงช Set Symfony 6.0 for nightly + +### Chore + +* โœ๏ธ Add EditorConfig files + +* :octocat: Move CI from Travis to Github Action + +* ๐Ÿ“Š Configure CodeCov + +* ๐Ÿ”ฌ Configure Codacy 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 b6c62e8..43cbb81 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,18 @@ # Symfony JSON-RPC server -[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=yoanm/symfony-jsonrpc-http-server)](https://dependabot.com) +[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server) +[![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server) +[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=yoanm/symfony-jsonrpc-http-server)](https://dependabot.com) -[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/symfony-jsonrpc-http-server.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/symfony-jsonrpc-http-server/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/symfony-jsonrpc-http-server/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server/?branch=master) +[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/symfony-jsonrpc-http-server.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server/build-status/master) +[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/symfony-jsonrpc-http-server/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server/?branch=master) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/8f39424add044b43a70bdb238e2f48db)](https://www.codacy.com/gh/yoanm/symfony-jsonrpc-http-server/dashboard?utm_source=github.com&utm_medium=referral&utm_content=yoanm/symfony-jsonrpc-http-server&utm_campaign=Badge_Grade) -[![Travis Build Status](https://img.shields.io/travis/com/yoanm/symfony-jsonrpc-http-server/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/symfony-jsonrpc-http-server) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/symfony-jsonrpc-http-server.svg?logo=travis)](https://php.net/) [![Travis Symfony Versions](https://img.shields.io/badge/Symfony-v4%20%2F%20v5-8892BF.svg?logo=travis)](https://php.net/) +[![CI](https://github.com/yoanm/symfony-jsonrpc-http-server/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/symfony-jsonrpc-http-server/actions/workflows/CI.yml) +[![codecov](https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server/branch/master/graph/badge.svg?token=NHdwEBUFK5)](https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server) +[![Symfony Versions](https://img.shields.io/badge/Symfony-v4%20%2F%20v5%20-8892BF.svg?logo=github)](https://symfony.com/) -[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/symfony-jsonrpc-http-server.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/symfony-jsonrpc-http-server.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server) +[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/symfony-jsonrpc-http-server.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server) +[![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/symfony-jsonrpc-http-server.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server) Symfony JSON-RPC HTTP Server to convert an HTTP json-rpc request into HTTP json-rpc response. @@ -17,11 +24,12 @@ See [yoanm/symfony-jsonrpc-http-server-doc](https://github.com/yoanm/symfony-jso ## Versions -- Symfony v3/4 - PHP >=7.1 : `^v2.0` +- Symfony v3/4 - PHP >=7.1 : `^2.0` - โš ๏ธโš ๏ธ `v2.1.0` and `v2.1.1` was badly taggued, used `v3.0.0` instead ! โš ๏ธโš ๏ธ + โš ๏ธโš ๏ธ `v2.1.0` and `v2.1.1` were badly taggued, used `v3.0.0` instead ! โš ๏ธโš ๏ธ -- Symfony v4/5 - PHP >=7.2 : `^v3.0` +- Symfony v4/5 - PHP >=7.2 : `~3.0.0` +- Symfony v4/5 - PHP >=7.3 : `^3.1` ## How to use diff --git a/behat.yml b/behat.yml index 7fae20b..25d85f1 100644 --- a/behat.yml +++ b/behat.yml @@ -1,19 +1,31 @@ default: + extensions: + DVDoug\Behat\CodeCoverage\Extension: + cache: build/behat-code-coverage-cache + filter: + include: + directories: + 'src': ~ + reports: [] # No reports suites: default: contexts: - Tests\Functional\BehatContext\DemoAppContext: ~ 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 512a4b3..e9852d3 100644 --- a/composer.json +++ b/composer.json @@ -30,24 +30,29 @@ "yoanm/symfony-jsonrpc-http-server-doc": "JSON-RPC documentation Bundle" }, "require": { - "php": ">=7.2", - "yoanm/jsonrpc-server-sdk": "^3.0", - "symfony/http-foundation": "^4.0 || ^5.0", - "symfony/http-kernel": "^4.0 || ^5.0", - "symfony/config": "^4.0 || ^5.0", - "symfony/dependency-injection": "^4.0 || ^5.0", - "symfony/event-dispatcher": "^4.0 || ^5.0", + "php": "^7.3 || ^8.0", + "psr/container": "^1.0", + "symfony/config": "^4.4 || ^5.4", + "symfony/dependency-injection": "^4.4 || ^5.4", + "symfony/event-dispatcher": "^4.4 || ^5.4", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0", - "psr/container": "^1.0" + "symfony/http-foundation": "^4.4 || ^5.4", + "symfony/http-kernel": "^4.4 || ^5.4", + "yoanm/jsonrpc-server-sdk": "^3.0" }, "require-dev": { "behat/behat": "~3.0", "squizlabs/php_codesniffer": "3.*", - "phpunit/phpunit": "^7.0 || ^8.0", + "phpunit/phpunit": "^8.0 || ^9.0", "matthiasnoback/symfony-dependency-injection-test": "^3.0 || ^4.0", "matthiasnoback/symfony-config-test": "^3.0 || ^4.0", - "symfony/framework-bundle": "^4.0 || ^5.0", - "symfony/routing": "^4.0 || ^5.0", - "yoanm/php-unit-extended": "~1.0" + "symfony/framework-bundle": "^4.4 || ^5.4", + "symfony/routing": "^4.4 || ^5.4", + "yoanm/php-unit-extended": "~1.0", + "phpspec/prophecy-phpunit": "^2.0", + "dvdoug/behat-code-coverage": "^5.0" + }, + "config": { + "sort-packages": true } } diff --git a/features/bootstrap/AbstractContext.php b/features/bootstrap/AbstractContext.php index ec3a27f..acb2a47 100644 --- a/features/bootstrap/AbstractContext.php +++ b/features/bootstrap/AbstractContext.php @@ -6,6 +6,7 @@ use DemoApp\DefaultKernel; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class AbstractContext implements Context { @@ -23,6 +24,15 @@ public function jsonDecode($encodedData) return $decoded; } + /** + * {@inheritdoc} + */ + protected function configureRoutes(RoutingConfigurator $routes) + { + $confDir = $this->getConfigDir(); + $routes->import($confDir.'/routes'.self::CONFIG_EXTS, 'glob'); + } + /** * @param string $uri * @param string $httpMethod diff --git a/features/demo_app/src/AbstractKernel.php b/features/demo_app/src/AbstractKernel.php index 5848183..01af49c 100644 --- a/features/demo_app/src/AbstractKernel.php +++ b/features/demo_app/src/AbstractKernel.php @@ -2,8 +2,12 @@ namespace DemoApp; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; +use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\Container; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseHttpKernel; +use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; +use Symfony\Component\Routing\RouteCollectionBuilder; abstract class AbstractKernel extends BaseHttpKernel { @@ -13,6 +17,17 @@ abstract class AbstractKernel extends BaseHttpKernel /** @var string|null */ private $customCacheDir = null; + public function registerBundles(): iterable + { + /** @noinspection PhpIncludeInspection */ + $contents = require $this->getConfigDir().'/bundles.php'; + foreach ($contents as $class => $envs) { + if (isset($envs['all']) || isset($envs[$this->environment])) { + yield new $class(); + } + } + } + /** * {@inheritdoc} */ @@ -20,7 +35,7 @@ public function getCacheDir() { // Use a specific cache for each kernels if (null === $this->customCacheDir) { - $this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectory(); + $this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectoryName(); } return $this->customCacheDir; @@ -42,6 +57,30 @@ public function getProjectDir() return realpath(__DIR__.'/../'); } + /** + * @param RouteCollectionBuilder|RoutingConfigurator $routes + */ + protected function configureRoutes($routes) + { + $confDir = $this->getConfigDir(); + if ($routes instanceof RoutingConfigurator) { + $routes->import($confDir . '/routes' . self::CONFIG_EXTS, 'glob'); + } else { + $routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob'); + } + } + + /** + * {@inheritdoc} + */ + protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) + { + $container->setParameter('container.dumper.inline_class_loader', true); + $confDir = $this->getConfigDir(); + $loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob'); + $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); + } + /** * Gets the container class. * @@ -50,8 +89,9 @@ public function getProjectDir() protected function getContainerClass() { // In order to avoid collisions between kernels use a dedicated name - return parent::getContainerClass().Container::camelize($this->getConfigDirectory()); + return parent::getContainerClass().Container::camelize($this->getConfigDirectoryName()); } - abstract public function getConfigDirectory() : string; + abstract public function getConfigDirectoryName() : string; + abstract public function getConfigDir(): string; } diff --git a/features/demo_app/src/DefaultKernel.php b/features/demo_app/src/DefaultKernel.php index 8d505a1..de495b7 100644 --- a/features/demo_app/src/DefaultKernel.php +++ b/features/demo_app/src/DefaultKernel.php @@ -1,48 +1,18 @@ getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php'; - foreach ($contents as $class => $envs) { - if (isset($envs['all']) || isset($envs[$this->environment])) { - yield new $class(); - } - } - } - /** * {@inheritdoc} */ - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) + public function getConfigDirectoryName() : string { - $container->setParameter('container.dumper.inline_class_loader', true); - $confDir = $this->getProjectDir().'/'.$this->getConfigDirectory(); - $loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob'); - $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); - } - - /** - * {@inheritdoc} - */ - protected function configureRoutes(RouteCollectionBuilder $routes) - { - $confDir = $this->getProjectDir().'/'.$this->getConfigDirectory(); - $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); + return 'default_config'; } - /** - * {@inheritdoc} - */ - public function getConfigDirectory() : string + public function getConfigDir(): string { - return 'default_config'; + return $this->getProjectDir().'/'.$this->getConfigDirectoryName(); } } diff --git a/features/demo_app/src/KernelWithMappingCollectorListener.php b/features/demo_app/src/KernelWithMappingCollectorListener.php index 17914ab..50118b5 100644 --- a/features/demo_app/src/KernelWithMappingCollectorListener.php +++ b/features/demo_app/src/KernelWithMappingCollectorListener.php @@ -1,48 +1,18 @@ getProjectDir().'/'.$this->getConfigDirectory().'/bundles.php'; - foreach ($contents as $class => $envs) { - if (isset($envs['all']) || isset($envs[$this->environment])) { - yield new $class(); - } - } - } - /** * {@inheritdoc} */ - protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader) + public function getConfigDirectoryName() : string { - $container->setParameter('container.dumper.inline_class_loader', true); - $confDir = $this->getProjectDir().'/'.$this->getConfigDirectory(); - $loader->load($confDir.'/config'.self::CONFIG_EXTS, 'glob'); - $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob'); - } - - /** - * {@inheritdoc} - */ - protected function configureRoutes(RouteCollectionBuilder $routes) - { - $confDir = $this->getProjectDir().'/'.$this->getConfigDirectory(); - $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob'); + return 'mapping_collector_config'; } - /** - * {@inheritdoc} - */ - public function getConfigDirectory() : string + public function getConfigDir(): string { - return 'mapping_collector_config'; + return $this->getProjectDir().'/'.$this->getConfigDirectoryName(); } } diff --git a/tests/Functional/DependencyInjection/ConfigFilesTest.php b/tests/Functional/DependencyInjection/ConfigFilesTest.php index 5615711..0f982f9 100644 --- a/tests/Functional/DependencyInjection/ConfigFilesTest.php +++ b/tests/Functional/DependencyInjection/ConfigFilesTest.php @@ -20,6 +20,7 @@ /** * /!\ This test class does not cover JsonRpcHttpServerExtension, it covers yaml configuration files * => So no [at]covers tag ! + * @coversNothing */ class ConfigFilesTest extends AbstractTestClass { diff --git a/tests/Functional/Dispatcher/SymfonyJsonRpcServerDispatcherTest.php b/tests/Functional/Dispatcher/SymfonyJsonRpcServerDispatcherTest.php index 0bb3a93..1e6382c 100644 --- a/tests/Functional/Dispatcher/SymfonyJsonRpcServerDispatcherTest.php +++ b/tests/Functional/Dispatcher/SymfonyJsonRpcServerDispatcherTest.php @@ -1,8 +1,9 @@