Skip to content

Commit

Permalink
Merge branch '6.3' into 6.4
Browse files Browse the repository at this point in the history
* 6.3:
  Add missing return type
  [HttpClient] Fix pausing responses before they start when using curl
  separate child and parent context in NotificationEmail on writes
  [Mailer] [Mailgun] Fix sender header encoding
  do not overwrite the cache key when it is false
  [Mailer] Throw TransportException when unable to read from socket
  [Serializer] Rewrite `AbstractObjectNormalizer::createChildContext()` to use the provided `cache_key` from original context when creating child contexts
  [HttpClient] Fix error chunk creation in passthru
  Adjusting and removing the 'review' attribute from the pt_br translation XML.
  [Serializer] Take unnamed variadic parameters into account when denormalizing
  Fix context data and display extra data
  • Loading branch information
nicolas-grekas committed Jan 29, 2024
2 parents 935cb2c + cdaa2d9 commit 46a0a7a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Mime/NotificationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ public function getHtmlTemplate(): ?string
return '@email/'.$this->theme.'/notification/body.html.twig';
}

/**
* @return $this
*/
public function context(array $context): static
{
$parentContext = [];

foreach ($context as $key => $value) {
if (\array_key_exists($key, $this->context)) {
$this->context[$key] = $value;
} else {
$parentContext[$key] = $value;
}
}

parent::context($parentContext);

return $this;
}

public function getContext(): array
{
return array_merge($this->context, parent::getContext());
Expand Down
50 changes: 50 additions & 0 deletions Tests/Mime/NotificationEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,54 @@ public function testPublicMailSubject()
$headers = $email->getPreparedHeaders();
$this->assertSame('Foo', $headers->get('Subject')->getValue());
}

public function testContext()
{
$email = new NotificationEmail();
$email->context(['some' => 'context']);

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => null,
'action_url' => null,
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
], $email->getContext());

$context = $email->getContext();
$context['foo'] = 'bar';
$email->context($context);

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => null,
'action_url' => null,
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
'foo' => 'bar',
], $email->getContext());

$email->action('Action Text', 'Action URL');

$this->assertSame([
'importance' => NotificationEmail::IMPORTANCE_LOW,
'content' => '',
'exception' => false,
'action_text' => 'Action Text',
'action_url' => 'Action URL',
'markdown' => false,
'raw' => false,
'footer_text' => 'Notification e-mail sent by Symfony',
'some' => 'context',
'foo' => 'bar',
], $email->getContext());
}
}

0 comments on commit 46a0a7a

Please sign in to comment.