8000 [Messenger] add tests to FailedMessagesShowCommand · symfony/symfony@4b9b93f · GitHub
[go: up one dir, main page]

Skip to content

Commit 4b9b93f

Browse files
ahmedash95fabpot
authored andcommitted
[Messenger] add tests to FailedMessagesShowCommand
1 parent 53127c5 commit 4b9b93f

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

src/Symfony/Component/Messenger/Tests/Command/FailedMessagesShowCommandTest.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Messenger\Stamp\SentToFailureTransportStamp;
2020
use Symfony\Component\Messenger\Stamp\TransportMessageIdStamp;
2121
use Symfony\Component\Messenger\Transport\Receiver\ListableReceiverInterface;
22+
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
2223

2324
/**
2425
* @group time-sensitive
@@ -94,4 +95,101 @@ public function testMultipleRedeliveryFails()
9495
$redeliveryStamp2->getRedeliveredAt()->format('Y-m-d H:i:s')),
9596
$tester->getDisplay(true));
9697
}
98+
99+
public function testReceiverShouldBeListable()
100+
{
101+
$receiver = $this->createMock(ReceiverInterface::class);
102+
$command = new FailedMessagesShowCommand(
103+
'failure_receiver',
104+
$receiver
105+
);
106+
107+
$this->expectExceptionMessage('The "failure_receiver" receiver does not support listing or showing specific messages.');
108+
109+
$tester = new CommandTester($command);
110+
$tester->execute(['id' => 15]);
111+
}
112+
113+
public function testListMessages()
114+
{
115+
$sentToFailureStamp = new SentToFailureTransportStamp('async');
116+
$redeliveryStamp = new RedeliveryStamp(0, 'failure_receiver', 'Things are bad!');
117+
$envelope = new Envelope(new \stdClass(), [
118+
new TransportMessageIdStamp(15),
119+
$sentToFailureStamp,
120+
$redeliveryStamp,
121+
]);
122+
$receiver = $this->createMock(ListableReceiverInterface::class);
123+
$receiver->expects($this->once())->method('all')->with()->willReturn([$envelope]);
124+
125+
$command = new FailedMessagesShowCommand(
126+
'failure_receiver',
127+
$receiver
128+
);
129+
130+
$tester = new CommandTester($command);
131+
$tester->execute([]);
132+
$this->assertStringContainsString(sprintf(<<<EOF
133+
15 stdClass %s Things are bad!
134+
EOF
135+
,
136+
$redeliveryStamp->getRedeliveredAt()->format('Y-m-d H:i:s')),
137+
$tester->getDisplay(true));
138+
}
139+
140+
public function testListMessagesReturnsNoMessagesFound()
141+
{
142+
$receiver = $this->createMock(ListableReceiverInterface::class);
143+
$receiver->expects($this->once())->method('all')->with()->willReturn([]);
144+
145+
$command = new FailedMessagesShowCommand(
146+
'failure_receiver',
147+
$receiver
148+
);
149+
150+
$tester = new CommandTester($command);
151+
$tester->execute([]);
152+
$this->assertStringContainsString('[OK] No failed messages were found.', $tester->getDisplay(true));
153+
}
154+
155+
public function testListMessagesReturnsPaginatedMessages()
156+
{
157+
$sentToFailureStamp = new SentToFailureTransportStamp('async');
158+
$envelope = new Envelope(new \stdClass(), [
159+
new TransportMessageIdStamp(15),
160+
$sentToFailureStamp,
161+
new RedeliveryStamp(0, 'failure_receiver', 'Things are bad!'),
162+
]);
163+
$receiver = $this->createMock(ListableReceiverInterface::class);
164+
$receiver->expects($this->once())->method('all')->with()->willReturn([$envelope]);
165+
166+
$command = new FailedMessagesShowCommand(
167+
'failure_receiver',
168+
$receiver
169+
);
170+
171+
$tester = new CommandTester($command);
172+
$tester->execute(['--max' => 1]);
173+
$this->assertStringContainsString('Showing first 1 messages.', $tester->getDisplay(true));
174+
}
175+
176+
public function testInvalidMessagesThrowsException()
177+
{
178+
$sentToFailureStamp = new SentToFailureTransportStamp('async');
179+
$envelope = new Envelope(new \stdClass(), [
180+
new TransportMessageIdStamp(15),
181+
$sentToFailureStamp,
182+
]);
183+
$receiver = $this->createMock(ListableReceiverInterface::class);
184+
185+
$command = new FailedMessagesShowCommand(
186+
'failure_receiver',
187+
$receiver
188+
);
189+
190+
$this->expectExceptionMessage('The message "15" was not found.');
191+
192+
$tester = new CommandTester($command);
193+
$tester->execute(['id' => 15]);
194+
}
97195
}

0 commit comments

Comments
 (0)
0