Пример #1
0
 /**
  * Check that email body is cached.
  * If do not, load it using appropriate email extension add it to a cache.
  *
  * @param Email $email
  */
 public function ensureEmailBodyCached(Email $email)
 {
     if ($email->getEmailBody() === null) {
         $this->emailBodySynchronizer->syncOneEmailBody($email);
         $this->em->flush();
     }
     $this->eventDispatcher->dispatch(EmailBodyLoaded::NAME, new EmailBodyLoaded($email));
 }
 public function testSync()
 {
     $email = new Email();
     $email->setSubject('Test email');
     $emailBody = new EmailBody();
     $emailUser = new EmailUser();
     $origin = new TestEmailOrigin();
     $folder = new EmailFolder();
     $folder->setOrigin($origin);
     $emailUser->setOrigin($origin);
     $emailUser->addFolder($folder);
     $email->addEmailUser($emailUser);
     $repo = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\EmailRepository')->disableOriginalConstructor()->getMock();
     $this->doctrine->expects($this->once())->method('getRepository')->willReturn($repo);
     $runCount = 0;
     $repo->expects($this->exactly(2))->method('getEmailsWithoutBody')->willReturnCallback(function () use(&$runCount, $email) {
         $runCount++;
         return $runCount === 1 ? [$email] : [];
     });
     $loader = $this->getMock('Oro\\Bundle\\EmailBundle\\Provider\\EmailBodyLoaderInterface');
     $this->selector->expects($this->once())->method('select')->with($this->identicalTo($origin))->will($this->returnValue($loader));
     $loader->expects($this->once())->method('loadEmailBody')->with($this->identicalTo($folder), $this->identicalTo($email), $this->identicalTo($this->em))->will($this->returnValue($emailBody));
     $this->em->expects($this->once())->method('persist')->with($this->identicalTo($email));
     $this->em->expects($this->once())->method('flush');
     $this->em->expects($this->once())->method('clear');
     $this->logger->expects($this->exactly(2))->method('notice');
     $this->logger->expects($this->never())->method('warning');
     $this->synchronizer->sync();
     $this->assertSame($emailBody, $email->getEmailBody());
 }