44
55use HelloFresh \Engine \CommandBus \CommandBusInterface ;
66use HelloFresh \Engine \CommandBus \EventDispatchingCommandBus ;
7+ use HelloFresh \Engine \CommandBus \Exception \MissingHandlerException ;
8+ use HelloFresh \Engine \CommandBus \Handler \InMemoryLocator ;
79use HelloFresh \Engine \CommandBus \SimpleCommandBus ;
810use HelloFresh \Engine \EventDispatcher \EventDispatcher ;
911use HelloFresh \Tests \Engine \Mock \InvalidHandler ;
1214
1315class EventDispatchingCommandBusTest extends \PHPUnit_Framework_TestCase
1416{
17+ /**
18+ * @var InMemoryLocator
19+ */
20+ private $ locator ;
21+
1522 /**
1623 * @var CommandBusInterface
1724 */
1825 private $ commandBus ;
1926
2027 protected function setUp ()
2128 {
22- $ simpleCommandBus = new SimpleCommandBus ();
29+ $ this ->locator = new InMemoryLocator ();
30+ $ simpleCommandBus = new SimpleCommandBus ($ this ->locator );
2331 $ eventDispatcher = new EventDispatcher ();
2432 $ this ->commandBus = new EventDispatchingCommandBus ($ simpleCommandBus , $ eventDispatcher );
2533 }
@@ -30,7 +38,7 @@ protected function setUp()
3038 public function itExecutesAMessage ()
3139 {
3240 $ handler = new TestHandler ();
33- $ this ->commandBus -> subscribe (TestCommand::class, $ handler );
41+ $ this ->locator -> addHandler (TestCommand::class, $ handler );
3442
3543 $ command = new TestCommand ("hey " );
3644 $ this ->commandBus ->execute ($ command );
@@ -42,6 +50,7 @@ public function itExecutesAMessage()
4250
4351 /**
4452 * @test
53+ * @expectedException \HelloFresh\Engine\CommandBus\Exception\MissingHandlerException
4554 */
4655 public function itLosesMessageWhenThereIsNoHandlers ()
4756 {
@@ -54,25 +63,25 @@ public function itLosesMessageWhenThereIsNoHandlers()
5463
5564 /**
5665 * @test
57- * @expectedException \Assert\ InvalidArgumentException
66+ * @expectedException \InvalidArgumentException
5867 */
5968 public function itFailsWhenHaveInvalidSubscriber ()
6069 {
6170 $ command = new TestCommand ("hey " );
6271 $ handler = new TestHandler ();
6372
64- $ this ->commandBus -> subscribe ($ command , $ handler );
73+ $ this ->locator -> addHandler ($ command , $ handler );
6574 $ this ->commandBus ->execute ($ command );
6675 }
6776
6877 /**
6978 * @test
70- * @expectedException \Assert\InvalidArgumentException
79+ * @expectedException \HelloFresh\Engine\CommandBus\Exception\CanNotInvokeHandlerException
7180 */
7281 public function itFailsWhenHandlerHasAnInvalidHandleMethod ()
7382 {
7483 $ handler = new InvalidHandler ();
75- $ this ->commandBus -> subscribe (TestCommand::class, $ handler );
84+ $ this ->locator -> addHandler (TestCommand::class, $ handler );
7685
7786 $ command = new TestCommand ("hey " );
7887 $ this ->commandBus ->execute ($ command );
0 commit comments