/**
  * @param  Context $context
  * @return mixed
  */
 private function getMessageContext(Context $context = null)
 {
     if (!$context) {
         return null;
     }
     $message = $this->messageFinder->findByReference($context->getValue());
     return $message ? $message->getSource() : null;
 }
 /**
  * Handle an event.
  *
  * @param EventInterface $event
  * @param Context        $context
  *
  * @return void
  */
 public function handle(EventInterface $event, Context $context = null)
 {
     if (!$event instanceof UnableToCreateUserEvent) {
         return;
     }
     $this->logger->info('Send message', ['user' => $event->getUser()->getName(), 'type' => $event->getName()]);
     $messageContext = null;
     if ($context) {
         $messageContext = $this->messageFinder->findByReference($context->getValue());
     }
     $message = $this->messageFactory->buildMessage([$event->getUser()], $event);
     if (!$message) {
         $this->logger->warning('Message could not be generated');
         return;
     }
     $this->messageSender->send($message, $messageContext ? $messageContext->getSource() : null);
 }
 private function givenMessageWillBeFoundByContextValue()
 {
     $this->messageFinder->shouldReceive('findByReference')->with($this->contextValue)->andReturn($this->sourceMessage);
 }
 private function givenMessageMatchingContextExists()
 {
     $this->messageFinder->shouldReceive('findByReference')->with($this->contextValue)->andReturn($this->sourceMessage);
 }