Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Scheduler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Allow setting timezone of next run date in CronExpressionTrigger
* Add `AbstractTriggerDecorator`
* Make `ScheduledStamp` "send-able"
* Add `ScheduledStamp` to `RedispatchMessage`

6.3
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Scheduler\Messenger;

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Message\RedispatchMessage;
use Symfony\Component\Messenger\Transport\TransportInterface;
use Symfony\Component\Scheduler\Exception\LogicException;
use Symfony\Component\Scheduler\Generator\MessageGeneratorInterface;
Expand All @@ -29,7 +30,16 @@ public function __construct(
public function get(): iterable
{
foreach ($this->messageGenerator->getMessages() as $context => $message) {
yield Envelope::wrap($message, [new ScheduledStamp($context)]);
$stamp = new ScheduledStamp($context);

if ($message instanceof RedispatchMessage) {
$message = new RedispatchMessage(
Envelope::wrap($message->envelope, [$stamp]),
$message->transportNames,
);
}

yield Envelope::wrap($message, [$stamp]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Message\RedispatchMessage;
use Symfony\Component\Scheduler\Exception\LogicException;
use Symfony\Component\Scheduler\Generator\MessageContext;
use Symfony\Component\Scheduler\Generator\MessageGeneratorInterface;
Expand All @@ -28,9 +29,7 @@ public function testGetFromIterator()
(object) ['id' => 'first'],
(object) ['id' => 'second'],
];
$generator = $this->createMock(MessageGeneratorInterface::class, [
'getMessages' => $messages,
]);
$generator = $this->createMock(MessageGeneratorInterface::class);
$generator->method('getMessages')->willReturnCallback(function () use ($messages): \Generator {
$trigger = $this->createMock(TriggerInterface::class);
$triggerAt = new \DateTimeImmutable('2020-02-20T02:00:00', new \DateTimeZone('UTC'));
Expand All @@ -50,6 +49,22 @@ public function testGetFromIterator()
$this->assertEmpty($messages);
}

public function testAddsStampToInnerRedispatchMessageEnvelope()
{
$generator = $this->createMock(MessageGeneratorInterface::class);
$generator->method('getMessages')->willReturnCallback(function (): \Generator {
yield new MessageContext('default', 'id', $this->createMock(TriggerInterface::class), new \DateTimeImmutable()) =>
new RedispatchMessage(new \stdClass(), ['transport']);
});
$envelopes = \iterator_to_array((new SchedulerTransport($generator))->get());

$stamp = $envelopes[0]->getMessage()->envelope->last(ScheduledStamp::class);

$this->assertSame($stamp, $envelopes[0]->last(ScheduledStamp::class));
$this->assertSame('default', $stamp->messageContext->name);
$this->assertSame('id', $stamp->messageContext->id);
}

public function testAckIgnored()
{
$transport = new SchedulerTransport($this->createMock(MessageGeneratorInterface::class));
Expand Down