dispatch($event); // THEN Event::assertDispatched($event::class, 1); }); it('buffers events and dispatches them only on outermost flush', function (): void { // GIVEN Event::fake(); $dispatcher = new LaravelDomainEventDispatcher(); $event = new class () implements DomainEvent { }; // WHEN $dispatcher->beginBuffering(); $dispatcher->beginBuffering(); $dispatcher->dispatch($event); Event::assertNothingDispatched(); $dispatcher->flush(); Event::assertNothingDispatched(); $dispatcher->flush(); // THEN Event::assertDispatched($event::class, 1); }); it('discards buffered events without dispatching them', function (): void { // GIVEN Event::fake(); $dispatcher = new LaravelDomainEventDispatcher(); $event = new class () implements DomainEvent { }; // WHEN $dispatcher->beginBuffering(); $dispatcher->dispatch($event); $dispatcher->discard(); $dispatcher->flush(); // THEN Event::assertNothingDispatched(); }); });