Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Honor SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSE env var for BrowserKit assertion verbosity#64222

Open
ousamabenyounes wants to merge 2 commits into
symfony:8.1from
ousamabenyounes:fix/issue-62433
Open

[FrameworkBundle] Honor SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSE env var for BrowserKit assertion verbosity#64222
ousamabenyounes wants to merge 2 commits into
symfony:8.1from
ousamabenyounes:fix/issue-62433

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Q A
Branch? 8.1
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #62433
License MIT

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:

  • per-call $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_VERBOSE env var (filter_var boolean parsing), so the same toggle can live in phpunit.xml:

<phpunit>
    <php>
        <env name="SYMFONY_BROWSERKIT_ASSERTIONS_VERBOSE" value="0"/>
    </php>
</phpunit>

setBrowserKitAssertionsAsVerbose() still wins over the env var, and the per-call $verbose argument still wins over both. Default with neither set stays true — 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 to 0, the response body is not included.
  • BrowserKitAssertionsTraitTest::testExplicitSetterWinsOverEnvVar — precedence guard: explicit setBrowserKitAssertionsAsVerbose(true) overrides the env var.

Each test runs in a separate process so the trait's static $defaultVerboseMode starts fresh. RED check passes: reverting the helper makes testEnvVarOptsOutOfVerboseFailureMessage fail (response body still included). GREEN: all three pass (3 tests, 6 assertions).

RED/GREEN verification

Without the fix (BrowserKitAssertionsTrait.php reverted to base on upstream/8.1):

1) testEnvVarOptsOutOfVerboseFailureMessage
Failed asserting that 'Failed asserting that the Response status code is 500.
HTTP/1.0 200 OK
Cache-Control: no-cache, private
... [full response dump] ...'
does not match expected condition (non-verbose).

FAILURES!
Tests: 3, Assertions: 6, Failures: 1, PHPUnit Warnings: 2.

With the fix:

Tests: 3, Assertions: 6, PHPUnit Warnings: 2.

testEnvVarOptsOutOfVerboseFailureMessage is 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 (testFailureMessageIsVerboseByDefault for default behavior, testExplicitSetterWinsOverEnvVar for setter precedence) — they pass on both sides by design, locking in the surrounding contract.

… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BrowserKit] Custom assertions are way too verbose

2 participants