Prepare the work for FunctionalTesting using Symfony's WebTestCase #19093
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.
Checklist before requesting a review
Please delete options that are not relevant.
This code is the very first step towards easing testing by using existing Symfony-related tooling.
This code allows doing things like this that can work (because it's not yet fully tested on my machine and I only have a few amount of uncommitted test cases related to this):
In the future, this will make it much easier to create functional tests by just spawning a kernel request call and asserting on HTML, XML or JSON output because Symfony already has tons of cool assertions for that purpose 👌
Another advantage is that some specific tests will need existing data in the database, and for that purpose, we can spawn some HTTP requests that will fill some forms or run the API to actually do the data addition (and even extract this in some utility Traits for reusability), and roll the changes back after the request, by wrapping the entire process in a database transaction and calling "rollback" on it at test's teardown.
A few small blockers though: all code using StreamedResponse won't (yet) be completely compatible because these streamed responses are harder to test with PHPUnit.
Not impossible, but you have to manually make the call to the internal closure and wrap it in an output buffer on which you'll make your assertions, so it's all manual stuff and cannot benefit from Symfony's assertions.