PHP code example of morebec / orkestra-event-sourcing-testing
1. Go to this page and download the library: Download morebec/orkestra-event-sourcing-testing library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
morebec / orkestra-event-sourcing-testing example snippets
class RegisterCustomerCommandHandlerTest extends EventSourcedTestCase
{
/**
* @return void
* @throws Throwable
*/
public function test(): void
{
$customerId = uniqid('cus_', true);
$this
->defineScenario()
->givenCurrentDateIs(new DateTime("2020-01-01"))
->whenCommand(from(static function() use ($customerId) {
$command = new RegistercustomerCommand();
$command->customerId = $customerId;
return $command;
}))
->messageBusShouldRespondWithPayload(null)
->messageBusShouldRespondWithStatusCodeSucceeded()
->expectSingleEventSameAs(from(static function() use ($customerId) {
$event = new CustomerRegisteredEvent();
$event->customerId = $customerId;
return $event;
}))
->runScenario()
;
}
}