Skip to content

fix(symfony): guard browserkit verbose setter on symfony 6.4 - #8580

Open
ousamabenyounes wants to merge 1 commit into
api-platform:4.4from
ousamabenyounes:fix/issue-8564
Open

ousamabenyounes wants to merge 1 commit into
api-platform:4.4from
ousamabenyounes:fix/issue-8564

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #8564
License MIT

Summary

Since 4.3.19 (#8523) ApiTestCase registers a #[Before] hook calling self::setBrowserKitAssertionsAsVerbose(true). That setter only exists since Symfony 7.3, so on Symfony 6.4 — a combination Composer still allows on 4.3 — every ApiTestCase-based test fatals with Call to undefined method before its body runs. No CI job caught it: the root PHPUnit suite is the only one exercising ApiTestCase and 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 as function.alreadyNarrowedType; it carries a one-line @phpstan-ignore next to the BC reason, like the other Symfony BC guards already ignored in phpstan.neon.dist.

Test plan

  • symfony/framework-bundle 6.4.46 — method_exists(BrowserKitAssertionsTrait::class, 'setBrowserKitAssertionsAsVerbose') is false, 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 on origin/4.3 (local sqlite fixture schema, unrelated to this change).
  • commitlint -g .commitlintrc on the branch's single commit — green.

@soyuka

soyuka commented Sep 25, 2026

Copy link
Copy Markdown
Member

Please target 4.4 or 5.0

@ousamabenyounes
ousamabenyounes changed the base branch from 4.3 to 4.4 September 25, 2026 15:21
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

Rebased onto 4.4 and retargeted, thanks @soyuka.

@soyuka

soyuka commented Sep 25, 2026

Copy link
Copy Markdown
Member

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>
@ousamabenyounes ousamabenyounes changed the title fix(symfony,test): guard browserkit verbose setter for symfony 6.4 compatibility fix(symfony): guard browserkit verbose setter on symfony 6.4 Sep 25, 2026
@ousamabenyounes

Copy link
Copy Markdown
Contributor Author

@soyuka thanks — both addressed.

PHPStan: the guard is unavoidably "always true" under Symfony 8.1 (I tried self::class, the BrowserKitAssertionsTrait name, Kernel::VERSION_ID, and is_callable — all narrowed), so it now carries a one-line @phpstan-ignore function.alreadyNarrowedType with the BC reason, like the other Symfony BC guards already ignored in phpstan.neon.dist. Green on the changed file.

Comments: the 4 added docblock lines are gone, one inline line left. Commit rebased on 4.3 with a single scope and a shorter subject, which also fixes commitlint (it was linting an unrelated commit picked up from a wrong merge base).

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.

2 participants