Skip to content

Fix 2.x CI: split preg-match nsrt test by PHP/PHPStan version#53

Merged
Seldaek merged 1 commit into
2.xfrom
fix-phpstan-tests-old-php
May 29, 2026
Merged

Fix 2.x CI: split preg-match nsrt test by PHP/PHPStan version#53
Seldaek merged 1 commit into
2.xfrom
fix-phpstan-tests-old-php

Conversation

@Seldaek

@Seldaek Seldaek commented May 29, 2026

Copy link
Copy Markdown
Member

Context

This started as a request to backport d25621a ("Update phpstan tests to latest phpstan features") to 2.x to fix the red CI. On investigation, that commit is already effectively present on 2.x (it landed via bfa9e76), and it is actually the cause of the failure rather than the fix.

Root cause

The failing job is phpunit --testsuite phpstan. The genuine failures occur only on PHP 7.2 / 7.3 (the 8.x reds are fail-fast cancellations). 2.x supports php: ^7.2 || ^8.0, but PHPStan 2.x requires PHP ≥ 7.4 — so on 7.2/7.3 composer --highest installs PHPStan 1.12, which infers plain string instead of non-falsy-string.

All 17 failures were in tests/PHPStanTests/nsrt/preg-match.php, the only nsrt file with no // lint directive, so it ran on every PHP version. The sibling preg-replace-callback test already handles this with a // lint >= 7.4 / // lint < 7.4 split.

Change

  • Gate preg-match.php to // lint >= 7.4 (keeps the non-falsy-string expectations for PHPStan 2.x).
  • Add preg-match-php7.2.php with // lint < 7.4 holding the plain-string expectations for PHPStan 1.12.

This mirrors the existing preg-replace-callback.php / preg-replace-callback-php7.2.php pattern. No production/src changes. Verified locally on PHP 8.4 (--testsuite phpstan green, 43 tests); the 7.2/7.3 side is exercised by CI.

🤖 Generated with Claude Code

On PHP 7.2/7.3 PHPStan 2.x cannot be installed (it requires PHP >= 7.4),
so composer falls back to PHPStan 1.12 which infers `string` rather than
`non-falsy-string` for these matches. preg-match.php was the only nsrt
file without a `// lint` directive, so it ran everywhere and failed on
7.2/7.3.

Gate preg-match.php to `// lint >= 7.4` (keeping the non-falsy-string
expectations for PHPStan 2.x) and add preg-match-php7.2.php with
`// lint < 7.4` holding the plain-string expectations for PHPStan 1.12,
mirroring the existing preg-replace-callback split.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Seldaek Seldaek merged commit 465869c into 2.x May 29, 2026
26 checks passed
@Seldaek Seldaek deleted the fix-phpstan-tests-old-php branch May 29, 2026 13:58
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