Skip to content

Commit ebdb824

Browse files
committed
Add test for exceptionHandler property on RoundRobinTransport
1 parent 4e5bfa9 commit ebdb824

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Symfony/Component/Mailer/Tests/Transport/RoundRobinTransportTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,37 @@ public function testSendOneDeadAndRecoveryWithinRetryPeriod()
144144
$this->assertTransports($t, 1, []);
145145
}
146146

147+
public function testExceptionHandlerReceivesExceptions()
148+
{
149+
$t1 = $this->createMock(TransportInterface::class);
150+
$t1->expects($this->exactly(2))->method('send');
151+
152+
$t2 = $this->createMock(TransportInterface::class);
153+
$t2->expects($this->exactly(1))
154+
->method('send')
155+
->willReturnCallback(function () {
156+
throw new TransportException();
157+
});
158+
159+
$eh = $this
160+
->getMockBuilder(\stdClass::class)
161+
->addMethods(['__invoke'])
162+
->getMock();
163+
$eh->expects($this->exactly(1))
164+
->method('__invoke')
165+
->willReturnCallback(function (TransportExceptionInterface $e) {
166+
$this->assertInstanceOf(TransportException::class, $e);
167+
});
168+
169+
$t = new RoundRobinTransport([$t1, $t2], exceptionHandler: $eh);
170+
$p = new \ReflectionProperty($t, 'cursor');
171+
$p->setValue($t, 0);
172+
$t->send(new RawMessage(''));
173+
$this->assertTransports($t, 1, []);
174+
$t->send(new RawMessage(''));
175+
$this->assertTransports($t, 1, [$t2]);
176+
}
177+
147178
public function testFailureDebugInformation()
148179
{
149180
$t1 = $this->createMock(TransportInterface::class);

0 commit comments

Comments
 (0)