Skip to content

feat(test): keep ApiTestCase BrowserKit assertions verbose for Symfony 8.2 - #8523

Open
ousamabenyounes wants to merge 1 commit into
api-platform:mainfrom
ousamabenyounes:fix/issue-8450
Open

feat(test): keep ApiTestCase BrowserKit assertions verbose for Symfony 8.2#8523
ousamabenyounes wants to merge 1 commit into
api-platform:mainfrom
ousamabenyounes:fix/issue-8450

Conversation

@ousamabenyounes

Copy link
Copy Markdown
Contributor

Symfony >= 8.2 flips BrowserKit response assertions to non-verbose by default, hiding the response body on failure. ApiTestCase now re-enables verbose assertions in a #[Before] hook so failing API tests keep showing the (JSON) body; projects can still opt out via setBrowserKitAssertionsAsVerbose(false) in setUp() or per-assertion verbose: false.

Test verification (RED → GREEN)

With the fix reverted, the new test fails (RED):

PHPUnit 12.5.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.25
Configuration: /app/phpunit.xml.dist

[issue-8450] before ApiTestCase before-hook: defaultVerboseMode = false
�[31;1mE�[0m                                                                   1 / 1 (100%)

Time: 00:00.007, Memory: 18.00 MB

There was 1 error:

1) ApiPlatform\Tests\Symfony\Bundle\Test\ApiTestCaseTest::testBrowserKitAssertionsStayVerboseByDefault
Error: Call to undefined method ApiPlatform\Tests\Symfony\Bundle\Test\ApiTestCaseTest::keepBrowserKitAssertionsVerbose()

/app/tests/Symfony/Bundle/Test/ApiTestCaseTest.php:439

�[37;41mERRORS!�[0m
�[37;41mTests: 1�[0m�[37;41m, Assertions: 0�[0m�[37;41m, Errors: 1�[0m�[37;41m.�[0m

With the fix applied, the test passes (GREEN):

GREEN attempt 1/2 (exit 0)
PHPUnit 12.5.35 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.25
Configuration: /app/phpunit.xml.dist

[issue-8450] before ApiTestCase before-hook: defaultVerboseMode = false
[issue-8450] after ApiTestCase before-hook:  defaultVerboseMode = true
.                                                                   1 / 1 (100%)

Time: 00:00.006, Memory: 18.00 MB

�[30;42mOK (1 test, 1 assertion)�[0m

Full local suite

Command: docker run --rm -v "$PWD":/app -w /app php:8.4-cli bash -c 'php vendor/bin/phpunit --ignore-baseline && php vendor/bin/php-cs-fixer fix --dry-run --diff'

    0/2964 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   0%
   31/2964 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░]   1%
  111/2964 [▓░░░░░░░░░░░░░░░░░░░░░░░░░░░]   3%
  161/2964 [▓░░░░░░░░░░░░░░░░░░░░░░░░░░░]   5%
  221/2964 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]   7%
  261/2964 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]   8%
  297/2964 [▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░]  10%
  461/2964 [▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░]  15%
  593/2964 [▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░]  20%
  781/2964 [▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░]  26%
  890/2964 [▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░]  30%
 1021/2964 [▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░]  34%
 1186/2964 [▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░]  40%
 1341/2964 [▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░]  45%
 1441/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░]  48%
 1482/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░]  50%
 1541/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░]  51%
 1651/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░]  55%
 1732/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░]  58%
 1772/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░]  59%
 1852/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░]  62%
 2002/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░]  67%
 2075/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░░]  70%
 2132/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░]  71%
 2172/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░░]  73%
 2272/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░░]  76%
 2372/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░]  80%
 2432/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░░]  82%
 2492/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░░]  84%
 2542/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░]  85%
 2632/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░░]  88%
 2668/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░]  90%
 2712/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░░]  91%
 2782/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░]  93%
 2842/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░░]  95%
 2922/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░]  98%
 2964/2964 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%


Found 0 of 2964 files that can be fixed in 36.649 seconds, 126.00 MB memory used

Fix #8450

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.

Evaluate changes to support less verbose BrowserKit from Symfony ^8.2

1 participant