Skip to content

Commit 6c74e38

Browse files
committed
Merge remote-tracking branch 'origin/MC-18193' into 2.3-develop-pr28
2 parents a019da1 + cd80c7a commit 6c74e38

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ public function setTemplateOptions($templateOptions)
261261
*/
262262
public function getTransport()
263263
{
264-
$this->prepareMessage();
265-
$mailTransport = $this->mailTransportFactory->create(['message' => clone $this->message]);
266-
$this->reset();
264+
try {
265+
$this->prepareMessage();
266+
$mailTransport = $this->mailTransportFactory->create(['message' => clone $this->message]);
267+
} finally {
268+
$this->reset();
269+
}
267270

268271
return $mailTransport;
269272
}

lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,34 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
143143
$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $this->builder->getTransport());
144144
}
145145

146+
/**
147+
* Test get transport with exception
148+
*
149+
* @expectedException \Magento\Framework\Exception\LocalizedException
150+
* @expectedExceptionMessage Unknown template type
151+
*/
152+
public function testGetTransportWithException()
153+
{
154+
$this->builder->setTemplateModel('Test\Namespace\Template');
155+
156+
$vars = ['reason' => 'Reason', 'customer' => 'Customer'];
157+
$options = ['area' => 'frontend', 'store' => 1];
158+
159+
$template = $this->createMock(\Magento\Framework\Mail\TemplateInterface::class);
160+
$template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf();
161+
$template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf();
162+
$template->expects($this->once())->method('getType')->willReturn('Unknown');
163+
$this->messageFactoryMock->expects($this->once())->method('create');
164+
$this->templateFactoryMock->expects($this->once())
165+
->method('get')
166+
->with($this->equalTo('identifier'), $this->equalTo('Test\Namespace\Template'))
167+
->willReturn($template);
168+
169+
$this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options);
170+
171+
$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $this->builder->getTransport());
172+
}
173+
146174
/**
147175
* @return array
148176
*/

0 commit comments

Comments
 (0)