@@ -71,7 +71,7 @@ public function testItShouldNotEvaluateExpressionInProcess()
7171 $ this ->expectException (ProcessingException::class);
7272
7373 $ expression = 'not good expression ' ;
74- $ exchange = $ this ->createMock (Exchange::class);
74+ $ exchange = $ this ->createMock (Exchange::class);
7575
7676 $ evaluator = $ this ->createMock (ExpressionEvaluator::class);
7777 $ evaluator
@@ -122,7 +122,7 @@ public function testItShouldDispatchAnEventForEveryRecipientOnProcess()
122122 ->will ($ this ->returnValue ('123 ' ));
123123
124124 $ expression = "exchange.getHeader('recipientList') " ;
125- $ recipientList = 'route_a, route_b ' ;
125+ $ recipientList = 'route_a! route_b ' ;
126126
127127 $ evaluator = $ this ->createMock (ExpressionEvaluator::class);
128128 $ evaluator
@@ -146,7 +146,7 @@ public function testItShouldDispatchAnEventForEveryRecipientOnProcess()
146146
147147 $ eventDispatcher = $ this ->createMock (EventDispatcherInterface::class);
148148
149- $ this ->recipientList ->setDelimiter (', ' );
149+ $ this ->recipientList ->setDelimiter ('! ' );
150150 $ this ->recipientList ->setExpression ($ expression );
151151 $ this ->recipientList ->setAggregationStrategy (RecipientList::AGGREGATION_STRATEGY_FIRE_AND_FORGET );
152152 $ this ->recipientList ->setEvaluator ($ evaluator );
@@ -171,4 +171,82 @@ public function testItShouldDispatchAnEventForEveryRecipientOnProcess()
171171
172172 $ this ->assertSame (2 , $ dispatchedEventsCounter );
173173 }
174+
175+ public function testItShouldAcceptEmptyRecipientLists ()
176+ {
177+ $ context = $ this ->createMock (Context::class);
178+ $ context
179+ ->expects ($ this ->any ())
180+ ->method ('get ' )
181+ ->with ($ this ->equalTo ('version ' ))
182+ ->will ($ this ->returnValue (1 ));
183+
184+ $ message = $ this ->createMock (MessageInterface::class);
185+ $ message
186+ ->expects ($ this ->any ())
187+ ->method ('getContext ' )
188+ ->will ($ this ->returnValue ($ context ));
189+
190+ // No interaction with the exchange
191+ $ exchange = $ this ->createMock (Exchange::class);
192+ $ exchange
193+ ->expects ($ this ->never ())
194+ ->method ('getIn ' );
195+ $ exchange
196+ ->expects ($ this ->never ())
197+ ->method ('getItinerary ' );
198+ $ exchange
199+ ->expects ($ this ->never ())
200+ ->method ('getHeaders ' );
201+ $ exchange
202+ ->expects ($ this ->never ())
203+ ->method ('getId ' );
204+
205+ $ expression = "exchange.getHeader('recipientList') " ;
206+ $ recipientList = '' ;
207+
208+ $ evaluator = $ this ->createMock (ExpressionEvaluator::class);
209+ $ evaluator
210+ ->expects ($ this ->once ())
211+ ->method ('evaluateWithExchange ' )
212+ ->with ($ this ->equalTo ($ expression ), $ this ->equalTo ($ exchange ))
213+ ->will ($ this ->returnValue ($ recipientList ));
214+
215+ $ itineraryParams = ['_itinerary ' => $ this ->createMock (Itinerary::class)];
216+
217+ // No interaction with the itinerary resolver
218+ $ itineraryResolver = $ this ->createMock (ItineraryResolver::class);
219+ $ itineraryResolver
220+ ->expects ($ this ->never ())
221+ ->method ('getItineraryParams ' );
222+ $ itineraryResolver
223+ ->expects ($ this ->never ())
224+ ->method ('filterItineraryParamsToPropagate ' );
225+
226+ $ eventDispatcher = $ this ->createMock (EventDispatcherInterface::class);
227+
228+ $ this ->recipientList ->setDelimiter (', ' );
229+ $ this ->recipientList ->setExpression ($ expression );
230+ $ this ->recipientList ->setAggregationStrategy (RecipientList::AGGREGATION_STRATEGY_FIRE_AND_FORGET );
231+ $ this ->recipientList ->setEvaluator ($ evaluator );
232+ $ this ->recipientList ->setItineraryResolver ($ itineraryResolver );
233+ $ this ->recipientList ->setEventDispatcher ($ eventDispatcher );
234+
235+ // No events should be dispatched if the list is empty
236+ $ exchangeEvents = false ;
237+ $ eventDispatcher
238+ ->expects ($ this ->any ())
239+ ->method ('dispatch ' )
240+ ->with (($ this ->callback (function ($ eventName ) use ($ exchangeEvents ){
241+ if (NewExchangeEvent::TYPE_NEW_EXCHANGE_EVENT === $ eventName ) {
242+ return false ;
243+ }
244+
245+ return true ;
246+ })));
247+
248+ $ this ->recipientList ->process ($ exchange );
249+
250+ $ this ->assertFalse ($ exchangeEvents , 'Exchange event was dispatched with an empty recipient list. ' );
251+ }
174252}
0 commit comments