[Messenger][FrameworkBundle] Add MessengerAssertionsTrait to test in-memory transports
A functional test that wants to run the messages queued on an in-memory transport has to build a Worker by hand, with an event dispatcher and a StopWorkerOnMessageLimitListener. FrameworkBundle ships assertion traits for Mailer, Notifier, HttpClient and Console but none for Messenger. Messenger: - StopWorkerOnIdleListener stops the worker as soon as its receivers return no message, so a worker can drain a queue and exit without sleeping. - InMemoryTransport implements ListableReceiverInterface and MessageCountAwareInterface: all(), find() and getMessageCount() expose the queued envelopes, delayed ones included. The messenger:show and messenger:stats commands work with in-memory transports as a result. FrameworkBundle: - MessengerAssertionsTrait, composed into KernelTestCase, provides assertQueuedMessageCount(), getQueuedMessages(), getMessengerTransport() and consumeQueuedMessages(). The last one runs the queued messages through the real message bus with the application's event dispatcher, so the retry and failure transport listeners behave as in production, and rethrows the first handler failure so that it fails the test. - Listing and consuming queued messages need symfony/messenger 8.2. With an older version the trait throws a LogicException that says so, like the other Messenger 8.2 features of the bundle.
N
Nicolas Grekas committed
9196ce5dc52a8abba0cdd555109e969edf616145
Parent: 5f68f75