From be6e9983a398b3be374e7025433fcb16014ea62f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 14 Nov 2026 18:15:26 +0100 Subject: [PATCH 1/2] [ci] Run AddDoesNotPerformAssertionToNonAssertingTestRector on Drupal core and its tests --- .github/drupal/rector.php | 11 +++++ .github/workflows/drupal.yaml | 78 +++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 .github/drupal/rector.php create mode 100644 .github/workflows/drupal.yaml diff --git a/.github/drupal/rector.php b/.github/drupal/rector.php new file mode 100644 index 00000000..e6bab2ed --- /dev/null +++ b/.github/drupal/rector.php @@ -0,0 +1,11 @@ +withPaths([getcwd() . '/core/tests', getcwd() . '/core/modules']) + ->withRules([AddDoesNotPerformAssertionToNonAssertingTestRector::class]); diff --git a/.github/workflows/drupal.yaml b/.github/workflows/drupal.yaml new file mode 100644 index 00000000..3868afcc --- /dev/null +++ b/.github/workflows/drupal.yaml @@ -0,0 +1,78 @@ +# runs AddDoesNotPerformAssertionToNonAssertingTestRector on Drupal core, +# then runs Drupal tests to catch wrongly added/removed #[DoesNotPerformAssertions] +name: Drupal + +on: + pull_request: null + push: + branches: + - main + +env: + COMPOSER_ROOT_VERSION: "dev-main" + # pinned for deterministic results, bump to test newer Drupal code + DRUPAL_REF: "7480c58b75c058f850b45e81664ac1df7d309744" + +jobs: + drupal: + runs-on: ubuntu-latest + timeout-minutes: 40 + + steps: + - uses: actions/checkout@v4 + + - + uses: actions/checkout@v4 + with: + repository: drupal/drupal + ref: ${{ env.DRUPAL_REF }} + path: drupal + + - + uses: shivammathur/setup-php@v2 + with: + # Drupal main requires PHP 8.5 + php-version: 8.5 + coverage: none + extensions: gd, pdo_sqlite, pdo_mysql, pdo_pgsql + # Drupal tests rely on runtime assert() checks + ini-values: zend.assertions=1 + + - uses: "ramsey/composer-install@v2" + + - + uses: "ramsey/composer-install@v2" + with: + working-directory: drupal + + - + name: "Run Rector on Drupal" + working-directory: drupal + run: | + php ../vendor/bin/rector process --config ../.github/drupal/rector.php --no-progress-bar + git diff --stat + + - + name: "Run Drupal unit tests" + working-directory: drupal + run: php vendor/bin/phpunit -c core --testsuite unit --no-progress + + # only the Kernel tests Rector changed, functional ones need a web server + - + name: "Run changed Drupal kernel tests" + working-directory: drupal + run: | + mkdir -p "$RUNNER_TEMP/kernel" + git diff --name-only | grep -E '/(Kernel|KernelTests)/.*Test\.php$' > "$RUNNER_TEMP/kernel-tests.txt" || true + cat "$RUNNER_TEMP/kernel-tests.txt" + + # each test file gets its own sqlite database, so they can run in parallel + xargs -P "$(nproc)" -I{} sh -c 'id=$(echo "{}" | md5sum | cut -c1-10); \ + SIMPLETEST_DB="sqlite://localhost/$RUNNER_TEMP/kernel/$id.sqlite" SIMPLETEST_BASE_URL=http://localhost \ + php vendor/bin/phpunit -c core --no-progress "{}" > "$RUNNER_TEMP/kernel/$id.txt" 2>&1; true' \ + < "$RUNNER_TEMP/kernel-tests.txt" + + # Rector only adds or removes #[DoesNotPerformAssertions], so risky assertion counts are the regression to catch + if grep -h -B1 -E 'not expected to perform assertions|did not perform any assertions' "$RUNNER_TEMP"/kernel/*.txt; then + exit 1 + fi From 124b47f309e9c938d0ca73cf2b3c2226f285ea83 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 15 Nov 2026 20:36:50 +0100 Subject: [PATCH 2/2] [ci] Skip Drupal test fixtures and PCRE-version dependent IconFinderTest in Drupal job --- .github/drupal/rector.php | 2 ++ .github/workflows/drupal.yaml | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/drupal/rector.php b/.github/drupal/rector.php index e6bab2ed..4b8d0d22 100644 --- a/.github/drupal/rector.php +++ b/.github/drupal/rector.php @@ -8,4 +8,6 @@ // run from Drupal root, see .github/workflows/drupal.yaml return RectorConfig::configure() ->withPaths([getcwd() . '/core/tests', getcwd() . '/core/modules']) + // test data for Drupal's own test tooling, not real tests + ->withSkip([getcwd() . '/core/tests/fixtures', getcwd() . '/core/tests/PHPStan/fixtures']) ->withRules([AddDoesNotPerformAssertionToNonAssertingTestRector::class]); diff --git a/.github/workflows/drupal.yaml b/.github/workflows/drupal.yaml index 3868afcc..9200a6a4 100644 --- a/.github/workflows/drupal.yaml +++ b/.github/workflows/drupal.yaml @@ -55,7 +55,8 @@ jobs: - name: "Run Drupal unit tests" working-directory: drupal - run: php vendor/bin/phpunit -c core --testsuite unit --no-progress + # IconFinderTest asserts an exact PCRE error offset, which differs between PCRE versions + run: php vendor/bin/phpunit -c core --testsuite unit --no-progress --exclude-filter 'IconFinderTest::testExtractIconIdFromFilenameWarning' # only the Kernel tests Rector changed, functional ones need a web server -