fix: PHP 8.2/8.3 の unit-test で polyfill-php84 の bcround が未定義になる問題を修正#6885
fix: PHP 8.2/8.3 の unit-test で polyfill-php84 の bcround が未定義になる問題を修正#6885nanasess wants to merge 1 commit into
Conversation
テスト env では Symfony DebugClassLoader が有効で、kernel 起動後にグローバル関数 bcround() から Symfony\Polyfill\Php84\Php84 を遅延 autoload すると Php84::bcround() が解決できず、PHP 8.2/8.3 で税計算(TaxRuleService::bcround)を通す 全テストが「Call to undefined method Php84::bcround()」で失敗していた (bootstrap 時点や standalone では bcround は正常に動作する)。 tests/bootstrap.php で kernel 起動前に Php84 クラスを class_exists で事前ロードし回避する。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughtests/bootstrap.php にて、Symfony Polyfill の Php84 クラスをテスト実行前に class_exists で明示的にロードする処理とコメントが追加された。vendor/autoload.php 読み込み後の遅延解決による問題を回避する目的の変更。 Changesテストブートストラップの変更
Estimated code review effort: 1 (Trivial) | ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 4.4 #6885 +/- ##
==========================================
- Coverage 75.32% 75.27% -0.06%
==========================================
Files 519 519
Lines 25483 25483
==========================================
- Hits 19196 19182 -14
- Misses 6287 6301 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
概要(Overview)
PHP 8.2 / 8.3 の unit-test で、
symfony/polyfill-php84のSymfony\Polyfill\Php84\Php84::bcround()が実行時に「Call to undefined method」となり、税計算(
TaxRuleService::roundByRoundingType()のbcround())を通す全テストが 600 件超エラーになる問題を修正します。
症状
bcroundのため無関係)。composer installした環境(=新規 PR)の unit-test で以下が多発。4.4ブランチの push CI が緑なのは、化石化した working なvendor/キャッシュをNothing to installで復元しているためで、fresh install する新規 PR は本問題を踏みます。原因
テスト環境(
APP_ENV=test)では Symfony のDebugClassLoaderが有効です。この状態で、グローバル関数
bcround()(polyfill-php84のbootstrap80.phpが定義)からSymfony\Polyfill\Php84\Php84クラスを kernel 起動後に遅延 autoload すると、Php84::bcround()が解決できなくなります。php -r)ではPhp84::bcroundは正しく存在しbcround()も動作する。Php84を autoload するケースだけ失敗する。切り分けの結果、composer キャッシュ・opcache・polyfill のバージョン(1.37 / 1.38 とも)は無関係で、
「遅延 autoload のタイミング」が要因であることを確認しています。
修正
tests/bootstrap.phpで kernel 起動前にPhp84クラスをclass_exists()で事前ロードします(8 行)。これにより PHP 8.2 / 8.3 の unit-test が安定して通ります。本番(
APP_ENV=prod, debug 無効)はDebugClassLoaderが非活性のため影響を受けません。検証
Summary by CodeRabbit