Testing Asynchronous Messaging
Testing asynchronous communication in PHP
Example Asynchronous Handler
class NotificationService
{
#[Asynchronous('notifications')]
#[EventHandler(endpointId: 'notifyOrderWasPlaced')]
public function notify(OrderWasPlaced $event, Notifier $notifier): void
{
$notifier->notifyAbout('placedOrder', $event->getOrderId());
}
}Running Asynchronous Consumer
$ecotoneTestSupport = EcotoneLite::bootstrapFlowTesting(
[OrderService::class, NotificationService::class],
[new OrderService(), new NotificationService()],
// 1. we need to provide Message Channel to use
enableAsynchronousProcessing: [
// In this scenario we are using In Memory implementation
SimpleMessageChannelBuilder::create('notifications')
]
);
// you could run Event Bus with OrderWasPlaced here instead
$ecotoneTestSupport->sendCommandWithRoutingKey('order.register', new PlaceOrder('123'));
// 2. running consumer
$ecotoneTestSupport->run('notifications');
$this->assertEquals(
1,
// 3. asserting the result
count($this->notifier->getNotificationsOf('placedOrder'))
);Default Message Channels
Polling Metadata
Testing Serialization
Testing Delayed Messages
Delaying to given date
Dropping all messages coming to given channel
Last updated
Was this helpful?