Add Messenger assertions#241
Merged
Merged
Conversation
This was referenced Jun 25, 2026
2a7a299 to
60c90d4
Compare
Add MessengerAssertionsTrait so functional tests can assert which messages were dispatched, how many, and on which bus. Like the Events/Mailer/Notifier traits, it reads Symfony's profiler "messenger" data collector. Steps: seeMessageDispatched, dontSeeMessageDispatched, seeDispatchedMessageCount and grabDispatchedMessageClasses. Per the module convention these use the see*/grab* idiom rather than assert*, which is reserved for direct ports of Symfony's own test assertions. Wire a dispatchable TestMessage into the test app (synchronous handler, no transport) and cover the steps in tests/MessengerAssertionsTest.php. symfony/messenger is a dev-only dependency; remove it before the Symfony 7.4 functional run, where the fixture app pulls in API Platform and would otherwise auto-register a Messenger processor bound to an undefined messenger.default_bus.
60c90d4 to
4c55de6
Compare
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.
What
Adds a
MessengerAssertionsTraitso functional tests can assert against Symfony Messenger, which until now had no coverage in this module — even though its Messenger-based siblings (Mailer, Notifier) are fully covered.New
$I->steps:seeMessageDispatched(string $messageClass, ?string $bus = null)dontSeeMessageDispatched(string $messageClass, ?string $bus = null)seeDispatchedMessageCount(int $expectedCount, ?string $bus = null)grabDispatchedMessageClasses(?string $bus = null)These follow the module's naming convention:
see*/dontSee*for module-native assertions (no upstream Symfony web-test equivalent, so notassert*),grab*for getters.grabDispatchedMessageClasses()returns class-strings — hence the explicit name, distinct from the object-returninggrabSentEmails/grabSentNotifications.How
Reads Symfony's
messengerprofiler data collector via the existinggrabCollector()helper — the same pattern the Events/Form/Twig traits use. Wires themessengercollector intoDataCollectorNameand thegrabCollector()conditional return-type map.The collector stores cloned
VarDumpersnapshots (message class, bus, exceptions), not live message objects, so payload-level assertions are intentionally out of scope. The class-name reader narrows theDatatree to themessage.typeleaf via ArrayAccess rather than recursively materializing each entry's whole snapshot (message payload, stamps, caller, exception trace) — handling both the plain-stringtype(Symfony ≤ 7.x) and theClassStubrepresentation (8.x).Tests
Adds a self-contained Messenger setup to the test app (
framework.messengerdefault bus + a sample message, handler, controller action and route) andtests/MessengerAssertionsTest.phpcovering counts, per-bus filtering, positive/negative dispatch checks and the no-dispatch case. Passesphpunit,phpstan(level max) andcs-check.Functional tests
Per
CONTRIBUTING.md, the matching functional tests are submitted as companion PRs toCodeception/symfony-module-tests(branches5.4,6.4,7.4,8.0).