|
|
@@ -1,5 +1,9 @@
|
|
|
-<?php
|
|
|
+<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Entity\Core\ContactPoint;
|
|
|
+use App\Entity\Person\Person;
|
|
|
+use App\Service\Access\Utils as AccessUtils;
|
|
|
use App\Service\Core\ContactPointUtils;
|
|
|
use App\Service\MailHub;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
@@ -11,88 +15,92 @@ class MailHubTest extends TestCase
|
|
|
private MailerInterface $mailer;
|
|
|
private string $opentalentNoReplyEmailAddress;
|
|
|
private ContactPointUtils $contactPointUtils;
|
|
|
- private \App\Service\Access\Utils $accessUtils;
|
|
|
+ private AccessUtils $accessUtils;
|
|
|
|
|
|
public function setUp(): void {
|
|
|
$this->mailer = $this->getMockBuilder(MailerInterface::class)->disableOriginalConstructor()->getMock();
|
|
|
$this->opentalentNoReplyEmailAddress = 'noreply@opentalent.fr';
|
|
|
$this->contactPointUtils = $this->getMockBuilder(ContactPointUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->accessUtils = $this->getMockBuilder(\App\Service\Access\Utils::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $this->accessUtils = $this->getMockBuilder(AccessUtils::class)->disableOriginalConstructor()->getMock();
|
|
|
}
|
|
|
|
|
|
public function testSendAutomaticEmailTo(): void
|
|
|
{
|
|
|
- $contactPoint = $this->getMockBuilder(\App\Entity\Core\ContactPoint::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $mailerHub = $this->getMockBuilder(MailHub::class)
|
|
|
+ ->setConstructorArgs([$this->mailer, $this->opentalentNoReplyEmailAddress, $this->contactPointUtils, $this->accessUtils])
|
|
|
+ ->setMethodsExcept(['sendAutomaticEmailTo'])
|
|
|
+ ->getMock();
|
|
|
+
|
|
|
+ $contactPoint = $this->getMockBuilder(ContactPoint::class)->disableOriginalConstructor()->getMock();
|
|
|
$contactPoint->method('getEmail')->willReturn('mail@domain.net');
|
|
|
|
|
|
- $person = $this->getMockBuilder(\App\Entity\Person\Person::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $person = $this->getMockBuilder(Person::class)->disableOriginalConstructor()->getMock();
|
|
|
$person->method('getFullName')->willReturn('Don Diego de la Vega');
|
|
|
$person->method('getUsername')->willReturn('zorro2000');
|
|
|
|
|
|
- $access = $this->getMockBuilder(\App\Entity\Access\Access::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
|
|
|
$access->method('getPerson')->willReturn($person);
|
|
|
|
|
|
$this->contactPointUtils->expects(self::once())->method('getPersonContactPointPrincipal')->willReturn($contactPoint);
|
|
|
|
|
|
- $this->mailer->expects(self::once())
|
|
|
+ $this->mailer
|
|
|
+ ->expects(self::once())
|
|
|
->method('send')
|
|
|
->with(self::isInstanceOf(TemplatedEmail::class));
|
|
|
|
|
|
- $mailerHub = new MailHub(
|
|
|
- $this->mailer,
|
|
|
- $this->opentalentNoReplyEmailAddress,
|
|
|
- $this->contactPointUtils,
|
|
|
- $this->accessUtils
|
|
|
- );
|
|
|
-
|
|
|
$mailerHub->sendAutomaticEmailTo($access, 'subject', 'a_template', []);
|
|
|
}
|
|
|
|
|
|
public function testSendAutomaticEmailToButNoAddress(): void
|
|
|
{
|
|
|
- $access = $this->getMockBuilder(\App\Entity\Access\Access::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $mailerHub = $this->getMockBuilder(MailHub::class)
|
|
|
+ ->setConstructorArgs([$this->mailer, $this->opentalentNoReplyEmailAddress, $this->contactPointUtils, $this->accessUtils])
|
|
|
+ ->setMethodsExcept(['sendAutomaticEmailTo'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
- $this->contactPointUtils->expects(self::once())->method('getPersonContactPointPrincipal')->willReturn(null);
|
|
|
+ $access = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
- $mailerHub = new MailHub(
|
|
|
- $this->mailer,
|
|
|
- $this->opentalentNoReplyEmailAddress,
|
|
|
- $this->contactPointUtils,
|
|
|
- $this->accessUtils
|
|
|
- );
|
|
|
+ $this->contactPointUtils->expects(self::once())->method('getPersonContactPointPrincipal')->willReturn(null);
|
|
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|
|
|
$mailerHub->sendAutomaticEmailTo($access, 'subject', 'a_template', []);
|
|
|
}
|
|
|
|
|
|
- public function testSendAutomaticEmailToAdmin() {
|
|
|
+ public function testSendAutomaticEmailToAdmin(): void
|
|
|
+ {
|
|
|
+ $mailerHub = $this->getMockBuilder(MailHub::class)
|
|
|
+ ->setConstructorArgs([$this->mailer, $this->opentalentNoReplyEmailAddress, $this->contactPointUtils, $this->accessUtils])
|
|
|
+ ->setMethodsExcept(['sendAutomaticEmailToAdmin'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
$organization = $this->getMockBuilder(\App\Entity\Organization\Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
- $admin = $this->getMockBuilder(\App\Entity\Access\Access::class)->disableOriginalConstructor()->getMock();
|
|
|
+ $admin = $this->getMockBuilder(Access::class)->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
$this->accessUtils->expects(self::once())->method('findAdminFor')->with($organization)->willReturn($admin);
|
|
|
|
|
|
- $mailerHub = $this->getMockBuilder(MailHub::class)
|
|
|
- ->onlyMethods(['sendAutomaticEmailTo'])
|
|
|
- ->setConstructorArgs([$this->mailer, $this->opentalentNoReplyEmailAddress, $this->contactPointUtils, $this->accessUtils])
|
|
|
- ->getMock();
|
|
|
- $mailerHub->expects(self::once())->method('sendAutomaticEmailTo')->with($admin, 'subject', 'template', []);
|
|
|
+ $mailerHub
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('sendAutomaticEmailTo')
|
|
|
+ ->with($admin, 'subject', 'template', []);
|
|
|
|
|
|
$mailerHub->sendAutomaticEmailToAdmin($organization, 'subject', 'template', []);
|
|
|
}
|
|
|
|
|
|
- public function testSendAutomaticEmailToAdminButNoAdmin() {
|
|
|
+ public function testSendAutomaticEmailToAdminButNoAdmin(): void
|
|
|
+ {
|
|
|
+ $mailerHub = $this->getMockBuilder(MailHub::class)
|
|
|
+ ->setConstructorArgs([$this->mailer, $this->opentalentNoReplyEmailAddress, $this->contactPointUtils, $this->accessUtils])
|
|
|
+ ->setMethodsExcept(['sendAutomaticEmailToAdmin'])
|
|
|
+ ->getMock();
|
|
|
|
|
|
$organization = $this->getMockBuilder(\App\Entity\Organization\Organization::class)->disableOriginalConstructor()->getMock();
|
|
|
- $this->accessUtils->expects(self::once())->method('findAdminFor')->with($organization)->willReturn(null);
|
|
|
-
|
|
|
- $mailerHub = new MailHub(
|
|
|
- $this->mailer,
|
|
|
- $this->opentalentNoReplyEmailAddress,
|
|
|
- $this->contactPointUtils,
|
|
|
- $this->accessUtils
|
|
|
- );
|
|
|
+
|
|
|
+ $this->accessUtils
|
|
|
+ ->expects(self::once())
|
|
|
+ ->method('findAdminFor')
|
|
|
+ ->with($organization)
|
|
|
+ ->willReturn(null);
|
|
|
|
|
|
$this->expectException(\RuntimeException::class);
|
|
|
|