Skip to content

Commit

Permalink
test-cases for using messenger HandleTrait as QueryBus
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartłomiej Nowak committed Jan 17, 2025
1 parent dd1aaa7 commit cc1869e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/Type/Symfony/data/messenger_handle_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,32 @@ public function __invoke()
assertType('mixed', $this->handle(new MultiHandlersForTheSameMessageQuery()));
}
}

class QueryBus {
use HandleTrait;

public function dispatch(object $query): mixed
{
return $this->handle($query);
}
}

class Controller {
public function action()
{
$queryBus = new QueryBus();

assertType(RegularQueryResult::class, $queryBus->dispatch(new RegularQuery()));

assertType('bool', $queryBus->dispatch(new BooleanQuery()));
assertType('int', $queryBus->dispatch(new IntQuery()));
assertType('float', $queryBus->dispatch(new FloatQuery()));
assertType('string', $queryBus->dispatch(new StringQuery()));

assertType(TaggedResult::class, $queryBus->dispatch(new TaggedQuery()));

// HandleTrait will throw exception in fact due to multiple handle methods/handlers per single query
assertType('mixed', $queryBus->dispatch(new MultiHandlesForInTheSameHandlerQuery()));
assertType('mixed', $queryBus->dispatch(new MultiHandlersForTheSameMessageQuery()));
}
}

0 comments on commit cc1869e

Please sign in to comment.