bug #35162 [Mailer] Make sure you can pass custom headers to Mailgun (Nyholm)
This PR was squashed before being merged into the 4.4 branch.
Discussion
----------
[Mailer] Make sure you can pass custom headers to Mailgun
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | fix #35095
| License | MIT
| Doc PR |
I can only assume that there was a mistake to use `$header->toString()` since it makes no sense to include the header name here. That is why this is a bugfix and not a new feature.
Without this fix my test will fail:
```
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'{"foo":"bar"}'
+'X-Mailgun-Variables: {"foo":"bar"}'
```
There are a few similar places for other mailer bridges that looks like they have similar issues. I dont know those providers very well. I can spend time researching them and confirm if there are bugs there too. But first I want to make sure a fix like this is accepted.
Commits
-------
43c1e77a88
[Mailer] Make sure you can pass custom headers to Mailgun
This commit is contained in:
commit
ca69626dc9
@ -13,6 +13,9 @@ namespace Symfony\Component\Mailer\Bridge\Mailchimp\Tests\Transport;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillApiTransport;
|
||||
use Symfony\Component\Mailer\Envelope;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
class MandrillApiTransportTest extends TestCase
|
||||
{
|
||||
@ -41,4 +44,21 @@ class MandrillApiTransportTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testCustomHeader()
|
||||
{
|
||||
$email = new Email();
|
||||
$email->getHeaders()->addTextHeader('foo', 'bar');
|
||||
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
|
||||
|
||||
$transport = new MandrillApiTransport('ACCESS_KEY');
|
||||
$method = new \ReflectionMethod(MandrillApiTransport::class, 'getPayload');
|
||||
$method->setAccessible(true);
|
||||
$payload = $method->invoke($transport, $email, $envelope);
|
||||
|
||||
$this->assertArrayHasKey('message', $payload);
|
||||
$this->assertArrayHasKey('headers', $payload['message']);
|
||||
$this->assertCount(1, $payload['message']['headers']);
|
||||
$this->assertEquals('foo: bar', $payload['message']['headers'][0]);
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,7 @@ class MandrillApiTransport extends AbstractApiTransport
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload['message']['headers'][] = $name.': '.$header->toString();
|
||||
$payload['message']['headers'][] = $name.': '.$header->getBodyAsString();
|
||||
}
|
||||
|
||||
return $payload;
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Mailer\Bridge\Mailgun\Tests\Transport;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunApiTransport;
|
||||
use Symfony\Component\Mailer\Envelope;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
class MailgunApiTransportTest extends TestCase
|
||||
{
|
||||
@ -45,4 +48,20 @@ class MailgunApiTransportTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testCustomHeader()
|
||||
{
|
||||
$json = json_encode(['foo' => 'bar']);
|
||||
$email = new Email();
|
||||
$email->getHeaders()->addTextHeader('X-Mailgun-Variables', $json);
|
||||
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
|
||||
|
||||
$transport = new MailgunApiTransport('ACCESS_KEY', 'DOMAIN');
|
||||
$method = new \ReflectionMethod(MailgunApiTransport::class, 'getPayload');
|
||||
$method->setAccessible(true);
|
||||
$payload = $method->invoke($transport, $email, $envelope);
|
||||
|
||||
$this->assertArrayHasKey('h:x-mailgun-variables', $payload);
|
||||
$this->assertEquals($json, $payload['h:x-mailgun-variables']);
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ class MailgunApiTransport extends AbstractApiTransport
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload['h:'.$name] = $header->toString();
|
||||
$payload['h:'.$name] = $header->getBodyAsString();
|
||||
}
|
||||
|
||||
return $payload;
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Mailer\Bridge\Postmark\Tests\Transport;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkApiTransport;
|
||||
use Symfony\Component\Mailer\Envelope;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
class PostmarkApiTransportTest extends TestCase
|
||||
{
|
||||
@ -41,4 +44,21 @@ class PostmarkApiTransportTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testCustomHeader()
|
||||
{
|
||||
$email = new Email();
|
||||
$email->getHeaders()->addTextHeader('foo', 'bar');
|
||||
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
|
||||
|
||||
$transport = new PostmarkApiTransport('ACCESS_KEY');
|
||||
$method = new \ReflectionMethod(PostmarkApiTransport::class, 'getPayload');
|
||||
$method->setAccessible(true);
|
||||
$payload = $method->invoke($transport, $email, $envelope);
|
||||
|
||||
$this->assertArrayHasKey('Headers', $payload);
|
||||
$this->assertCount(1, $payload['Headers']);
|
||||
|
||||
$this->assertEquals(['Name' => 'foo', 'Value' => 'bar'], $payload['Headers'][0]);
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class PostmarkApiTransport extends AbstractApiTransport
|
||||
|
||||
$payload['Headers'][] = [
|
||||
'Name' => $name,
|
||||
'Value' => $header->toString(),
|
||||
'Value' => $header->getBodyAsString(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Mailer\Bridge\Sendgrid\Tests\Transport;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridApiTransport;
|
||||
use Symfony\Component\Mailer\Envelope;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
@ -149,4 +150,20 @@ class SendgridApiTransportTest extends TestCase
|
||||
|
||||
$mailer->send($email);
|
||||
}
|
||||
|
||||
public function testCustomHeader()
|
||||
{
|
||||
$email = new Email();
|
||||
$email->getHeaders()->addTextHeader('foo', 'bar');
|
||||
$envelope = new Envelope(new Address('alice@system.com'), [new Address('bob@system.com')]);
|
||||
|
||||
$transport = new SendgridApiTransport('ACCESS_KEY');
|
||||
$method = new \ReflectionMethod(SendgridApiTransport::class, 'getPayload');
|
||||
$method->setAccessible(true);
|
||||
$payload = $method->invoke($transport, $email, $envelope);
|
||||
|
||||
$this->assertArrayHasKey('headers', $payload);
|
||||
$this->assertArrayHasKey('foo', $payload['headers']);
|
||||
$this->assertEquals('bar', $payload['headers']['foo']);
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ class SendgridApiTransport extends AbstractApiTransport
|
||||
continue;
|
||||
}
|
||||
|
||||
$payload['headers'][$name] = $header->toString();
|
||||
$payload['headers'][$name] = $header->getBodyAsString();
|
||||
}
|
||||
|
||||
return $payload;
|
||||
|
Reference in New Issue
Block a user