@@ -167,7 +167,7 @@ final class ProfileTest extends AggregateRootTestCase
167167
168168For testing a subscriber there is a utility class which you can use. Using ` SubscriberUtilities ` will provide you a
169169bunch of dx features which makes the testing easier. First, you will need to provide the utility class the subscriptions
170- you will want to test, this is done when initialiszing the class. After that, you can call these 3 methods:
170+ you will want to test, this is done when initializing the class. After that, you can call these 3 methods:
171171` executeSetup ` , ` executeRun ` and ` executeTeardown ` . These methods will be calling the right methods which are defined
172172via the attributes. For our example we are taking as simplified subscriber:
173173
@@ -232,4 +232,56 @@ final class ProfileSubscriberTest extends TestCase
232232}
233233```
234234
235- This Util class can be used for integration or unit tests.
235+ This Util class can be used for integration or unit tests.
236+
237+ You can also pass ` Message ` instances with additional headers to the ` executeRun ` method. This allows testing
238+ subscribers that rely on additional parameters like header information:
239+
240+
241+ ``` php
242+ use Patchlevel\EventSourcing\Attribute\Subscribe;
243+ use Patchlevel\EventSourcing\Attribute\Subscriber;
244+ use DateTimeImmutable;
245+
246+ #[Subscriber('profile_subscriber', RunMode::FromBeginning)]
247+ final class ProfileSubscriber
248+ {
249+ #[Subscribe(ProfileCreated::class)]
250+ public function run(ProfileCreated $event, DateTimeImmutable $recordedOn): void
251+ {
252+ }
253+ }
254+ ```
255+
256+ Add any headers you want in the test:
257+
258+ ``` php
259+ use Patchlevel\EventSourcing\Attribute\Subscriber;
260+ use Patchlevel\EventSourcing\Message\Message;
261+ use Patchlevel\EventSourcing\Store\Header\RecordedOnHeader;
262+ use Patchlevel\EventSourcing\Subscription\RunMode;
263+ use Patchlevel\EventSourcing\PhpUnit\Test\SubscriberUtilities;
264+ use DateTimeImmutable;
265+
266+ final class ProfileSubscriberTest extends TestCase
267+ {
268+ use SubscriberUtilities;
269+
270+ public function testProfileCreated(): void
271+ {
272+ /* Setup and Teardown as before */
273+
274+ $util->executeRun(
275+ Message::createWithHeaders(
276+ new ProfileCreated(
277+ ProfileId::fromString('1'),
278+ Email::fromString('hq@patchlevel.de'),
279+ ),
280+ [new RecordedOnHeader(new DateTimeImmutable('now'))],
281+ )
282+ );
283+
284+ /* Your assertions */
285+ }
286+ }
287+ ```
0 commit comments