public function testChainWithDifferentProceedCalls()
 {
     $interceptor1 = new Interceptor1();
     $interceptor2 = new Interceptor2();
     \Phake::when($this->mockCommandHandler)->handle(\Phake::anyParameters())->thenReturn('Result');
     $testSubject = new DefaultInterceptorChain(GenericCommandMessage::asCommandMessage(new Payload("original")), $this->mockUnitOfWork, $this->mockCommandHandler, array($interceptor1, $interceptor2));
     $actual = $testSubject->proceed();
     $this->assertSame("Result", $actual);
 }
 /**
  * @param CommandMessageInterface $command
  * @param CommandHandlerInterface $handler
  * @return mixed
  * @throws \Exception
  */
 protected function doDispatch(CommandMessageInterface $command, CommandHandlerInterface $handler)
 {
     $this->logger->debug("Dispatching command [{name}]", array('name' => $command->getCommandName()));
     $unitOfWork = $this->unitOfWorkFactory->createUnitOfWork();
     $unitOfWork->setLogger($this->logger);
     $chain = new DefaultInterceptorChain($command, $unitOfWork, $handler, $this->handlerInterceptors);
     try {
         $return = $chain->proceed();
     } catch (\Exception $ex) {
         $unitOfWork->rollback($ex);
         throw $ex;
     }
     $unitOfWork->commit();
     return $return;
 }