22
33namespace MessengerHandleTrait ;
44
5- use Symfony \Component \Messenger \Handler \MessageSubscriberInterface ;
65use Symfony \Component \Messenger \HandleTrait ;
76use function PHPStan \Testing \assertType ;
87
@@ -16,41 +15,6 @@ public function __invoke(RegularQuery $query): RegularQueryResult
1615 }
1716}
1817
19- class BooleanQuery {}
20- class StringQuery {}
21- class IntQuery {}
22- class FloatQuery {}
23- class MultiQueryHandler implements MessageSubscriberInterface
24- {
25- public static function getHandledMessages (): iterable
26- {
27- yield BooleanQuery::class;
28- yield IntQuery::class => ['method ' => 'handleInt ' ];
29- yield FloatQuery::class => ['method ' => 'handleFloat ' ];
30- yield StringQuery::class => ['method ' => 'handleString ' ];
31- }
32-
33- public function __invoke (BooleanQuery $ query ): bool
34- {
35- return true ;
36- }
37-
38- public function handleInt (IntQuery $ query ): int
39- {
40- return 0 ;
41- }
42-
43- public function handleFloat (FloatQuery $ query ): float
44- {
45- return 0.0 ;
46- }
47-
48- public function handleString (StringQuery $ query ): string
49- {
50- return 'string result ' ;
51- }
52- }
53-
5418class TaggedQuery {}
5519class TaggedResult {}
5620class TaggedHandler
@@ -61,21 +25,6 @@ public function handle(TaggedQuery $query): TaggedResult
6125 }
6226}
6327
64- class MultiHandlesForInTheSameHandlerQuery {}
65- class MultiHandlesForInTheSameHandler implements MessageSubscriberInterface
66- {
67- public static function getHandledMessages (): iterable
68- {
69- yield MultiHandlesForInTheSameHandlerQuery::class;
70- yield MultiHandlesForInTheSameHandlerQuery::class => ['priority ' => '0 ' ];
71- }
72-
73- public function __invoke (MultiHandlesForInTheSameHandlerQuery $ query ): bool
74- {
75- return true ;
76- }
77- }
78-
7928class MultiHandlersForTheSameMessageQuery {}
8029class MultiHandlersForTheSameMessageHandler1
8130{
@@ -99,15 +48,9 @@ public function __invoke()
9948 {
10049 assertType (RegularQueryResult::class, $ this ->handle (new RegularQuery ()));
10150
102- assertType ('bool ' , $ this ->handle (new BooleanQuery ()));
103- assertType ('int ' , $ this ->handle (new IntQuery ()));
104- assertType ('float ' , $ this ->handle (new FloatQuery ()));
105- assertType ('string ' , $ this ->handle (new StringQuery ()));
106-
10751 assertType (TaggedResult::class, $ this ->handle (new TaggedQuery ()));
10852
10953 // HandleTrait will throw exception in fact due to multiple handle methods/handlers per single query
110- assertType ('mixed ' , $ this ->handle (new MultiHandlesForInTheSameHandlerQuery ()));
11154 assertType ('mixed ' , $ this ->handle (new MultiHandlersForTheSameMessageQuery ()));
11255 }
11356}
0 commit comments