Skip to content

Conversation

remipelhate
Copy link
Member

@remipelhate remipelhate commented Sep 5, 2025

Instead of having to check whether a handler is mapped using the facade directly:

$this->assertTrue(Bus::hasCommandHandler($message), "Missing handler for $messageClassFQN.");
$this->assertInstanceOf($useCaseClassFQN, Bus::getCommandHandler($message));

This new constraint encapsulates the logic and adds clear failure messages:

$this->assertThat($messageClassFCN, new HasHandler(useCaseClassFQN));

When the assertion fails, it will display one of the following failure messages:

Failed asserting that 'App\Some\Command' has handler.

* App\Some\Command has no handler mapped to it.
Failed asserting that 'App\Some\Command' has handler.

* App\Some\Command has a different handler mapped to it.

@remipelhate remipelhate self-assigned this Sep 5, 2025
Copy link

@fowbi fowbi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌🏻

@remipelhate remipelhate merged commit 8dc4edc into main Sep 5, 2025
4 checks passed
@remipelhate remipelhate deleted the addition/bus-has-handler-laravel-constraint branch September 5, 2025 11:54
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