/**
  * It should update the locale if the requested locale is different from the loaded locale.
  */
 public function testUpdateDocumentLocale()
 {
     $locale = 'de';
     $originalLocale = 'fr';
     $this->hydrateEvent->hasDocument()->willReturn(true);
     $this->hydrateEvent->getLocale()->willReturn($locale);
     $this->hydrateEvent->getDocument()->willReturn($this->document);
     $this->registry->isHydrated($this->document)->willReturn(true);
     $this->registry->getOriginalLocaleForDocument($this->document)->willReturn($originalLocale);
     $this->hydrateEvent->stopPropagation()->shouldNotBeCalled();
     $this->registry->updateLocale($this->document, $locale, $locale)->shouldBeCalled();
     $this->subscriber->handleStopPropagationAndResetLocale($this->hydrateEvent->reveal());
 }
 /**
  * Stop propagation if the document is already loaded in the requested locale,
  * otherwise reset the document locale to the new locale.
  *
  * @param HydrateEvent $event
  */
 public function handleStopPropagationAndResetLocale(HydrateEvent $event)
 {
     if (!$event->hasDocument()) {
         return;
     }
     $locale = $event->getLocale();
     $document = $event->getDocument();
     $originalLocale = $this->documentRegistry->getOriginalLocaleForDocument($document);
     if (true === $this->documentRegistry->isHydrated($document) && $originalLocale === $locale) {
         $event->stopPropagation();
         return;
     }
     $this->documentRegistry->updateLocale($document, $locale, $locale);
 }