fix(symfony): guard browserkit verbose setter on symfony 6.4 - #8580
ousamabenyounes wants to merge 1 commit into
Conversation
|
Please target 4.4 or 5.0 |
b9fab8e to
50f1fd6
Compare
|
Rebased onto |
|
phpstan is red you can lower the amount of comments as well |
setBrowserKitAssertionsAsVerbose() only exists since Symfony 7.3, so every ApiTestCase-based test fataled with "Call to undefined method" on Symfony 6.4, which the 4.3 branch still supports. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
50f1fd6 to
b0fff89
Compare
|
@soyuka thanks — both addressed. PHPStan: the guard is unavoidably "always true" under Symfony 8.1 (I tried Comments: the 4 added docblock lines are gone, one inline line left. Commit rebased on |
Summary
Since 4.3.19 (#8523)
ApiTestCaseregisters a#[Before]hook callingself::setBrowserKitAssertionsAsVerbose(true). That setter only exists since Symfony 7.3, so on Symfony 6.4 — a combination Composer still allows on4.3— everyApiTestCase-based test fatals withCall to undefined methodbefore its body runs. No CI job caught it: the root PHPUnit suite is the only one exercisingApiTestCaseand it always installs Symfony >= 7.x.The call is now guarded with
method_exists(): verbose output stays on where the setter exists, and is a no-op where it does not. PHPStan analyses against Symfony 8.1, where the setter always exists, so the guard is reported asfunction.alreadyNarrowedType; it carries a one-line@phpstan-ignorenext to the BC reason, like the other Symfony BC guards already ignored inphpstan.neon.dist.Test plan
symfony/framework-bundle6.4.46 —method_exists(BrowserKitAssertionsTrait::class, 'setBrowserKitAssertionsAsVerbose')isfalse, confirming the guard is required.vendor/bin/phpstan analyse src/Symfony/Bundle/Test/ApiTestCase.php— 1 error before the ignore, 0 after (Symfony 8.1.7, PHPStan 2.x).PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix src/Symfony/Bundle/Test/ApiTestCase.php— clean.vendor/bin/phpunit tests/Symfony/Bundle/Test— 67 tests, 109 assertions, 3 failures, identical to the same run onorigin/4.3(local sqlite fixture schema, unrelated to this change).commitlint -g .commitlintrcon the branch's single commit — green.