Skip to content

test: add event Listen/Dispatch integration coverage (framework#1541) - #156

Merged
hwbrzzl merged 1 commit into
masterfrom
test-pr-1541-event-listen-dispatch
Sep 28, 2026
Merged

hwbrzzl merged 1 commit into
masterfrom
test-pr-1541-event-listen-dispatch

Conversation

@goravel-coder

Copy link
Copy Markdown
Contributor

Summary

  • Adds end-to-end coverage for framework#1541's new facades.Event().Listen() / Dispatch() API: string events with payloads, wildcard matching and ordering, typed and plain closures, slice registrations, aggregated Result errors, listener/event panic recovery, registration validation, and concurrent dispatch.
  • Covers the deprecated-but-still-supported Register / Job / GetEvents path as well, pinning its coexistence with Listen, name-based event identity, wildcard matching, and queued delivery so the legacy contract stays regression-tested until it is removed.
  • The shared listener capture now records the canonical event name beside the payload, so wildcard and queued tests assert the exact name delivered to Handle (the matched name, never the pattern).

Closes https://github.com/goravel/goravel/issues/1541

Why

framework#1541 replaced the Register / Job flow with Listen / Dispatch and a Result that joins every listener error, and the example was adapted to the new Handle(eventName string, args ...any) contract in #150. The event feature suite, though, only exercised event-value dispatch and a handful of deprecated paths, leaving the new surface — wildcards, closure forms, slice registrations, validation, panic recovery, and concurrency — without end-to-end coverage. This PR adds that integration coverage, plus the deprecated path that still ships, all through the real application container and its database-backed queue worker.

// app/providers/event.go
func (r *EventServiceProvider) Boot(app foundation.Application) {
	facades.Event().Listen("user.registered", &listeners.SendWelcomeMail{})
	facades.Event().Listen([]string{"user.created", "user.updated"}, &listeners.AuditLogger{})
	facades.Event().Listen("user.*", func(evt any, args ...any) error {
		facades.Log().Info("user event fired", evt, args)

		return nil
	})
	facades.Event().Listen(func(evt *events.UserRegistered) error {
		return facades.Mail().To([]string{evt.Email}).Send()
	})
}

// app/http/controllers/user_controller.go
func (c *UserController) Store(ctx http.Context) http.Response {
	user := events.UserRegistered{Email: ctx.Request().Input("email")}

	result := facades.Event().Dispatch(&user, []event.Arg{
		{Type: "string", Value: user.Email},
	})
	if result.Failed() {
		return ctx.Response().String(http.StatusInternalServerError, result.Error().Error())
	}

	return ctx.Response().Success().Json(http.Json{"status": "ok"})
}

The tests lock in the semantics the migration depends on: an event with no listeners is a silent success, every matching listener runs with its failures aggregated into Result, a panicking listener or event is recovered and reported rather than crashing the request, and queued listeners receive the canonical event name ahead of the payload. They also confirm the deprecated Register / Job APIs still resolve listeners registered through the new Listen, so the two surfaces coexist safely during the deprecation window.

@goravel-coder
goravel-coder requested a review from a team as a code owner September 28, 2026 01:57
@hwbrzzl
hwbrzzl merged commit 7a97186 into master Sep 28, 2026
9 checks passed
@hwbrzzl
hwbrzzl deleted the test-pr-1541-event-listen-dispatch branch September 28, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants