Jelajahi Sumber

complete unit tests

Olivier Massot 1 tahun lalu
induk
melakukan
3a7368bfc1
1 mengubah file dengan 50 tambahan dan 0 penghapusan
  1. 50 0
      tests/Unit/Service/Mailer/MailerTest.php

+ 50 - 0
tests/Unit/Service/Mailer/MailerTest.php

@@ -143,6 +143,56 @@ class MailerTest extends TestCase
         $this->assertInstanceOf(Email::class, $emailsCollection->first());
     }
 
+    /**
+     * @see Mailer::main()
+     */
+    public function testMainWithReport()
+    {
+        $mailer = $this->makeMailerMock('main');
+        $mailerModel = $this->getMockBuilder(MailerModelInterface::class)->disableOriginalConstructor()->getMock();
+        $builderService = $this->getMockBuilder(BuilderInterface::class)->disableOriginalConstructor()->getMock();
+
+        $email = $this->getMockBuilder(Email::class)->disableOriginalConstructor()->getMock();
+        $email->method('getEmailRecipients')->willReturn(new ArrayCollection());
+        $email->method('getEmailEntity')->willReturn(new \App\Entity\Message\Email());
+
+        $emailsCollection = new ArrayCollection([$email]);
+
+        $this->builderIterator
+            ->method('getBuilderFor')
+            ->willReturn($builderService);
+
+        $builderService
+            ->method('build')
+            ->with($mailerModel)
+            ->willReturn($emailsCollection)
+        ;
+
+        $mailer
+            ->method('reduceEmailsCollectionInPreproduction')
+            ->with($emailsCollection)
+            ->willReturn($emailsCollection)
+        ;
+
+        $mailerModel->method('getSendReport')->willReturn(true);
+
+        $mailer
+            ->expects(self::once())
+            ->method('sendReport')
+        ;
+
+        $this->entityManager
+            ->expects(self::once())
+            ->method('flush')
+        ;
+
+        $emailsCollection = $mailer->main($mailerModel);
+
+        $this->assertEquals(MessageStatusEnum::NO_RECIPIENT, $email->getEmailEntity()->getStatus());
+
+        $this->assertInstanceOf(Email::class, $emailsCollection->first());
+    }
+
     /**
      * @see Mailer::send()
      */