Skip to content

refactor(VariableAnalysis): Replace sniff with upstream sniff (#3553265) #519

refactor(VariableAnalysis): Replace sniff with upstream sniff (#3553265)

refactor(VariableAnalysis): Replace sniff with upstream sniff (#3553265) #519

Workflow file for this run

name: Tests
on: [push, pull_request]
jobs:
testing:
name: PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3']
extra-tests: ['0']
# We only need to run PHPStan and Drupal core regression tests once on
# the latest PHP version.
include:
- php-versions: '8.4'
extra-tests: '1'
steps:
- name: Checkout Coder
uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring
# Disable Xdebug for better performance.
coverage: none
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
# Running composer install without a lock file will also update cached
# dependencies in vendor.
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run PHPUnit
run: ./vendor/bin/phpunit
- name: Run PHPCS
run: ./vendor/bin/phpcs
- name: Check custom standard autoloading
# Ensure that a custom standard can be invoked and the auto-loading of
# abstract classes works.
# Ensure that the DrupalPractice standard can be invoked standalone and the
# auto-loading of abstract classes works.
run: |
./vendor/bin/phpcs -p --standard=tests/Drupal/phpcs-ruleset.xml tests/Drupal/good/ --ignore=tests/Drupal/good/GoodUnitTest.php
./vendor/bin/phpcs -p --standard=coder_sniffer/DrupalPractice tests/DrupalPractice/good/ --ignore=tests/DrupalPractice/good/GoodUnitTest.php
- name: Run PHPStan
if: ${{ matrix.extra-tests == '1' }}
run: ./vendor/bin/phpstan analyse
- name: Run Cspell
if: ${{ matrix.extra-tests == '1' }}
uses: streetsidesoftware/cspell-action@v7
with:
incremental_files_only: false
- name: Checkout Drupal core
if: ${{ matrix.extra-tests == '1' }}
uses: actions/checkout@v3
with:
repository: drupal/drupal
ref: "11.x"
path: drupal
- name: Run PHPCS on Drupal core for regressions
if: ${{ matrix.extra-tests == '1' }}
# In case Drupal core files have known problems that should be
# ignored temporarily, add them with the --ignore option.
run: |
cd drupal/core
# Fix Drupal core PHPCS config by replacing removed sniffs.
sed -i 's/Drupal.Classes.ClassCreateInstance/SlevomatCodingStandard.ControlStructures.NewWithParentheses/g' phpcs.xml.dist
sed -i 's/Drupal.Classes.UnusedUseStatement/SlevomatCodingStandard.Namespaces.UnusedUses/g' phpcs.xml.dist
sed -i '/<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch" \/>/a \ <rule ref="SlevomatCodingStandard.Namespaces.UseFromSameNamespace"/>' phpcs.xml.dist
find . -type f -name "*.php" -exec sed -i 's#// phpcs:ignore Drupal.Classes.PropertyDeclaration, Drupal.NamingConventions.ValidVariableName.LowerCamelName, Drupal.Commenting.VariableComment.Missing#// phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName,PSR2.Classes.PropertyDeclaration.Underscore#g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreLine#// phpcs:ignore#g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreFile#// phpcs:ignoreFile#g' {} +
find . -type f -exec sed -i '/\/\/ phpcs:ignore/ s/, /,/g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreStart#// phpcs:disable#g' {} +
find . -type f -name "*.php" -exec sed -i 's#// @codingStandardsIgnoreEnd#// phpcs:enable#g' {} +
sed -i '/<rule ref="Drupal.Functions.FunctionDeclaration"\/>/d' phpcs.xml.dist
sed -i 's/DrupalPractice.CodeAnalysis.VariableAnalysis/VariableAnalysis.CodeAnalysis.VariableAnalysis/g' phpcs.xml.dist
find .. -type f -name "*.php" -exec sed -i 's#// phpcs:ignore DrupalPractice.CodeAnalysis.VariableAnalysis#// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis#g' {} +
../../vendor/bin/phpcs -p -s --parallel=$(nproc) --ignore=lib/Drupal/Core/Command/GenerateTheme.php,modules/mysql/tests/src/Kernel/mysql/Console/DbDumpCommandTest.php