1010use App \Service \MailService ;
1111use PHPUnit \Framework \Attributes \DataProvider ;
1212use Symfony \Bundle \FrameworkBundle \Test \KernelTestCase ;
13+ use Symfony \Bundle \SecurityBundle \Security ;
1314use Symfony \Component \Mailer \MailerInterface ;
1415use Symfony \Contracts \Translation \TranslatorInterface ;
1516use Twig \Environment ;
@@ -23,6 +24,7 @@ class MailServiceTest extends KernelTestCase {
2324
2425 private Camp $ camp ;
2526 private User $ user ;
27+ private Security $ security ;
2628
2729 private MailService $ mailer ;
2830
@@ -33,7 +35,15 @@ protected function setUp(): void {
3335 $ translator = self ::getContainer ()->get (TranslatorInterface::class);
3436 $ twigEnvironment = self ::getContainer ()->get (Environment::class);
3537
36- $ this ->
mailer =
new MailService (
$ mailer,
$ translator,
$ twigEnvironment,
'frontend.example.com ' ,
'[email protected] ' ,
'SenderName ' );
38+ $ this ->security = $ this ->createMock (Security::class);
39+ $ profile = new Profile ();
40+ $ profile ->nickname = 'Linux ' ;
41+ $ profile->
email =
'[email protected] ' ;
42+ $ user = new User ();
43+ $ user ->profile = $ profile ;
44+ $ this ->security ->method ('getUser ' )->willReturn ($ user );
45+
46+ $ this ->
mailer =
new MailService (
$ mailer,
$ translator,
$ twigEnvironment,
'frontend.example.com ' ,
'[email protected] ' ,
'SenderName ' ,
$ this ->
security );
3747
3848 $ this ->user = new User ();
3949 $ profile = new Profile ();
@@ -52,6 +62,7 @@ public function testSendInviteToCampMailDeChScout() {
5262 self ::assertEmailCount (1 );
5363 $ mailerMessage = self ::getMailerMessage (0 );
5464 self ::assertEmailAddressContains ($ mailerMessage , 'To ' , self ::INVITE_MAIL );
65+ self ::
assertEmailAddressContains (
$ mailerMessage,
'reply-to ' ,
'[email protected] ' );
5566 self ::assertEmailHeaderSame ($ mailerMessage , 'subject ' , '[eCamp v3] Du wurdest ins Lager "some camp title" eingeladen ' );
5667
5768 self ::assertEmailHtmlBodyContains ($ mailerMessage , $ this ->camp ->title );
@@ -71,6 +82,7 @@ public function testSendInvitationMailDoesNotCrashForAllLanguages(string $langua
7182 self ::assertEmailCount (1 );
7283 $ mailerMessage = self ::getMailerMessage (0 );
7384 self ::assertEmailAddressContains ($ mailerMessage , 'To ' , self ::INVITE_MAIL );
85+ self ::
assertEmailAddressContains (
$ mailerMessage,
'reply-to ' ,
'[email protected] ' );
7486
7587 self ::assertEmailHtmlBodyContains ($ mailerMessage , $ this ->camp ->title );
7688 self ::assertEmailHtmlBodyContains ($ mailerMessage , $ this ->user ->getDisplayName ());
0 commit comments