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/dependabot.yml b/.github/dependabot.yml index 24db029..9db6ceb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,10 @@ version: 2 updates: -# -# -# [GHAction] -# Based on https://github.com/yoanm/shared-config/blob/master/GitHub/dependabot/github-action.yml file -# + # + # + # [GHAction] + # Based on https://github.com/yoanm/shared-config/blob/master/GitHub/dependabot/github-action.yml file + # - package-ecosystem: github-actions directory: / schedule: @@ -14,22 +14,22 @@ updates: prefix: '[dependabot][ghaction] - ' # No need to specify prod/dev for GHAction as there is only "production" updates ! include: scope groups: -# Group all basic updates inside the a single PR -# No need to split prod/dev as there is only prod updates + # Group all basic updates inside the a single PR + # No need to split prod/dev as there is only prod updates all-actions: applies-to: version-updates patterns: ['*'] -# Group all security updates inside the a single PR -# No need to split prod/dev as there is only prod updates -# +Most likely no need to split major and other updates either + # Group all security updates inside the a single PR + # No need to split prod/dev as there is only prod updates + # +Most likely no need to split major and other updates either SECURITY-all: applies-to: security-updates patterns: ['*'] -# -# -# [Composer] -# Based on https://github.com/yoanm/shared-config/blob/master/GitHub/dependabot/composer.yml file -# + # + # + # [Composer] + # Based on https://github.com/yoanm/shared-config/blob/master/GitHub/dependabot/composer.yml file + # - package-ecosystem: composer directory: / schedule: # Create PRs during week-ends, they will be ready on monday morning @@ -41,9 +41,9 @@ updates: prefix-development: '[dependabot][dev][composer] - ' include: scope groups: -# Split basic updates by: -# - prod vs dev -# - major vs others (assuming packages properly follow semver !) + # Split basic updates by: + # - prod vs dev + # - major vs others (assuming packages properly follow semver !) prod-majors: applies-to: version-updates dependency-type: production @@ -62,9 +62,9 @@ updates: applies-to: version-updates dependency-type: development patterns: ['*'] -# Split security updates by: -# - prod vs dev -# - Major prod updates vs other prod updates + # Split security updates by: + # - prod vs dev + # - Major prod updates vs other prod updates SECURITY-prod-major: applies-to: security-updates dependency-type: production diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..5797b1a --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,234 @@ +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 + - 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 + +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 + env: + update: true # Always use latest available patch for the version + fail-fast: true # step will fail if an extension or tool fails to set up + with: + php-version: '${{ matrix.php-version }}' + tools: composer + coverage: ${{ env.COVERAGE_TYPE }} + + - name: Setup cache + id: cache + uses: actions/cache@v4 + 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 }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }} + + - 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/config:^$SF_VERSION \ + symfony/dependency-injection:^$SF_VERSION \ + symfony/http-kernel:^$SF_VERSION \ + symfony/event-dispatcher:^$SF_VERSION \ + symfony/framework-bundle:^$SF_VERSION \ + symfony/routing:^$SF_VERSION \ + && composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \ + && make build + + - name: Tests + run: make test-unit && make test-functional + + - name: Create "unit tests" reports group + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + id: unit-tests-coverage-group + uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop + with: + name: unit-tests + format: clover + files: build/coverage-phpunit/unit.clover + flags: | + unit-tests + php-${{ matrix.php-version }} + sf-${{ matrix.symfony-version }} + path: build/coverage-groups + + - name: Create "functional tests" coverage group + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + id: functional-tests-coverage-group + uses: yoanm/temp-reports-group-workspace/.github/actions/create-action@develop + with: + name: functional-tests + format: clover + files: | + build/coverage-phpunit/functional.clover + build/coverage-behat/clover.xml + flags: | + functional-tests + php-${{ matrix.php-version }} + sf-${{ matrix.symfony-version }} + path: build/coverage-groups + + - name: Upload coverage reports + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + uses: actions/upload-artifact@v4 + with: + name: coverage-groups-php${{ matrix.php-version }}-sf${{ matrix.symfony-version }} + path: build/coverage-groups + if-no-files-found: error + + 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 + + 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/config:^${{ matrix.symfony-version }} \ + symfony/dependency-injection:^${{ matrix.symfony-version }} \ + symfony/http-kernel:^${{ matrix.symfony-version }} \ + symfony/event-dispatcher:^${{ matrix.symfony-version }} \ + symfony/framework-bundle:^${{ matrix.symfony-version }} \ + symfony/routing:^${{ 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 2caf798..b579dd2 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,96 +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: - - - command: make build - title: Build deps - 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 - 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' - 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 297ffa5..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-kernel:$SYMFONY_VERSION symfony/dependency-injection:$SYMFONY_VERSION symfony/config:$SYMFONY_VERSION symfony/routing:$SYMFONY_VERSION symfony/event-dispatcher:$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 ef5590e..ae2e317 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,28 @@ # Symfony JSON-RPC Http server swagger documentation -[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc) [![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc) [![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=yoanm/symfony-jsonrpc-http-server-swagger-doc)](https://dependabot.com) -[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/?branch=master) +[![License](https://img.shields.io/github/license/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc) +[![Code size](https://img.shields.io/github/languages/code-size/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc) +[![Dependabot Status](https://api.dependabot.com/badges/status?host=github\&repo=yoanm/symfony-jsonrpc-http-server-swagger-doc)](https://dependabot.com) -[![Travis Build Status](https://img.shields.io/travis/com/yoanm/symfony-jsonrpc-http-server-swagger-doc/master.svg?label=Travis&logo=travis)](https://travis-ci.com/yoanm/symfony-jsonrpc-http-server-swagger-doc) [![Travis Symfony Versions](https://img.shields.io/badge/Symfony-v4%20%2F%20v5-8892BF.svg?logo=travis)](https://symfony.com/) +[![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg?label=Scrutinizer\&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/build-status/master) +[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/symfony-jsonrpc-http-server-swagger-doc/?branch=master) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/e50269d2b7bc465fa43a9f9000bc5f06)](https://app.codacy.com/gh/yoanm/symfony-jsonrpc-http-server-swagger-doc/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) -[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-swagger-doc) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-swagger-doc) +[![CI](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc/actions/workflows/CI.yml) +[![codecov](https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server-swagger-doc/branch/master/graph/badge.svg?token=NHdwEBUFK5)](https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server-swagger-doc) +[![Symfony Versions](https://img.shields.io/badge/Symfony-v4.4%20%2F%20v5.4%2F%20v6.x-8892BF.svg?logo=github)](https://symfony.com/) + +[![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-swagger-doc) +[![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/symfony-jsonrpc-http-server-swagger-doc.svg)](https://packagist.org/packages/yoanm/symfony-jsonrpc-http-server-swagger-doc) Symfony bundle for easy JSON-RPC server Swagger 2.0 documentation Symfony bundle for [yoanm/jsonrpc-http-server-swagger-doc-sdk](https://github.com/yoanm/php-jsonrpc-http-server-swagger-doc-sdk) ## Versions -- Symfony v3/4 - PHP >=7.1 : `^v0.X` -- Symfony v4/5 - PHP >=7.2 : `^v1.0` + +* Symfony v3/4 - PHP >=7.1 : `^v0.X` +* Symfony v4/5 - PHP >=7.2 : `^v1.0` ## How to use @@ -25,30 +34,31 @@ See below how to configure it. [Behat demo app configuration folders](./features/demo_app) can be used as examples. - - Add the bundles in your config/bundles.php file: - ```php - // config/bundles.php - return [ - ... - Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], - Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true], - Yoanm\SymfonyJsonRpcHttpServerDoc\JsonRpcHttpServerDocBundle::class => ['all' => true], - Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\JsonRpcHttpServerSwaggerDocBundle::class => ['all' => true], - ... - ]; - ``` - - - Configure `yoanm/symfony-jsonrpc-http-server` as described on [yoanm/symfony-jsonrpc-http-server](https://github.com/yoanm/symfony-jsonrpc-http-server) documentation. - - - Configure `yoanm/symfony-jsonrpc-http-server-doc` as described on [yoanm/symfony-jsonrpc-http-server-doc](https://github.com/yoanm/symfony-jsonrpc-http-server-doc) documentation. - - - Query your project at `/doc/swagger.json` endpoint and you will have a swagger json documentation file of your server. - +* Add the bundles in your config/bundles.php file: + ```php + // config/bundles.php + return [ + ... + Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], + Yoanm\SymfonyJsonRpcHttpServer\JsonRpcHttpServerBundle::class => ['all' => true], + Yoanm\SymfonyJsonRpcHttpServerDoc\JsonRpcHttpServerDocBundle::class => ['all' => true], + Yoanm\SymfonyJsonRpcHttpServerSwaggerDoc\JsonRpcHttpServerSwaggerDocBundle::class => ['all' => true], + ... + ]; + ``` + +* Configure `yoanm/symfony-jsonrpc-http-server` as described on [yoanm/symfony-jsonrpc-http-server](https://github.com/yoanm/symfony-jsonrpc-http-server) documentation. + +* Configure `yoanm/symfony-jsonrpc-http-server-doc` as described on [yoanm/symfony-jsonrpc-http-server-doc](https://github.com/yoanm/symfony-jsonrpc-http-server-doc) documentation. + +* Query your project at `/doc/swagger.json` endpoint and you will have a swagger json documentation file of your server. + ## Event You are able to enhance resulting documentation by listening on `json_rpc_http_server_swagger_doc.array_created` event. See below an example of listener service configuration: + ```yaml method_doc_created.listener: class: Full\Namespace\DocCreatedListener # <-- replace by your class name @@ -56,11 +66,12 @@ See below an example of listener service configuration: - name: 'kernel.event_listener' event: 'json_rpc_http_server_swagger_doc.array_created' method: 'enhanceMethodDoc' # <-- replace by your method name -``` +``` You will receive an event of type [`SwaggerDocCreatedEvent`](./src/Event/SwaggerDocCreatedEvent.php). You can take example on Behat [`DocCreatedListener`](./features/demo_app/src/Listener/DocCreatedListener.php) ## Contributing + See [contributing note](./CONTRIBUTING.md) diff --git a/behat.yml b/behat.yml index 7fae20b..4244bfa 100644 --- a/behat.yml +++ b/behat.yml @@ -1,19 +1,30 @@ default: + extensions: + DVDoug\Behat\CodeCoverage\Extension: + 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 4ab9a3b..d7cdcc9 100644 --- a/composer.json +++ b/composer.json @@ -6,9 +6,6 @@ "support": { "issues": "https://github.com/yoanm/symfony-jsonrpc-http-server-swagger-doc/issues" }, - "config": { - "sort-packages": true - }, "authors": [ { "name": "Yoanm", @@ -32,24 +29,31 @@ "yoanm/symfony-jsonrpc-http-server": "Symfony Bundle to convert an HTTP json-rpc request into HTTP json-rpc response" }, "require": { - "php": ">=7.2", - "symfony/config": "^4.0 || ^5.0", - "symfony/dependency-injection": "^4.0 || ^5.0", + "php": "^8.0", + "symfony/config": "^4.4 || ^5.4 || ^6.0", + "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0", "symfony/event-dispatcher-contracts": "^1.0 || ^2.0", - "symfony/http-kernel": "^4.0 || ^5.0", - "yoanm/jsonrpc-http-server-swagger-doc-sdk": "^0.2", - "yoanm/jsonrpc-server-doc-sdk": "^0.2", - "yoanm/symfony-jsonrpc-http-server-doc": "^1.0" + "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", + "yoanm/jsonrpc-http-server-swagger-doc-sdk": "^v1.0", + "yoanm/jsonrpc-server-doc-sdk": "^v1.0", + "yoanm/symfony-jsonrpc-http-server-doc": "^1.1" }, "require-dev": { - "behat/behat": "~3.0", - "matthiasnoback/symfony-config-test": "^3.0 || ^4.0", - "matthiasnoback/symfony-dependency-injection-test": "^3.0 || ^4.0", - "phpunit/phpunit": "^7.0 || ^8.0", - "squizlabs/php_codesniffer": "3.*", - "symfony/event-dispatcher": "^4.0 || ^5.0", - "symfony/framework-bundle": "^4.0 || ^5.0", - "symfony/routing": "^4.0 || ^5.0", - "yoanm/php-unit-extended": "~1.0" + "behat/behat": "^3.9.0", + "dvdoug/behat-code-coverage": "^5.0", + "matthiasnoback/symfony-config-test": "^4.0", + "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/php-code-coverage": "^9.2.4", + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "^3.5", + "symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.0", + "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/routing": "^4.4 || ^5.4 || ^6.0", + "yoanm/php-unit-extended": "^2.0.2" + }, + "config": { + "sort-packages": true } } diff --git a/features/bundle.feature b/features/bundle.feature index 0d35d9b..ec32ef4 100644 --- a/features/bundle.feature +++ b/features/bundle.feature @@ -166,7 +166,16 @@ Feature: demo symfony application "required": ["code"], "properties": { "code": {"example": -32603}, - "data": {"type": "object", "x-nullable": true, "properties": {"previous": {"description": "Previous error message", "type": "string", "x-nullable": true}}} + "data": { + "type": "object", + "x-nullable": true, + "properties": { + "_class": {"description": "Exception class", "type": "string", "x-nullable": true}, + "_code":{"description": "Exception code", "type": "integer", "x-nullable": true}, + "_message":{"description": "Exception message", "type": "string", "x-nullable": true}, + "_trace":{"description": "PHP stack trace", "type": "array", "x-nullable": true, "items":{"type": "string"}} + } + } } } ] @@ -252,7 +261,16 @@ Feature: demo symfony application "required": ["code"], "properties": { "code": {"example": -32603}, - "data": {"type": "object", "x-nullable": true, "properties": {"previous": {"description": "Previous error message", "type": "string", "x-nullable": true}}} + "data": { + "type": "object", + "x-nullable": true, + "properties": { + "_class": {"description": "Exception class", "type": "string", "x-nullable": true}, + "_code":{"description": "Exception code", "type": "integer", "x-nullable": true}, + "_message":{"description": "Exception message", "type": "string", "x-nullable": true}, + "_trace":{"description": "PHP stack trace", "type": "array", "x-nullable": true, "items":{"type": "string"}} + } + } } } ] diff --git a/features/demo_app/src/AbstractKernel.php b/features/demo_app/src/AbstractKernel.php index 5848183..09a32fd 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,14 +17,30 @@ 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} */ - public function getCacheDir() + public function getCacheDir(): string { // Use a specific cache for each kernels if (null === $this->customCacheDir) { - $this->customCacheDir = $this->getProjectDir().'/var/cache/'.$this->environment.'/'.$this->getConfigDirectory(); + $this->customCacheDir = sprintf( + '%s/var/cache/%s/%s', + $this->getProjectDir(), + $this->environment, + $this->getConfigDirectoryName() + ); } return $this->customCacheDir; @@ -29,7 +49,7 @@ public function getCacheDir() /** * {@inheritdoc} */ - public function getLogDir() + public function getLogDir(): string { return $this->getProjectDir().'/var/log'; } @@ -37,21 +57,50 @@ public function getLogDir() /** * {@inheritdoc} */ - public function getProjectDir() + public function getProjectDir(): string { return realpath(__DIR__.'/../'); } + public function getConfigDir(): string + { + return $this->getProjectDir().'/'.$this->getConfigDirectoryName(); + } + + /** + * @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. * * @return string The container class */ - protected function getContainerClass() + protected function getContainerClass(): string { // 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; } diff --git a/features/demo_app/src/DefaultKernel.php b/features/demo_app/src/DefaultKernel.php index e93b143..f91f2d0 100644 --- a/features/demo_app/src/DefaultKernel.php +++ b/features/demo_app/src/DefaultKernel.php @@ -1,46 +1,12 @@ 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) - { - $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'); - } - /** * {@inheritdoc} */ - public function getConfigDirectory() : string + public function getConfigDirectoryName() : string { return 'default_config'; } diff --git a/features/demo_app/src/KernelWithDocCreatedListener.php b/features/demo_app/src/KernelWithDocCreatedListener.php index 302d44a..217fd51 100644 --- a/features/demo_app/src/KernelWithDocCreatedListener.php +++ b/features/demo_app/src/KernelWithDocCreatedListener.php @@ -7,40 +7,10 @@ class KernelWithDocCreatedListener extends AbstractKernel { - public function registerBundles(): iterable - { - $contents = require $this->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) - { - $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'); - } - /** * {@inheritdoc} */ - public function getConfigDirectory() : string + public function getConfigDirectoryName() : string { return 'config_with_doc_created_listener'; } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e85eeb9..0b44794 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,8 +1,7 @@ - - - - - - - - tests/Functional - - - tests/Technical - - - - - - src - - + + + src + + + + + + + + tests/Functional + + + tests/Technical + + diff --git a/tests/Functional/DependencyInjection/ConfigFilesTest.php b/tests/Functional/DependencyInjection/ConfigFilesTest.php index cac67bc..639d158 100644 --- a/tests/Functional/DependencyInjection/ConfigFilesTest.php +++ b/tests/Functional/DependencyInjection/ConfigFilesTest.php @@ -19,6 +19,7 @@ /** * /!\ This test class does not cover JsonRpcHttpServerDocExtension, it covers yaml configuration files * => So no [at]covers tag ! + * @coversNothing */ class ConfigFilesTest extends AbstractTestClass { diff --git a/tests/Functional/Event/SwaggerDocCreatedEventTest.php b/tests/Functional/Event/SwaggerDocCreatedEventTest.php index 2d34afa..3cd4e66 100644 --- a/tests/Functional/Event/SwaggerDocCreatedEventTest.php +++ b/tests/Functional/Event/SwaggerDocCreatedEventTest.php @@ -1,7 +1,8 @@