/** * @test */ public function handle_should_log_message_with_payload() { $exceptionMessage = "Fatal error"; $baseException = new Exception($exceptionMessage); $payloadMessage = $this->prophesize(MessageInterface::class); $exception = new ConsumerContainerException($this->consumerContainer->reveal(), new AMQPMessage(), $payloadMessage->reveal(), $baseException); $this->handler->handle($exception); $this->logger->warning(Argument::allOf(Argument::containingString(self::MESSAGE_CLASS), Argument::containingString($exceptionMessage)), Argument::that(function ($context) use($baseException) { verify($context['exception'])->isInstanceOf(ConsumerContainerException::class); verify($context['exception']->getPrevious())->equals($baseException); return $context; }))->shouldHaveBeenCalled(); }
/** * @test */ public function handle_should_use_existing_headers() { $table = new AMQPTable(); $exceptionMessage = "Fatal error"; $exception = new Exception($exceptionMessage); $payloadMessage = new Message(); $amqpMessage = $this->prophesize(AMQPMessage::class); $amqpMessage->has('application_headers')->willReturn(true); $amqpMessage->get('application_headers')->willReturn($table); $amqpMessage->set('application_headers', $table)->shouldBeCalled(); $this->client->sendMessage($amqpMessage->reveal(), self::CONSUMER_IDENTIFICATION)->shouldBeCalled(); $exception = new ConsumerContainerException($this->consumerContainer->reveal(), $amqpMessage->reveal(), $payloadMessage, $exception); $this->handler->handle($exception); }
/** * @test */ public function get_method_name_should_return_class_with_method_name() { $consumer = new Consumer(); $method = new ReflectionMethod($consumer, 'consume'); $consumerAnnotation = new ConsumerAnnotation(); $container = new ConsumerContainer(self::TEST_PREFIX, $consumer, $method, $consumerAnnotation); $result = $container->getMethodName(); verify($result)->equals(Consumer::class . '::consume'); }
/** * @param ConsumerContainer $consumerContainer * @param AMQPMessage $message * * @throws ConsumerContainerException * @return mixed|null */ private function invoke(ConsumerContainer $consumerContainer, AMQPMessage $message) { $payload = $this->serializer->deserialize($message->body, $consumerContainer->getMessageClass(), 'json'); try { $result = $consumerContainer->invoke($payload); } catch (Exception $e) { $containerException = new ConsumerContainerException($consumerContainer, $message, $payload, $e); if ($this->errorHandlers->isEmpty()) { throw $containerException; } $this->errorHandlers->map(function (ErrorHandlerInterface $handler) use($containerException) { $handler->handle($containerException); }); return null; } return $result; }