Skip to content

Commit

Permalink
Merge pull request #10 from nucleos/patch-from
Browse files Browse the repository at this point in the history
Make from mail optional
  • Loading branch information
core23 committed Jan 31, 2020
2 parents 17d9f78 + 4bc7427 commit 25fcde5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ parameters:
count: 3
path: src/DependencyInjection/Configuration.php

-
message: "#^Return type \\(array\\<string\\>\\) of method Nucleos\\\\ProfileBundle\\\\EventListener\\\\AlreadyLoggedinListener\\:\\:getSubscribedEvents\\(\\) should be covariant with return type \\(array\\<string, array\\<int\\|string, array\\<int\\|string, int\\|string\\>\\|int\\|string\\>\\|string\\>\\) of method Symfony\\\\Component\\\\EventDispatcher\\\\EventSubscriberInterface\\:\\:getSubscribedEvents\\(\\)$#"
count: 1
path: src/EventListener/AlreadyLoggedinListener.php

2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function addRegistrationSection(ArrayNodeDefinition $node): void
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->scalarNode('from_email')->isRequired()->cannotBeEmpty()->end()
->scalarNode('from_email')->defaultNull()->end()
->end()
->end()
->end()
Expand Down
9 changes: 6 additions & 3 deletions src/Mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ final class Mailer implements MailerInterface
private $router;

/**
* @var string
* @var string|null
*/
private $fromEmail;

public function __construct(
SymfonyMailer $mailer,
TranslatorInterface $translator,
UrlGeneratorInterface $router,
string $fromEmail
?string $fromEmail
) {
$this->mailer = $mailer;
$this->translator = $translator;
Expand All @@ -65,7 +65,6 @@ public function sendConfirmationEmailMessage(UserInterface $user): void
);

$mail = (new ResettingMail())
->from(Address::fromString($this->fromEmail))
->to(new Address($user->getEmail()))
->subject($this->translator->trans('registration.email.subject', [
'%username%' => $user->getUsername(),
Expand All @@ -74,6 +73,10 @@ public function sendConfirmationEmailMessage(UserInterface $user): void
->setConfirmationUrl($url)
;

if (null !== $this->fromEmail) {
$mail->from(Address::fromString($this->fromEmail));
}

$this->mailer->send($mail);
}
}
18 changes: 1 addition & 17 deletions tests/DependencyInjection/NucleosProfileExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private function createEmptyConfiguration(): void
{
$this->configuration = new ContainerBuilder();
$loader = new NucleosProfileExtension();
$config = $this->getEmptyConfig();
$loader->load([$config], $this->configuration);
$loader->load([], $this->configuration);
static::assertInstanceOf(ContainerBuilder::class, $this->configuration);
}

Expand All @@ -88,21 +87,6 @@ private function createFullConfiguration(): void
static::assertInstanceOf(ContainerBuilder::class, $this->configuration);
}

/**
* @return array<mixed>
*/
private function getEmptyConfig(): array
{
$yaml = <<<'EOF'
registration:
confirmation:
from_email: register@acme.org
EOF;
$parser = new Parser();

return $parser->parse($yaml);
}

/**
* @return array<mixed>
*/
Expand Down

0 comments on commit 25fcde5

Please sign in to comment.