Last active
December 17, 2022 17:59
-
-
Save dgafka/04cf82830210a205062b85b981a7f90d to your computer and use it in GitHub Desktop.
testing-message-driven-architecture-in-php-02.php
This file contains 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
<?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