Skip to content

Instantly share code, notes, and snippets.

@dgafka
Last active December 17, 2022 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgafka/04cf82830210a205062b85b981a7f90d to your computer and use it in GitHub Desktop.
Save dgafka/04cf82830210a205062b85b981a7f90d to your computer and use it in GitHub Desktop.
testing-message-driven-architecture-in-php-02.php
<?php
/**
* This isolates test scenario to given set of classes
* If there would be mmore Event Handlers for OrderWasPlaced, we will be sure that only single message specifically to this
* Event Handler will be sent.
*/
$relatedClasses = [OrderService::class, OrderNotifier::class, ChannelConfiguration::class];
$ecotoneTestSupport = EcotoneLite::bootstrapForTesting(
$relatedClasses,
$dependencyContainer, // our dependency container
);
$ecotoneTestSupport->getCommandBus()->send(PlaceOrder::create($orderId));
/**
* handledMessageLimit will ensure that process will exit after handling our message. We can run it for single message thanks to isolating Event Handler.
* executionTimeLimit will ensure process will close itself after 5 seconds
* stopOnFailure will ensure that process exists immediately on error
*/
$process = new Process('php bin/console ecotone:run notifications --handledMessageLimit=1 --executionTimeLimit=5000 --stopOnFailure');
$process->start();
// continues loop
while ($process->isRunning()) {
// our Query Handler must store the state in some external storage, so we can assert it across processes
Assert::assertEquals(1, $ecotoneTestSupport->getQueryBus()->sendWithRouting("notificationService.getSentNotificationsCount");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment