@@ -41,15 +41,35 @@ public function testItRoutesToTheCorrectBus()
4141 $ this ->assertSame ($ envelope , $ routableBus ->dispatch ($ envelope , [$ stamp ]));
4242 }
4343
44- public function testItExceptionOnMissingStamp ()
44+ public function testItRoutesToDefaultBus ()
45+ {
46+ $ envelope = new Envelope (new \stdClass ());
47+ $ stamp = new DelayStamp (5 );
48+ $ defaultBus = $ this ->createMock (MessageBusInterface::class);
49+ $ defaultBus ->expects ($ this ->once ())->method ('dispatch ' )->with ($ envelope , [$ stamp ])
50+ ->willReturn ($ envelope );
51+
52+ $ container = $ this ->createMock (ContainerInterface::class);
53+ $ container ->expects ($ this ->once ())->method ('has ' )->with (MessageBusInterface::class)
54+ ->willReturn (true );
55+ $ container ->expects ($ this ->once ())->method ('get ' )->with (MessageBusInterface::class)
56+ ->willReturn ($ defaultBus );
57+
58+ $ routableBus = new RoutableMessageBus ($ container );
59+
60+ $ this ->assertSame ($ envelope , $ routableBus ->dispatch ($ envelope , [$ stamp ]));
61+ }
62+
63+ public function testItExceptionOnDefaultBusNotFound ()
4564 {
4665 $ this ->expectException (InvalidArgumentException::class);
47- $ this ->expectExceptionMessage (' does not contain a BusNameStamp ' );
66+ $ this ->expectExceptionMessage (sprintf ( ' Bus name "%s" does not exists. ' , MessageBusInterface::class) );
4867
4968 $ envelope = new Envelope (new \stdClass ());
5069
5170 $ container = $ this ->createMock (ContainerInterface::class);
52- $ container ->expects ($ this ->never ())->method ('has ' );
71+ $ container ->expects ($ this ->once ())->method ('has ' )->with (MessageBusInterface::class)
72+ ->willReturn (false );
5373
5474 $ routableBus = new RoutableMessageBus ($ container );
5575 $ routableBus ->dispatch ($ envelope );
@@ -58,7 +78,7 @@ public function testItExceptionOnMissingStamp()
5878 public function testItExceptionOnBusNotFound ()
5979 {
6080 $ this ->expectException (InvalidArgumentException::class);
61- $ this ->expectExceptionMessage (' Invalid bus name' );
81+ $ this ->expectExceptionMessage (sprintf ( ' Bus name "%s" does not exists. ' , ' foo_bus ' ) );
6282
6383 $ envelope = new Envelope (new \stdClass (), [new BusNameStamp ('foo_bus ' )]);
6484
0 commit comments