/**
  * @test
  */
 public function it_should_pass_trough_none_rpc_commands()
 {
     $this->transformer->shouldNotReceive('transformCommandResponse');
     $this->publisher->shouldNotReceive('publish');
     $envelope = Mockery::mock(\AMQPEnvelope::class);
     $envelope->shouldReceive('getReplyTo')->atLeast()->once()->andReturn('');
     $command = Mockery::mock(Command::class);
     $command->shouldReceive('getEnvelope')->atLeast()->once()->andReturn($envelope);
     $this->execute($this->middleware, $command, $command);
 }
 /**
  * {@inheritdoc}
  */
 public function execute($command, callable $next)
 {
     // Check that the command expects a response
     if (!$command instanceof Command || empty($command->getEnvelope()->getReplyTo())) {
         return $next($command);
     }
     // Execute command
     $result = $next($command);
     // Transform result
     $message = $this->transformer->transformCommandResponse($result);
     // Publish the response message
     $publisher = $this->getPublisher($command);
     $publisher->publish($message);
     return $result;
 }