Skip to content

Commit

Permalink
bug #54712 [RemoteEvent] Fix date parsing remote event payload conver…
Browse files Browse the repository at this point in the history
…ter (alexandre-daubois)

This PR was merged into the 7.1 branch.

Discussion
----------

[RemoteEvent] Fix date parsing remote event payload converter

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

[AppVeyor fails](https://ci.appveyor.com/project/fabpot/symfony/builds/49679328) on some date expectation:

```diff
There was 1 failure:
1) Symfony\Component\Mailer\Bridge\Resend\Tests\Webhook\ResendRequestParserTest::testParse with data set "C:\projects\symfony\src\Symfony\Component\Mailer\Bridge\Resend\Tests\Webhook/Fixtures\sent.json" ('{\n    "created_at": "2024-04..."\n}\n', Symfony\Component\RemoteEvent\Event\Mailer\MailerDeliveryEvent Object (...))
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
     'name' => 'received'
     'id' => '172c41ce-ba6d-4281-8a7a-541faa725748'
     'payload' => Array (...)
-    'date' => 2024-04-08T09:43:09.500000-0700
+    'date' => 2024-04-08T09:43:09.500000+0000
     'email' => 'test@example.com'
     'metadata' => Array (...)
     'tags' => Array ()
     'reason' => ''
 )
C:\projects\symfony\src\Symfony\Component\Webhook\Test\AbstractRequestParserTestCase.php:32
```

Indeed, this can happen depending on your configuration because the timezone is not set when creating fixtures, which leads to a difference, as shown here: https://3v4l.org/iFBMq.

Defining the timezone in the parsing should solve this flaky test.

Commits
-------

98a7214 [Mailer] Fix date parsing remote event payload converter
  • Loading branch information
fabpot committed Apr 27, 2024
2 parents 65ccca0 + 98a7214 commit c834064
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function convert(array $payload): AbstractMailerEvent
$event = new MailerEngagementEvent($name, $this->getMessageId($payload), $payload);
}

if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', $payload['created_at'])) {
if (!$date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $payload['created_at'])) {
throw new ParseException(sprintf('Invalid date "%s".', $payload['created_at']));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
'ip' => '127.0.0.1',
'url' => 'https://www.mailersend.com'
]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
'ip' => '127.0.0.1',
'url' => 'https://www.mailersend.com'
]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(["test-tag"]);
$wh->setMetadata([]);
$wh->setReason('');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(["test-tag"]);
$wh->setMetadata([]);
$wh->setReason('Host or domain name not found');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
$wh->setMetadata([
'ip' => '127.0.0.1'
]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
$wh->setMetadata([
'ip' => '127.0.0.1'
]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(["test-tag"]);
$wh->setMetadata([]);
$wh->setReason('');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$wh->setTags(["test-tag"]);
$wh->setMetadata([]);
$wh->setReason('Unknown reason');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
$wh->setRecipientEmail('test@example.com');
$wh->setTags(["test-tag"]);
$wh->setMetadata([]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
'reason' => 'NO_LONGER_WANT',
'readable_reason' => 'I no longer want to receive these emails'
]);
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-01-01T12:00:00.000000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-01-01T12:00:00.000000Z'));

return $wh;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
],
]);
$wh->setReason('');
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.u\Z', '2024-04-08T09:43:09.500000Z'));
$wh->setDate(\DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', '2024-04-08T09:43:09.500000Z'));

return $wh;

0 comments on commit c834064

Please sign in to comment.