diff --git a/.ahoy.yml b/.ahoy.yml index e060aca..9a9774d 100644 --- a/.ahoy.yml +++ b/.ahoy.yml @@ -68,30 +68,30 @@ commands: usage: Run unit tests. cmd: | pushd "build" >/dev/null || exit 1 - vendor/bin/phpunit --testsuite unit + vendor/bin/phpunit --testsuite unit "$@" popd >/dev/null || exit 1 test-kernel: usage: Run kernel tests. cmd: | pushd "build" >/dev/null || exit 1 - vendor/bin/phpunit --testsuite kernel + vendor/bin/phpunit --testsuite kernel "$@" popd >/dev/null || exit 1 test-functional: usage: Run functional tests. cmd: | pushd "build" >/dev/null || exit 1 - vendor/bin/phpunit --testsuite functional + vendor/bin/phpunit --testsuite functional "$@" popd >/dev/null || exit 1 reset: usage: Reset project to the default state. cmd: | killall -9 php >/dev/null 2>&1 || true - chmod -Rf 777 build > /dev/null - rm -Rf build > /dev/null || true - rm -Rf .logs > /dev/null || true + chmod -Rf 777 build .logs > /dev/null 2>&1 || true + rm -Rf build > /dev/null 2>&1 || true + rm -Rf .logs > /dev/null 2>&1 || true # Override entrypoint to alter default behaviour of Ahoy. entrypoint: diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index fbb4a71..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,199 +0,0 @@ -# @see https://github.com/AlexSkrypnyk/drupal_extension_scaffold -version: 2 - -aliases: - # Default git branch name used for deploying tagged releases. - - &default_branch "2.x" - - # SSH deployment key fingerprint from CircleCI App -> Project -> Settings -> SSH Permissions. - # Replace with the value used for your project. - - &deploy_ssh_fingerprint "2d:71:4d:aa:4d:34:38:b5:8f:af:ca:3b:d4:82:6a:21" - - # Configuration for shared runner containers, applied to each job. - - &container_config - working_directory: ~/project - docker: - - image: cimg/php:8.2-browsers - -job-test: &job-test - steps: - - checkout - - - run: - name: Upgrade sqlite3 - command: | - wget https://www.sqlite.org/2024/sqlite-autoconf-3450300.tar.gz -O /tmp/sqlite.tar.gz - tar -xzf /tmp/sqlite.tar.gz -C /tmp - cd /tmp/sqlite-autoconf-3450300 - ./configure CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" --prefix=/usr/local - make && sudo make install - sudo ldconfig - echo "export LD_LIBRARY_PATH=/usr/local/lib" >> $BASH_ENV - - - run: - name: Install PCOV - command: | - sudo pecl install pcov - echo "extension=pcov.so" | sudo tee -a /usr/local/etc/php/conf.d/pcov.ini - echo "pcov.enabled=1" | sudo tee -a /usr/local/etc/php/conf.d/pcov.ini - - - run: - name: Assemble the codebase - command: .devtools/assemble.sh - - - run: - name: Start built-in PHP server - command: .devtools/start.sh - - - run: - name: Provision site - command: .devtools/provision.sh - - - run: - name: Lint code with PHPCS - command: vendor/bin/phpcs || [ "${CI_PHPCS_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - - - run: - name: Lint code with PHPStan - command: vendor/bin/phpstan || [ "${CI_PHPSTAN_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - - - run: - name: Lint code with Rector - command: vendor/bin/rector --clear-cache --dry-run || [ "${CI_RECTOR_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - - - run: - name: Lint code with PHPMD - command: vendor/bin/phpmd . text phpmd.xml || [ "${CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - - - run: - name: Lint code with Twig CS Fixer - command: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - - - run: - name: Run tests - command: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ] - working_directory: build - environment: - BROWSERTEST_OUTPUT_DIRECTORY: /tmp - - - store_test_results: - path: .logs/test_results - - - store_artifacts: - path: build/web/sites/simpletest/browser_output - - - store_artifacts: - path: .logs/coverage - - - run: - name: Upload code coverage reports to Codecov - command: | - if [ -z "${CIRCLE_TAG-}" ] && [ -n "${CODECOV_TOKEN-}" ] && [ -d .logs/coverage/phpunit ]; then - curl -Os https://cli.codecov.io/latest/linux/codecov && sudo chmod +x codecov - ./codecov --verbose upload-process --fail-on-error -n "circleci-$CIRCLE_JOB" -s .logs/coverage - fi - -jobs: - test-php-8.2: - <<: *container_config - docker: - - image: cimg/php:8.2-browsers - environment: - DRUPAL_VERSION: 10.1 - DRUPAL_PROJECT_SHA: 10.x - <<: *job-test - - test-php-8.2-legacy: - <<: *container_config - docker: - - image: cimg/php:8.2-browsers - environment: - DRUPAL_VERSION: 10.1 - DRUPAL_PROJECT_SHA: 10.x - <<: *job-test - - test-php-8.2-next: - <<: *container_config - docker: - - image: cimg/php:8.2-browsers - environment: - DRUPAL_VERSION: 10@beta - DRUPAL_PROJECT_SHA: 10.x - <<: *job-test - - test-php-8.3: - <<: *container_config - docker: - - image: cimg/php:8.3-browsers - environment: - DRUPAL_VERSION: stable - DRUPAL_PROJECT_SHA: 10.x - <<: *job-test - - test-php-8.3-next: - <<: *container_config - docker: - - image: cimg/php:8.3-browsers - environment: - DRUPAL_VERSION: 11@alpha - DRUPAL_PROJECT_SHA: 11.x - <<: *job-test - - deploy: - <<: *container_config - environment: - DEPLOY_SSH_KEY_FINGERPRINT: *deploy_ssh_fingerprint - DEFAULT_BRANCH: *default_branch - steps: - - checkout - - - add_ssh_keys: - fingerprints: - - *deploy_ssh_fingerprint - - - run: - name: Deploy - command: DEPLOY_BRANCH=${DEPLOY_BRANCH:-${CIRCLE_BRANCH:-${DEFAULT_BRANCH}}} .devtools/deploy.sh - -workflows: - version: 2 - commit: - jobs: - - test-php-8.2: - filters: - tags: - only: /.*/ - - test-php-8.2-legacy: - filters: - tags: - only: /.*/ - - test-php-8.2-next: - filters: - tags: - only: /.*/ - - test-php-8.3: - filters: - tags: - only: /.*/ - - test-php-8.3-next: - filters: - tags: - only: /.*/ - - deploy: - requires: - - test-php-8.2 - - test-php-8.2-legacy - - test-php-8.2-next - - test-php-8.3 - - test-php-8.3-next - filters: - tags: - only: /.*/ - branches: - # 1.0.x, 2.3.x, 9.x, 10.x, 9.x-2.x, ci, ci-test - only: /^[0-9]+.[0-9]+.x$|^[0-9]+.x(?:\-[0-9]+\.x)?$|^ci.*/ diff --git a/.devtools/assemble.sh b/.devtools/assemble.sh index 7a6fca3..a23bff5 100755 --- a/.devtools/assemble.sh +++ b/.devtools/assemble.sh @@ -21,14 +21,12 @@ set -eu # Variables (passed from environment; provided for reference only). #------------------------------------------------------------------------------- -# Drupal core version to use. If not provided - the latest stable version will be used. -# Must be coupled with DRUPAL_PROJECT_SHA below. -DRUPAL_VERSION="${DRUPAL_VERSION:-10}" +# Drupal core version to use. +DRUPAL_VERSION="${DRUPAL_VERSION:-11}" # Commit SHA of the drupal-project to install custom core version. If not -# provided - the latest version will be used. -# Must be coupled with DRUPAL_VERSION above. -DRUPAL_PROJECT_SHA="${DRUPAL_PROJECT_SHA:-10.x}" +# provided - will be calculated from `$DRUPAL_VERSION` above. +DRUPAL_PROJECT_SHA="${DRUPAL_PROJECT_SHA:-}" # Repository for "drupal-composer/drupal-project" project. # May be overwritten to use forked repos that may have not been accepted @@ -51,19 +49,33 @@ echo " 🏗️ ASSEMBLE " echo "===============================" echo +# Validate required variables. +if [ -z "${DRUPAL_VERSION}" ]; then + fail "ERROR: DRUPAL_VERSION is not set." + exit 1 +fi + +if [ -z "${DRUPAL_PROJECT_REPO}" ]; then + fail "ERROR: DRUPAL_PROJECT_REPO is not set." + exit 1 +fi + # Make sure Composer doesn't run out of memory. export COMPOSER_MEMORY_LIMIT=-1 info "Validate tools." -! command -v git >/dev/null && echo "ERROR: Git is required for this script to run." && exit 1 -! command -v php >/dev/null && echo "ERROR: PHP is required for this script to run." && exit 1 -! command -v composer >/dev/null && echo "ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1 -! command -v jq >/dev/null && echo "ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1 +! command -v git >/dev/null && fail "ERROR: Git is required for this script to run." && exit 1 +! command -v php >/dev/null && fail "ERROR: PHP is required for this script to run." && exit 1 +! command -v composer >/dev/null && fail "ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1 +! command -v jq >/dev/null && fail "ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1 pass "Tools are valid." +# Set the sed options based on the OS. +sed_opts=(-i) && [ "$(uname)" == "Darwin" ] && sed_opts=(-i '') + # Extension name, taken from the .info file. extension="$(basename -s .info.yml -- ./*.info.yml)" -[ "${extension}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1 +[ "${extension}" == "*" ] && fail "ERROR: No .info.yml file found." && exit 1 # Extension type. type=$(grep -q "type: theme" "${extension}.info.yml" && echo "themes" || echo "modules") @@ -80,25 +92,36 @@ if [ -d "build" ]; then fi info "Creating Drupal codebase." -# Allow installing custom version of Drupal core from drupal-composer/drupal-project, -# but only coupled with drupal-project SHA (required to get correct dependencies). -if [ -n "${DRUPAL_VERSION:-}" ] && [ -n "${DRUPAL_PROJECT_SHA:-}" ]; then - note "Initialising Drupal site from the scaffold repo ${DRUPAL_PROJECT_REPO} commit ${DRUPAL_PROJECT_SHA}." - - # Clone Drupal core at the specific commit SHA. - git clone -n "${DRUPAL_PROJECT_REPO}" "build" - git --git-dir="build/.git" --work-tree="build" checkout "${DRUPAL_PROJECT_SHA}" - rm -rf "build/.git" >/dev/null - - note "Pin Drupal to a specific version ${DRUPAL_VERSION}." - sed_opts=(-i) && [ "$(uname)" == "Darwin" ] && sed_opts=(-i '') - sed "${sed_opts[@]}" 's|\(.*"drupal\/core"\): "\(.*\)",.*|\1: '"\"$DRUPAL_VERSION\",|" "build/composer.json" - cat "build/composer.json" -else - note "Initialising Drupal site from the latest scaffold." - # There are no releases in "drupal-composer/drupal-project", so have to use "@dev". - composer create-project drupal-composer/drupal-project:@dev "build" --no-interaction --no-install + +drupal_version_major="$(echo "${DRUPAL_VERSION}" | cut -d '.' -f 1 | cut -d '@' -f 1)" +drupal_version_stability="$(echo "${DRUPAL_VERSION}" | sed -n 's/.*@\(.*\)/\1/p')" +drupal_version_stability="${drupal_version_stability:-stable}" + +DRUPAL_PROJECT_SHA="${DRUPAL_PROJECT_SHA:-"${drupal_version_major}.x"}" + +note "Initialising Drupal ${DRUPAL_VERSION} site from the scaffold repo ${DRUPAL_PROJECT_REPO} ref ${DRUPAL_PROJECT_SHA}." + +# Clone Drupal project at the specific commit SHA. +git clone -n "${DRUPAL_PROJECT_REPO}" "build" +git --git-dir="build/.git" --work-tree="build" checkout "${DRUPAL_PROJECT_SHA}" +rm -rf "build/.git" >/dev/null + +note "Pinning Drupal to a specific version ${DRUPAL_VERSION}." +sed "${sed_opts[@]}" 's|\(.*"drupal\/core.*"\): "\(.*\)",.*|\1: '"\"~$DRUPAL_VERSION\",|" "build/composer.json" +grep '"drupal/core-.*": "' "build/composer.json" + +note "Updating stability to ${drupal_version_stability}." +# Do not rely on the values coming from the scaffold and always set them. +sed "${sed_opts[@]}" 's|\(.*"minimum-stability"\): "\(.*\)",.*|\1: '"\"${drupal_version_stability}\",|" "build/composer.json" +grep 'minimum-stability' "build/composer.json" + +drupal_version_prefer_stable="true" +if [ "${drupal_version_stability}" != "stable" ]; then + drupal_version_prefer_stable="false" fi +sed "${sed_opts[@]}" 's|\(.*"prefer-stable"\): \(.*\),.*|\1: '${drupal_version_prefer_stable}',|' "build/composer.json" +grep 'prefer-stable' "build/composer.json" + pass "Drupal codebase created." info "Merging configuration from composer.dev.json." @@ -141,14 +164,31 @@ for composer_suggest in $composer_suggests; do done pass "Suggested dependencies installed." +# Some versions of Drupal enforce maximum verbosity for errors by default. This +# leads to functional tests failing due to deprecation notices showing up in +# the page output, which is then interpreted as a test failure by PHPUnit. +# To address this, we inject the error_reporting() without deprecations into +# the index.php and default.settings.php file used by the system under test. +# But we do this only if the deprecations helper is set to `disable` which means +# to ignore deprecation notices. +# @see https://www.drupal.org/project/drupal/issues/1267246 +if [ "${SYMFONY_DEPRECATIONS_HELPER-}" == "disabled" ]; then + info "Disabling deprecation notices in functional tests." + echo "error_reporting(E_ALL & ~E_DEPRECATED);" >>build/web/sites/default/default.settings.php + sed "${sed_opts[@]}" 's/^ Building front-end dependencies." + note "Building front-end dependencies." if [ ! -f ".skip_npm_build" ]; then npm run build; fi pass "Front-end dependencies installed." fi @@ -157,6 +197,7 @@ info "Copying tools configuration files." # Not every tool correctly resolves the path to the configuration file if it is # symlinked, so we copy them instead. cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig-cs-fixer.php phpunit.xml "build/" +[ -f "phpunit.d${drupal_version_major}.xml" ] && cp "phpunit.d${drupal_version_major}.xml" "build/phpunit.xml" pass "Tools configuration files copied." info "Symlinking extension's code." @@ -170,6 +211,6 @@ echo " 🏗 ASSEMBLE COMPLETE ✅ " echo "===============================" echo echo "> Next steps:" -echo " .devtools/start.sh # Start the webserver" +echo " .devtools/start.sh # Start the webserver" echo " .devtools/provision.sh # Provision the website" echo diff --git a/.devtools/provision.sh b/.devtools/provision.sh index cc43ce4..829c776 100755 --- a/.devtools/provision.sh +++ b/.devtools/provision.sh @@ -54,7 +54,10 @@ fi db_file="/tmp/site_${extension}.sqlite" info "Installing Drupal into SQLite database ${db_file}." -drush sql:drop -y || true >/dev/null +db_status=$(drush status --field=db-status) +if [ "${db_status}" = "Connected" ]; then + drush sql:drop -y || true >/dev/null +fi drush site-install "${DRUPAL_PROFILE}" -y --db-url="sqlite://localhost/${db_file}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL pass "Drupal installed." @@ -90,8 +93,12 @@ echo "Site URL: http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" echo -n "One-time login link: " drush -l "http://${WEBSERVER_HOST}:${WEBSERVER_PORT}" uli --no-browser echo -echo "> Available commands:" -echo " ahoy build # Rebuild" -echo " ahoy lint # Check coding standards" -echo " ahoy test # Run tests" +if [ -f ".ahoy.yml" ]; then + # shellcheck disable=SC2016 + echo 'Run `ahoy` to see available commands.' +fi +if [ -f "Makefile" ]; then + # shellcheck disable=SC2016 + echo 'Run `make` to see available commands.' +fi echo diff --git a/.gitattributes b/.gitattributes index 355e0b1..0ee5bb2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,22 +1,19 @@ # Ignore files for distribution archives. -# Uncomment the lines below in your project. -.ahoy.yml export-ignore -.circleci export-ignore -.devtools export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.github export-ignore -.gitignore export-ignore -.twig_cs.php export-ignore -Makefile export-ignore -composer.dev.json export-ignore -phpcs.xml export-ignore -phpmd.xml export-ignore -phpstan.neon export-ignore -rector.php export-ignore -renovate.json export-ignore -tests export-ignore +.ahoy.yml export-ignore +.circleci export-ignore +.devtools export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.github export-ignore +.gitignore export-ignore +.twig-cs-fixer.php export-ignore +Makefile export-ignore +composer.dev.json export-ignore +phpcs.xml export-ignore +phpmd.xml export-ignore +phpstan.neon export-ignore +rector.php export-ignore +renovate.json export-ignore +tests export-ignore -.github/FUNDING.yml export-ignore -LICENSE export-ignore diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..802c3f8 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,41 @@ +name: Deploy + +on: + workflow_run: + workflows: + - Test + types: + - completed + +jobs: + deploy: + runs-on: ubuntu-24.04 + + env: + DEPLOY_USER_NAME: ${{ secrets.DEPLOY_USER_NAME }} + DEPLOY_USER_EMAIL: ${{ secrets.DEPLOY_USER_NAME }} + DEPLOY_REMOTE: ${{ secrets.DEPLOY_REMOTE }} + DEPLOY_PROCEED: ${{ secrets.DEPLOY_PROCEED }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install SSH key + uses: shimataro/ssh-key-action@v2 + with: + key: ${{ secrets.DEPLOY_SSH_KEY }} + known_hosts: unnecessary + config: | + Host * + StrictHostKeyChecking no + + - name: Deploy to Remote + env: + DEPLOY_BRANCH: ${{ env.DEPLOY_BRANCH }} + HEAD_REF: ${{ github.head_ref }} + run: | + REF=${{ github.event.pull_request && env.HEAD_REF || github.ref_name }} + DEPLOY_BRANCH=${DEPLOY_BRANCH:-${REF}} .devtools/deploy.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3ce2b87 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,186 @@ +name: Test + +on: + push: + tags: + - '**' + branches: + - 2.x + pull_request: + branches: + - 2.x + +jobs: + test: + runs-on: ubuntu-24.04 + + strategy: + fail-fast: false + + matrix: + include: + - name: test-php-8.2-d10-legacy + php-version: 8.2 + drupal-version: 10.2 + + - name: test-php-8.2-d10-stable + php-version: 8.2 + drupal-version: 10.3 + + - name: test-php-8.2-d10-canary + php-version: 8.2 + drupal-version: 10.4@beta + stability: canary + + - name: test-php-8.3-d10-legacy + php-version: 8.3 + drupal-version: 10.2 + + - name: test-php-8.3-d10-stable + php-version: 8.3 + drupal-version: 10.3 + + - name: test-php-8.3-d10-canary + php-version: 8.3 + drupal-version: 10.4@beta + stability: canary + + - name: test-php-8.4-d10-legacy + php-version: 8.4 + drupal-version: 10.3 # Lowest Drupal version that supports PHP 8.4. + + - name: test-php-8.4-d10-stable + php-version: 8.4 + drupal-version: 10.3 + + - name: test-php-8.4-d10-canary + php-version: 8.4 + drupal-version: 10.4@beta + + - name: test-php-8.3-d11-legacy + php-version: 8.3 + drupal-version: 11.0 # Lowest Drupal version that exists. + + - name: test-php-8.3-d11-stable + php-version: 8.3 + drupal-version: 11.0 + + - name: test-php-8.3-d11-canary + php-version: 8.3 + drupal-version: 11@beta + + - name: test-php-8.4-d11-legacy + php-version: 8.4 + drupal-version: 11.0 # Lowest Drupal version that exists. + + - name: test-php-8.4-d11-stable + php-version: 8.4 + drupal-version: 11.0 + + - name: test-php-8.4-d11-canary + php-version: 8.4 + drupal-version: 11@beta + + name: ${{ matrix.name }} + + env: + DRUPAL_VERSION: ${{ matrix.drupal-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: /tmp/composer-cache + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + - name: Upgrade sqlite3 + run: | + wget https://www.sqlite.org/2024/sqlite-autoconf-3450300.tar.gz -O /tmp/sqlite.tar.gz + tar -xzf /tmp/sqlite.tar.gz -C /tmp + cd /tmp/sqlite-autoconf-3450300 + ./configure CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" --prefix=/usr/local + make && sudo make install + sudo ldconfig + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: gd, sqlite, pdo_sqlite + coverage: pcov + ini-values: pcov.directory=. + + # Disable Symfony deprecations helper for PHP 8.4+ until minor + # versions of Drupal 10 and 11 fully support PHP 8.4. + # @see https://www.drupal.org/project/drupal/issues/1267246 + - name: Update SYMFONY_DEPRECATIONS_HELPER for PHP 8.4 + run: | + if [ "$(php -r 'echo PHP_MAJOR_VERSION . PHP_MINOR_VERSION;')" == "84" ]; then + echo "SYMFONY_DEPRECATIONS_HELPER=disabled" >> "$GITHUB_ENV" + fi + + - name: Assemble the codebase + run: .devtools/assemble.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Start built-in PHP server + run: .devtools/start.sh + + - name: Provision site + run: .devtools/provision.sh + + - name: Lint code with PHPCS + working-directory: build + run: vendor/bin/phpcs || [ "${CI_PHPCS_IGNORE_FAILURE:-0}" -eq 1 ] + + - name: Lint code with PHPStan + working-directory: build + run: vendor/bin/phpstan || [ "${CI_PHPSTAN_IGNORE_FAILURE:-0}" -eq 1 ] + continue-on-error: ${{ endsWith(matrix.name, 'canary') }} # PHPStan levels for canary releases are not the same as for this project. + + - name: Lint code with Rector + working-directory: build + run: vendor/bin/rector --clear-cache --dry-run || [ "${CI_RECTOR_IGNORE_FAILURE:-0}" -eq 1 ] + + - name: Lint code with PHPMD + working-directory: build + run: vendor/bin/phpmd . text phpmd.xml || [ "${CI_PHPMD_IGNORE_FAILURE:-0}" -eq 1 ] + + - name: Lint code with Twig CS Fixer + working-directory: build + run: vendor/bin/twig-cs-fixer || [ "${CI_TWIGCSFIXER_IGNORE_FAILURE:-0}" -eq 1 ] + + - name: Run tests + working-directory: build + run: vendor/bin/phpunit || [ "${CI_TEST_IGNORE_FAILURE:-0}" -eq 1 ] + env: + BROWSERTEST_OUTPUT_DIRECTORY: /tmp + + - name: Upload test results as an artifact + uses: actions/upload-artifact@v4 + if: always() + with: + name: Artifacts (${{ matrix.name }}) + path: build/web/sites/simpletest/browser_output + + - name: Upload coverage report as an artifact + uses: actions/upload-artifact@v4 + with: + name: ${{github.job}}-code-coverage-report-${{ matrix.name }} + path: ./.logs/coverage/phpunit/.coverage-html + include-hidden-files: true + if-no-files-found: error + + - name: Upload coverage report to Codecov + uses: codecov/codecov-action@v5 + if: ${{ env.CODECOV_TOKEN != '' }} + with: + files: ./.logs/coverage/phpunit/cobertura.xml + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index d987b03..9d880a1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -.logs -composer.lock -build -node_modules +/.logs +/build +/composer.lock +/node_modules +/vendor diff --git a/README.md b/README.md index f9ace25..3e9a47b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- Test mode + Testmode logo

Testmode

@@ -14,7 +14,6 @@ ![LICENSE](https://img.shields.io/github/license/AlexSkrypnyk/testmode) ![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot) -![Drupal 9](https://img.shields.io/badge/Drupal-9-blue.svg) ![Drupal 10](https://img.shields.io/badge/Drupal-10-009CDE.svg) ![Drupal 11](https://img.shields.io/badge/Drupal-11-006AA9.svg) @@ -25,7 +24,6 @@

This Drupal module is designed to modify existing site content and configurations while running tests.

## Features -This is a module to support testing, so it is not expected to be used in production (although, it adheres to Drupal coding standards and has good test coverage). @@ -65,10 +63,10 @@ the provided scripts. ### Build -Run `.devtools/buid.sh` (or `ahoy build` +Run `.devtools/assemble.sh` (or `ahoy assemble` if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to start inbuilt PHP server locally and run the same commands as in CI, plus installing a site and -your extension automatically. +Testmode automatically. ### Code linting @@ -92,18 +90,15 @@ vendor/bin/twig-cs-fixer - PHPMD config: [`phpmd.xml`](phpmd.xml) - Rector config: [`rector.php`](rector.php) - Twig CS Fixer config: [`.twig-cs-fixer.php`](.twig-cs-fixer.php) -- Patches can be applied to the dependencies: add a patch to the - `patches` section of `composer.json`. Local patches will be sourced from - the `patches` directory. ### Tests Run tests individually with `cd build && ./vendor/bin/phpunit` (or `ahoy test` if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to run all test for -your extension. +Testmode. ### Browsing SQLite database To browse the contents of created SQLite database -(located at `/tmp/site_[EXTENSION_NAME].sqlite`), +(located at `/tmp/site_testmode.sqlite`), use [DB Browser for SQLite](https://sqlitebrowser.org/). diff --git a/composer.dev.json b/composer.dev.json index 84ae244..fbe3475 100644 --- a/composer.dev.json +++ b/composer.dev.json @@ -6,6 +6,7 @@ "palantirnet/drupal-rector": "^0.18", "phpcompatibility/php-compatibility": "^9.3", "phpmd/phpmd": "^2.15", + "phpstan/phpdoc-parser": "^1", "phpspec/prophecy-phpunit": "^2", "phpstan/extension-installer": "^1.3", "vincentlanglet/twig-cs-fixer": "^2.8" diff --git a/composer.json b/composer.json index be138f8..f83b974 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "drupal/testmode", - "type": "drupal-module", "description": "Alter existing site content and other configurations when running tests.", + "type": "drupal-module", "license": "GPL-2.0-or-later", "authors": [ { @@ -17,7 +17,10 @@ "source": "https://git.drupalcode.org/project/testmode" }, "require": { - "php": ">=8.1" + "php": ">=8.2" + }, + "require-dev": { + "drupal/autologout": "^2" }, "suggest": { "drupal/search_api": "^1.25" diff --git a/phpcs.xml b/phpcs.xml index edd6fa8..0acae9d 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -18,10 +18,6 @@ - - circle\.yml - \.circle\/config\.yml - .*\/node_modules\/.* *\.min\.* @@ -41,17 +37,10 @@ warning - - - *.Test\.php - *.TestCase\.php - *.test - - *.Test\.php *.TestCase\.php *.test - \ No newline at end of file + diff --git a/phpmd.xml b/phpmd.xml index 0095bb1..1d59107 100644 --- a/phpmd.xml +++ b/phpmd.xml @@ -15,6 +15,7 @@ */web/sites/* */scripts/* */tests/*Test.php + */tests/*TestBase.php @@ -26,4 +27,4 @@ - \ No newline at end of file + diff --git a/phpstan.neon b/phpstan.neon index e103f7d..e3ab989 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -19,9 +19,6 @@ parameters: - vendor/* - node_modules/* - drupal: - drupal_root: web - ignoreErrors: - # Hook implementations do not provide docblocks for parameters, so there diff --git a/phpunit.d10.xml b/phpunit.d10.xml new file mode 100644 index 0000000..9c2440f --- /dev/null +++ b/phpunit.d10.xml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + web/modules/custom/*/tests/src/Unit + web/themes/custom/*/tests/src/Unit + + + web/modules/custom/*/tests/src/Kernel + web/themes/custom/*/tests/src/Kernel + + + web/modules/custom/*/tests/src/Functional + web/themes/custom/*/tests/src/Functional + + + + + + + + + + + + + + + web/modules/custom + web/themes/custom + + + + web/modules/custom/*/tests + web/themes/custom/*/tests + web/modules/custom/testmode/rector.php + web/themes/custom/testmode/rector.php + + + + + + + + diff --git a/phpunit.xml b/phpunit.xml index 8babd77..1539edc 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,51 +1,43 @@ - - + + + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" + cacheDirectory=".phpunit.cache"> - - + + - + - - - - - - - + - - - + + + + + + + + + + + + + web/modules/custom/*/tests/src/Unit @@ -83,7 +93,7 @@ - +