File tree Expand file tree Collapse file tree 2 files changed +21
-12
lines changed
Expand file tree Collapse file tree 2 files changed +21
-12
lines changed Original file line number Diff line number Diff line change 22
33namespace ApiClients \Foundation ;
44
5+ use InvalidArgumentException ;
56use League \Container \ContainerInterface ;
67use League \Tactician \CommandBus ;
78
@@ -12,20 +13,17 @@ final class Client
1213 */
1314 private $ container ;
1415
15- /**
16- * @var CommandBus
17- */
18- private $ commandBus ;
19-
2016 /**
2117 * Client constructor.
2218 * @param ContainerInterface $container
23- * @param CommandBus $commandBus
2419 */
25- public function __construct (ContainerInterface $ container, CommandBus $ commandBus )
20+ public function __construct (ContainerInterface $ container )
2621 {
2722 $ this ->container = $ container ;
28- $ this ->commandBus = $ commandBus ;
23+
24+ if (!$ this ->container ->has (CommandBus::class)) {
25+ throw new InvalidArgumentException ();
26+ }
2927 }
3028
3129 /**
@@ -38,6 +36,6 @@ public function getContainer(): ContainerInterface
3836
3937 public function handle ($ command )
4038 {
41- return $ this ->commandBus ->handle ($ command );
39+ return $ this ->container -> get (CommandBus::class) ->handle ($ command );
4240 }
4341}
Original file line number Diff line number Diff line change 44
55use ApiClients \Foundation \Client ;
66use ApiClients \Tools \TestUtilities \TestCase ;
7- use League \Container \ContainerInterface ;
7+ use InvalidArgumentException ;
8+ use League \Container \Container ;
9+ use League \Tactician \CommandBus ;
810use League \Tactician \Setup \QuickStart ;
911
1012final class ClientTest extends TestCase
@@ -19,13 +21,22 @@ public function handle($command)
1921 }
2022 };
2123
22- $ container = $ this ->prophesize (ContainerInterface::class)->reveal ();
2324 $ commandBus = QuickStart::create ([
2425 get_class ($ command ) => $ handler ,
2526 ]);
26- $ client = new Client ($ container , $ commandBus );
27+ $ container = new Container ();
28+ $ container ->share (CommandBus::class, $ commandBus );
29+ $ client = new Client ($ container );
2730
2831 $ this ->assertSame ($ container , $ client ->getContainer ());
2932 $ this ->assertSame ($ command , $ client ->handle ($ command ));
3033 }
34+
35+ /**
36+ * @expectedException InvalidArgumentException
37+ */
38+ public function testMissingCommandBus ()
39+ {
40+ new Client (new Container ());
41+ }
3142}
You can’t perform that action at this time.
0 commit comments