@@ -41,15 +41,35 @@ public function testItRoutesToTheCorrectBus()
41
41
$ this ->assertSame ($ envelope , $ routableBus ->dispatch ($ envelope , [$ stamp ]));
42
42
}
43
43
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 ()
45
64
{
46
65
$ this ->expectException (InvalidArgumentException::class);
47
- $ this ->expectExceptionMessage (' does not contain a BusNameStamp ' );
66
+ $ this ->expectExceptionMessage (sprintf ( ' Bus name "%s" does not exists. ' , MessageBusInterface::class) );
48
67
49
68
$ envelope = new Envelope (new \stdClass ());
50
69
51
70
$ 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 );
53
73
54
74
$ routableBus = new RoutableMessageBus ($ container );
55
75
$ routableBus ->dispatch ($ envelope );
@@ -58,7 +78,7 @@ public function testItExceptionOnMissingStamp()
58
78
public function testItExceptionOnBusNotFound ()
59
79
{
60
80
$ this ->expectException (InvalidArgumentException::class);
61
- $ this ->expectExceptionMessage (' Invalid bus name' );
81
+ $ this ->expectExceptionMessage (sprintf ( ' Bus name "%s" does not exists. ' , ' foo_bus ' ) );
62
82
63
83
$ envelope = new Envelope (new \stdClass (), [new BusNameStamp ('foo_bus ' )]);
64
84
0 commit comments