2424use Drift \CommandBus \Tests \Command \ChangeYetAnotherThing ;
2525use Drift \CommandBus \Tests \Command \NotRecoverableCommand ;
2626use Drift \CommandBus \Tests \Command \RejectException ;
27+ use Drift \CommandBus \Tests \Command \ThrowError ;
2728use Drift \CommandBus \Tests \Command \ThrowException ;
2829use Drift \CommandBus \Tests \CommandHandler \ChangeAnotherThingHandler ;
2930use Drift \CommandBus \Tests \CommandHandler \ChangeAThingHandler ;
3031use Drift \CommandBus \Tests \CommandHandler \ChangeYetAnotherThingHandler ;
3132use Drift \CommandBus \Tests \CommandHandler \NotRecoverableCommandHandler ;
3233use Drift \CommandBus \Tests \CommandHandler \RejectExceptionHandler ;
34+ use Drift \CommandBus \Tests \CommandHandler \ThrowErrorHandler ;
3335use Drift \CommandBus \Tests \CommandHandler \ThrowExceptionHandler ;
3436use Drift \CommandBus \Tests \Context ;
3537use Drift \CommandBus \Tests \Middleware \Middleware1 ;
@@ -86,6 +88,12 @@ protected static function decorateConfiguration(array $configuration): array
8688 ],
8789 ];
8890
91+ $ configuration ['services ' ][ThrowErrorHandler::class] = [
92+ 'tags ' => [
93+ ['name ' => 'command_handler ' , 'method ' => 'handle ' ],
94+ ],
95+ ];
96+
8997 $ configuration ['imports ' ] = [
9098 ['resource ' => __DIR__ .'/../autowiring.yml ' ],
9199 ];
@@ -285,6 +293,11 @@ public function testReturnRejectedPromise()
285293 $ process ->stop ();
286294 }
287295
296+ /**
297+ * @return void
298+ *
299+ * @throws \Drift\CommandBus\Exception\InvalidCommandException
300+ */
288301 public function testNoRecoverableCommand ()
289302 {
290303 $ this ->resetInfrastructure ();
@@ -307,6 +320,33 @@ public function testNoRecoverableCommand()
307320 $ process ->stop ();
308321 }
309322
323+ /**
324+ * @return void
325+ *
326+ * @throws \Drift\CommandBus\Exception\InvalidCommandException
327+ */
328+ public function testErrorIsThrownInHandler ()
329+ {
330+ $ this ->resetInfrastructure ();
331+
332+ $ process = $ this ->runAsyncCommand ([
333+ 'command-bus:consume-commands ' ,
334+ ]);
335+
336+ usleep (500000 );
337+
338+ $ promises [] = $ this
339+ ->getCommandBus ()
340+ ->execute (new ThrowError ());
341+
342+ awaitAll ($ promises , $ this ->getLoop ());
343+ usleep (500000 );
344+ $ output = $ process ->getOutput ();
345+ $ this ->assertTrue (1 === substr_count ($ output , 'Rejected ' ));
346+ $ this ->assertStringContainsString ("\033[01;31mRejected \033[0m ThrowError " , $ output );
347+ $ process ->stop ();
348+ }
349+
310350 /**
311351 * Reset infrastructure.
312352 *
0 commit comments