public function testSubscribe()
 {
     $commandHandler = $this->getMock(CommandHandlerInterface::class);
     $this->subject->subscribe(get_class(new TestCommand('hi')), $commandHandler);
     $handler = $this->subject->findCommandHandlerFor(GenericCommandMessage::asCommandMessage(new TestCommand('hi')));
     $this->assertInstanceOf(CommandHandlerInterface::class, $handler);
 }
 public function testDispatchCommand_ImplicitUnitOfWorkIsRolledBackOnException()
 {
     $command = new TestCommand("Say hi!");
     $test = $this;
     $this->handlerRegistry->subscribe(TestCommand::class, new CallbackCommandHandler(function (CommandMessageInterface $commandMessage, UnitOfWorkInterface $unitOfWork) use($test) {
         $test->assertTrue(CurrentUnitOfWork::isStarted());
         $test->assertNotNull(CurrentUnitOfWork::get());
         throw new \RuntimeException("exception");
     }));
     $callback = new ClosureCommandCallback(function ($result) use($command) {
         $this->fail("Did not expect exception");
     }, function ($exception) {
         $this->assertEquals(\RuntimeException::class, get_class($exception));
     });
     $this->commandBus->dispatch(GenericCommandMessage::asCommandMessage($command), $callback);
     $this->assertFalse(CurrentUnitOfWork::isStarted());
 }
 public function registerCommandHandler($commandName, CommandHandlerInterface $commandHandler)
 {
     $this->registerAggregateCommandHandlers();
     $this->explicitCommandHandlersSet = true;
     $this->handlerRegistry->subscribe($commandName, $commandHandler);
     return $this;
 }