Skip to content

fix(upgrade): actually modernize phpunit XML configs - #56

Merged
imorland merged 2 commits into
3.xfrom
im/upgrade-phpunit-configs
Aug 2, 2026
Merged

fix(upgrade): actually modernize phpunit XML configs#56
imorland merged 2 commits into
3.xfrom
im/upgrade-phpunit-configs

Conversation

@imorland

@imorland imorland commented Aug 2, 2026

Copy link
Copy Markdown
Member

The bug — the XML rewrite has never run

Found while modernizing fof/synopsis's configs by hand (FriendsOfFlarum/synopsis#7) and asking why the upgrade tool hadn't already done it. Two independent defects, either fatal alone:

replacements(file: string): Replacement[] {
    if (!file.endsWith('.php')) return [];   // ← XML files never get replacements
    return [
      ...,
      (file, code) => {
        if (!file.endsWith('.xml')) return null;   // ← unreachable
        return {
          // ← String.replace with regex syntax in a plain string: literal match, hits nothing
          updated: code.replace('xsi:noNamespaceSchemaLocation="([^"]+)"', '...'),
        };
      },
    ];
}

So every extension run through upgrade:2.0 kept its PHPUnit 9.3-era config — which PHPUnit 12 tolerates but flags as a deprecation on every run, hides query-guard warnings behind summary counts, and pins the schema to a URL that no longer matches the installed phpunit.

The fix

modernizePhpunitXml() in its own dependency-free module, wired through a restructured dispatch (.php and phpunit*.xml each get their own path; root-level phpunit.xml added to targets). The transform converts to the shape this CLI scaffolds:

  • schema from the vendored phpunit, depth-aware (tests/…../vendor/…, root → vendor/…)
  • removed-in-10 attributes dropped; backupStaticAttributesbackupStaticProperties keeping its value
  • cacheDirectory + displayDetailsOnTestsThatTriggerWarnings inserted in scaffold order
  • <coverage><source> (include list preserved); <listeners> removed
  • testsuites and per-file settings untouched; idempotent on already-modern configs

Verification

  • 9 new jest tests written RED first (fixtures are synopsis's actual old configs): schema paths at both depths, attribute removal/rename, insertions, coverage→source, listeners removal, preservation, idempotency
  • Full suite 190/190, Prettier clean
  • End-to-end: the built binary run against a fixture extension carrying the old config produced byte-for-byte the scaffolded modern shape

The upgrade step's XML rewrite has never run: the callback sat behind
an early return that only let .php files through, and even if reached,
it called String.replace with regex syntax in a plain string — a
literal match that hits nothing. Every upgraded extension kept its
PHPUnit 9.3-era config, which PHPUnit 12 flags as a deprecation on
every run.

The rewrite is now a real transform in its own module, converting
configs to the shape the CLI scaffolds: schema resolved from the
vendored phpunit (relative to the config's own directory, so root-level
configs resolve without ../), the attributes PHPUnit 10 removed dropped
or renamed (backupStaticAttributes becomes backupStaticProperties with
its value kept), cacheDirectory and
displayDetailsOnTestsThatTriggerWarnings inserted in scaffold order so
flarum/testing's query guard warnings surface in output, coverage's
include list moved to <source>, and the Mockery listeners block
removed. Testsuites and per-file settings are preserved, and the
transform is idempotent on already-modern configs.

Root-level phpunit.xml files are now targeted alongside tests/.
@imorland
imorland merged commit 7cde039 into 3.x Aug 2, 2026
3 checks passed
@imorland
imorland deleted the im/upgrade-phpunit-configs branch August 2, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant