[FrameworkBundle] Honor SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSE env var for BrowserKit assertion verbosity#64222
Open
ousamabenyounes wants to merge 2 commits into
Open
[FrameworkBundle] Honor SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSE env var for BrowserKit assertion verbosity#64222ousamabenyounes wants to merge 2 commits into
ousamabenyounes wants to merge 2 commits into
Conversation
… as default for assertion verbosity setBrowserKitAssertionsAsVerbose() requires editing a bootstrap file and re-running tests; an env var is set once in phpunit.xml and immediately covers every BrowserKit assertion in the project. Explicit setter and per-call $verbose argument still win — env var only fills the previously-hardcoded default. Adresses 62433.
…traint in assertResponseRedirects When assertResponseRedirects is called with both a location AND an expected code, the status-code constraint was instantiated without the resolved verbose flag, so env/setter/per-call verbosity was ignored on the status-code failure branch. Resolve the verbose value once and pass it to both constraints for consistency with the other response assertions.
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.
When a CI run hits a failing
assertResponseStatusCodeSame()(or any of the verbose-by-default BrowserKit assertions), the failure message includes the full response body. For an HTML page that's hundreds to thousands of lines per failing test, which makes the CI log unreadable when a regression touches many controllers — the original report counts 2276 lines for one test.Two existing escape hatches:
$verbose: false— boring to repeat;self::setBrowserKitAssertionsAsVerbose(false)in a PHPUnit bootstrap — requires writing/registering a bootstrap file just for this knob.This PR makes the default also honor the
SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSEenv var (filter_varboolean parsing), so the same toggle can live inphpunit.xml:setBrowserKitAssertionsAsVerbose()still wins over the env var, and the per-call$verboseargument still wins over both. Default with neither set staystrue— fully BC.Test plan:
BrowserKitAssertionsTraitTest::testFailureMessageIsVerboseByDefault— BC guard: with no env var and no setter call, the response body is included in the failure message.BrowserKitAssertionsTraitTest::testEnvVarOptsOutOfVerboseFailureMessage— with the env var set to0, the response body is not included.BrowserKitAssertionsTraitTest::testExplicitSetterWinsOverEnvVar— precedence guard: explicitsetBrowserKitAssertionsAsVerbose(true)overrides the env var.Each test runs in a separate process so the trait's static
$defaultVerboseModestarts fresh. RED check passes: reverting the helper makestestEnvVarOptsOutOfVerboseFailureMessagefail (response body still included). GREEN: all three pass (3 tests, 6 assertions).RED/GREEN verification
Without the fix (
BrowserKitAssertionsTrait.phpreverted to base onupstream/8.1):With the fix:
testEnvVarOptsOutOfVerboseFailureMessageis the test that targets the regression itself (env-var resolution path); it fails on the base branch and passes once the patch is restored. The other two new tests are backwards-compat guards (testFailureMessageIsVerboseByDefaultfor default behavior,testExplicitSetterWinsOverEnvVarfor setter precedence) — they pass on both sides by design, locking in the surrounding contract.