/**
  * @test
  */
 public function it_should_throw_a_exception_when_publish_fails()
 {
     $message = new MessageCommand('message');
     $this->exchange->shouldReceive('publish')->once()->with($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $message->getAttributes())->andReturn(false);
     $this->setExpectedException(FailedToPublishException::class);
     $this->publisher->publish($message);
 }
 /**
  * @test
  */
 public function it_should_wrap_amqp_exception()
 {
     $message = new MessageCommand('message', 'key');
     $exchange = Mockery::mock(\AMQPExchange::class);
     $exchange->shouldReceive('publish')->once()->with($message->getMessage(), $message->getRoutingKey(), $message->getFlags(), $message->getAttributes())->andThrow(\AMQPConnectionException::class);
     $this->locator->shouldReceive('getExchangeForMessage')->atLeast()->once()->with($message)->andReturn($exchange);
     try {
         $this->publisher->publish($message);
         $this->fail('A exception should have been throw by exchange::publish');
     } catch (FailedToPublishException $e) {
         $this->assertInstanceOf(\AMQPConnectionException::class, $e->getPrevious(), 'Expected the previous exception to be the throw to be a \\AMQPConnectionException');
         return;
     } catch (\Exception $e) {
         $this->fail(sprintf('A exception of type %s was expected but got %s', \AMQPConnectionException::class, get_class($e)));
     }
 }