Skip to content

Commit 4ce55dc

Browse files
authored
[ci] Run AddDoesNotPerformAssertionToNonAssertingTestRector on Drupal core and its tests (#832)
1 parent e8fab67 commit 4ce55dc

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

‎.github/drupal/rector.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\PHPUnit\PHPUnit60\Rector\ClassMethod\AddDoesNotPerformAssertionToNonAssertingTestRector;
7+
8+
// run from Drupal root, see .github/workflows/drupal.yaml
9+
return RectorConfig::configure()
10+
->withPaths([getcwd() . '/core/tests', getcwd() . '/core/modules'])
11+
// test data for Drupal's own test tooling, not real tests
12+
->withSkip([getcwd() . '/core/tests/fixtures', getcwd() . '/core/tests/PHPStan/fixtures'])
13+
->withRules([AddDoesNotPerformAssertionToNonAssertingTestRector::class]);

‎.github/workflows/drupal.yaml‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# runs AddDoesNotPerformAssertionToNonAssertingTestRector on Drupal core,
2+
# then runs Drupal tests to catch wrongly added/removed #[DoesNotPerformAssertions]
3+
name: Drupal
4+
5+
on:
6+
pull_request: null
7+
push:
8+
branches:
9+
- main
10+
11+
env:
12+
COMPOSER_ROOT_VERSION: "dev-main"
13+
# pinned for deterministic results, bump to test newer Drupal code
14+
DRUPAL_REF: "7480c58b75c058f850b45e81664ac1df7d309744"
15+
16+
jobs:
17+
drupal:
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 40
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
-
25+
uses: actions/checkout@v4
26+
with:
27+
repository: drupal/drupal
28+
ref: ${{ env.DRUPAL_REF }}
29+
path: drupal
30+
31+
-
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
# Drupal main requires PHP 8.5
35+
php-version: 8.5
36+
coverage: none
37+
extensions: gd, pdo_sqlite, pdo_mysql, pdo_pgsql
38+
# Drupal tests rely on runtime assert() checks
39+
ini-values: zend.assertions=1
40+
41+
- uses: "ramsey/composer-install@v2"
42+
43+
-
44+
uses: "ramsey/composer-install@v2"
45+
with:
46+
working-directory: drupal
47+
48+
-
49+
name: "Run Rector on Drupal"
50+
working-directory: drupal
51+
run: |
52+
php ../vendor/bin/rector process --config ../.github/drupal/rector.php --no-progress-bar
53+
git diff --stat
54+
55+
-
56+
name: "Run Drupal unit tests"
57+
working-directory: drupal
58+
# IconFinderTest asserts an exact PCRE error offset, which differs between PCRE versions
59+
run: php vendor/bin/phpunit -c core --testsuite unit --no-progress --exclude-filter 'IconFinderTest::testExtractIconIdFromFilenameWarning'
60+
61+
# only the Kernel tests Rector changed, functional ones need a web server
62+
-
63+
name: "Run changed Drupal kernel tests"
64+
working-directory: drupal
65+
run: |
66+
mkdir -p "$RUNNER_TEMP/kernel"
67+
git diff --name-only | grep -E '/(Kernel|KernelTests)/.*Test\.php$' > "$RUNNER_TEMP/kernel-tests.txt" || true
68+
cat "$RUNNER_TEMP/kernel-tests.txt"
69+
70+
# each test file gets its own sqlite database, so they can run in parallel
71+
xargs -P "$(nproc)" -I{} sh -c 'id=$(echo "{}" | md5sum | cut -c1-10); \
72+
SIMPLETEST_DB="sqlite://localhost/$RUNNER_TEMP/kernel/$id.sqlite" SIMPLETEST_BASE_URL=http://localhost \
73+
php vendor/bin/phpunit -c core --no-progress "{}" > "$RUNNER_TEMP/kernel/$id.txt" 2>&1; true' \
74+
< "$RUNNER_TEMP/kernel-tests.txt"
75+
76+
# Rector only adds or removes #[DoesNotPerformAssertions], so risky assertion counts are the regression to catch
77+
if grep -h -B1 -E 'not expected to perform assertions|did not perform any assertions' "$RUNNER_TEMP"/kernel/*.txt; then
78+
exit 1
79+
fi

0 commit comments

Comments
 (0)