Skip to content

Commit 8418ca2

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: [Mailer] Fix exception message on invalid event in `SendgridPayloadConverter`
2 parents fee0766 + 8d7f2d5 commit 8418ca2

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

src/Symfony/Component/Mailer/Bridge/Sendgrid/RemoteEvent/SendgridPayloadConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function convert(array $payload): AbstractMailerEvent
3939
'unsubscribe' => MailerEngagementEvent::UNSUBSCRIBE,
4040
'open' => MailerEngagementEvent::OPEN,
4141
'spamreport' => MailerEngagementEvent::SPAM,
42-
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['unsubscribe'])),
42+
default => throw new ParseException(sprintf('Unsupported event "%s".', $payload['event'])),
4343
};
4444
$event = new MailerEngagementEvent($name, $payload['sg_message_id'], $payload);
4545
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Symfony\Component\Mailer\Bridge\Sendgrid\Tests\RemoteEvent;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\Mailer\Bridge\Sendgrid\RemoteEvent\SendgridPayloadConverter;
7+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent;
8+
use Symfony\Component\RemoteEvent\Event\Mailer\MailerEngagementEvent;
9+
use Symfony\Component\RemoteEvent\Exception\ParseException;
10+
11+
class SendgridPayloadConverterTest extends TestCase
12+
{
13+
/**
14+
* @dataProvider provideDeliveryEvents
15+
*/
16+
public function testMailDeliveryEvent(string $event, string $expectedEventName)
17+
{
18+
$converter = new SendgridPayloadConverter();
19+
20+
$event = $converter->convert([
21+
'event' => $event,
22+
'sg_message_id' => '123456',
23+
'reason' => 'reason',
24+
'timestamp' => '123456789',
25+
'email' => 'test@example.com',
26+
]);
27+
28+
$this->assertInstanceOf(MailerDeliveryEvent::class, $event);
29+
$this->assertSame($expectedEventName, $event->getName());
30+
$this->assertSame('123456', $event->getId());
31+
$this->assertSame('reason', $event->getReason());
32+
$this->assertSame('test@example.com', $event->getRecipientEmail());
33+
}
34+
35+
public static function provideDeliveryEvents(): iterable
36+
{
37+
yield ['processed', MailerDeliveryEvent::DELIVERED];
38+
yield ['delivered', MailerDeliveryEvent::DELIVERED];
39+
yield ['bounce', MailerDeliveryEvent::BOUNCE];
40+
yield ['dropped', MailerDeliveryEvent::DROPPED];
41+
yield ['deferred', MailerDeliveryEvent::DEFERRED];
42+
}
43+
44+
/**
45+
* @dataProvider provideEngagementEvents
46+
*/
47+
public function testMailEngagementEvent(string $event, string $expectedEventName)
48+
{
49+
$converter = new SendgridPayloadConverter();
50+
51+
$event = $converter->convert([
52+
'event' => $event,
53+
'sg_message_id' => '123456',
54+
'timestamp' => '123456789',
55+
'email' => 'test@example.com',
56+
]);
57+
58+
$this->assertInstanceOf(MailerEngagementEvent::class, $event);
59+
$this->assertSame($expectedEventName, $event->getName());
60+
$this->assertSame('123456', $event->getId());
61+
}
62+
63+
public static function provideEngagementEvents(): iterable
64+
{
65+
yield ['click', MailerEngagementEvent::CLICK];
66+
yield ['unsubscribe', MailerEngagementEvent::UNSUBSCRIBE];
67+
yield ['open', MailerEngagementEvent::OPEN];
68+
yield ['spamreport', MailerEngagementEvent::SPAM];
69+
}
70+
71+
public function testUnsupportedEvent()
72+
{
73+
$converter = new SendgridPayloadConverter();
74+
75+
$this->expectException(ParseException::class);
76+
$this->expectExceptionMessage('Unsupported event "unsupported".');
77+
78+
$converter->convert([
79+
'event' => 'unsupported',
80+
'sg_message_id' => '123456',
81+
'timestamp' => '123456789',
82+
'email' => 'test@example.com',
83+
]);
84+
}
85+
86+
public function testInvalidDate()
87+
{
88+
$converter = new SendgridPayloadConverter();
89+
90+
$this->expectException(ParseException::class);
91+
$this->expectExceptionMessage('Invalid date "invalid".');
92+
93+
$converter->convert([
94+
'event' => 'processed',
95+
'sg_message_id' => '123456',
96+
'timestamp' => 'invalid',
97+
'email' => 'test@example.com',
98+
]);
99+
}
100+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy