Fix 2.x CI: split preg-match nsrt test by PHP/PHPStan version#53
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
This started as a request to backport d25621a ("Update phpstan tests to latest phpstan features") to
2.xto fix the red CI. On investigation, that commit is already effectively present on2.x(it landed viabfa9e76), 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.xsupportsphp: ^7.2 || ^8.0, but PHPStan 2.x requires PHP ≥ 7.4 — so on 7.2/7.3composer --highestinstalls PHPStan 1.12, which infers plainstringinstead ofnon-falsy-string.All 17 failures were in
tests/PHPStanTests/nsrt/preg-match.php, the only nsrt file with no// lintdirective, so it ran on every PHP version. The siblingpreg-replace-callbacktest already handles this with a// lint >= 7.4/// lint < 7.4split.Change
preg-match.phpto// lint >= 7.4(keeps thenon-falsy-stringexpectations for PHPStan 2.x).preg-match-php7.2.phpwith// lint < 7.4holding the plain-stringexpectations for PHPStan 1.12.This mirrors the existing
preg-replace-callback.php/preg-replace-callback-php7.2.phppattern. No production/srcchanges. Verified locally on PHP 8.4 (--testsuite phpstangreen, 43 tests); the 7.2/7.3 side is exercised by CI.🤖 Generated with Claude Code