File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change 44
55use ApiClients \Tools \CommandBus \CommandBus ;
66use Interop \Container \ContainerInterface ;
7- use InvalidArgumentException ;
87use React \Promise \CancellablePromiseInterface ;
98
109final class Client
@@ -14,16 +13,18 @@ final class Client
1413 */
1514 private $ container ;
1615
16+ /**
17+ * @var CommandBus
18+ */
19+ private $ commandBus ;
20+
1721 /**
1822 * @param ContainerInterface $container
1923 */
2024 public function __construct (ContainerInterface $ container )
2125 {
2226 $ this ->container = $ container ;
23-
24- if (!$ this ->container ->has (CommandBus::class)) {
25- throw new InvalidArgumentException ();
26- }
27+ $ this ->commandBus = $ this ->container ->get (CommandBus::class);
2728 }
2829
2930 /**
@@ -34,8 +35,20 @@ public function getContainer(): ContainerInterface
3435 return $ this ->container ;
3536 }
3637
38+ /**
39+ * @return mixed
40+ */
41+ public function getFromContainer (string $ id )
42+ {
43+ return $ this ->container ->get ($ id );
44+ }
45+
46+ /**
47+ * @param $command
48+ * @return CancellablePromiseInterface
49+ */
3750 public function handle ($ command ): CancellablePromiseInterface
3851 {
39- return $ this ->container -> get (CommandBus::class) ->handle ($ command );
52+ return $ this ->commandBus ->handle ($ command );
4053 }
4154}
Original file line number Diff line number Diff line change @@ -45,6 +45,15 @@ public function handle($command)
4545 $ client = new Client ($ container );
4646
4747 $ this ->assertSame ($ container , $ client ->getContainer ());
48+ $ this ->assertSame ($ commandBus , $ client ->getFromContainer (CommandBus::class));
4849 $ this ->assertSame ($ command , await ($ client ->handle ($ command ), $ loop ));
4950 }
51+
52+ /**
53+ * @expectedException \DI\Definition\Exception\DefinitionException
54+ */
55+ public function testCommandBusMissing ()
56+ {
57+ new Client (ContainerBuilder::buildDevContainer ());
58+ }
5059}
You can’t perform that action at this time.
0 commit comments