Skip to content
This repository has been archived by the owner on Apr 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #64 from magento-epam/MAGETWO-91493
Browse files Browse the repository at this point in the history
MAGETWO-91493: MDC Framework Issues. Message passed as a service to T…
  • Loading branch information
nikshostko authored Aug 17, 2018
2 parents 7058877 + 51b29a5 commit 5191b90
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
18 changes: 15 additions & 3 deletions lib/internal/Magento/Framework/Mail/Template/TransportBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\App\TemplateTypesInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Mail\MessageInterface;
use Magento\Framework\Mail\MessageInterfaceFactory;
use Magento\Framework\Mail\TransportInterfaceFactory;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Phrase;
Expand Down Expand Up @@ -88,25 +89,36 @@ class TransportBuilder
*/
protected $mailTransportFactory;

/**
* @var \Magento\Framework\Mail\MessageInterfaceFactory
*/
private $messageFactory;

/**
* @param FactoryInterface $templateFactory
* @param MessageInterface $message
* @param SenderResolverInterface $senderResolver
* @param ObjectManagerInterface $objectManager
* @param TransportInterfaceFactory $mailTransportFactory
* @param MessageInterfaceFactory $messageFactory
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
FactoryInterface $templateFactory,
MessageInterface $message,
SenderResolverInterface $senderResolver,
ObjectManagerInterface $objectManager,
TransportInterfaceFactory $mailTransportFactory
TransportInterfaceFactory $mailTransportFactory,
MessageInterfaceFactory $messageFactory = null
) {
$this->templateFactory = $templateFactory;
$this->message = $message;
$this->objectManager = $objectManager;
$this->_senderResolver = $senderResolver;
$this->mailTransportFactory = $mailTransportFactory;
$this->messageFactory = $messageFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(MessageInterfaceFactory::class);
$this->message = $this->messageFactory->create();
}

/**
Expand Down Expand Up @@ -242,7 +254,7 @@ public function getTransport()
*/
protected function reset()
{
$this->message = $this->objectManager->create(\Magento\Framework\Mail\Message::class);
$this->message = $this->messageFactory->create();
$this->templateIdentifier = null;
$this->templateVars = null;
$this->templateOptions = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Magento\Framework\App\TemplateTypesInterface;
use Magento\Framework\Mail\MessageInterface;
use Magento\Framework\Mail\MessageInterfaceFactory;

class TransportBuilderTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -41,6 +42,11 @@ class TransportBuilderTest extends \PHPUnit\Framework\TestCase
*/
protected $senderResolverMock;

/**
* @var \Magento\Framework\Mail\MessageInterfaceFactory| \PHPUnit_Framework_MockObject_MockObject
*/
private $messageFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand All @@ -60,15 +66,21 @@ protected function setUp()
\Magento\Framework\Mail\TransportInterfaceFactory::class
)->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
->getMockForAbstractClass();
$this->messageFactoryMock = $this->getMockBuilder(\Magento\Framework\Mail\MessageInterfaceFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMockForAbstractClass();
$this->messageFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->messageMock);
$this->builder = $objectManagerHelper->getObject(
$this->builderClassName,
[
'templateFactory' => $this->templateFactoryMock,
'message' => $this->messageMock,
'objectManager' => $this->objectManagerMock,
'senderResolver' => $this->senderResolverMock,
'mailTransportFactory' => $this->mailTransportFactoryMock
'mailTransportFactory' => $this->mailTransportFactoryMock,
'messageFactory' => $this->messageFactoryMock
]
);
}
Expand Down Expand Up @@ -122,10 +134,7 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
->with($this->equalTo(['message' => $this->messageMock]))
->willReturn($transport);

$this->objectManagerMock->expects($this->at(0))
->method('create')
->with($this->equalTo(\Magento\Framework\Mail\Message::class))
->willReturn($transport);
$this->messageFactoryMock->expects($this->once())->method('create')->willReturn($transport);

$this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options);
$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $this->builder->getTransport());
Expand Down

0 comments on commit 5191b90

Please sign in to comment.