Skip to content

Commit

Permalink
Merge pull request #69 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 e09ec2d + e113070 commit 47514cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,43 @@ class TransportBuilderTest extends \PHPUnit\Framework\TestCase
*/
protected $mailTransportFactoryMock;

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

/**
* @return void
*/
public function setUp()
{
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->templateFactoryMock = $this->createMock(\Magento\Framework\Mail\Template\FactoryInterface::class);
$this->messageMock = $this->createMock(\Magento\Framework\Mail\Message::class);
$this->messageMock = $this->getMockBuilder(\Magento\Framework\Mail\MessageInterface::class)
->disableOriginalConstructor()
->setMethods(['setBodyHtml', 'setSubject'])
->getMockForAbstractClass();
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$this->senderResolverMock = $this->createMock(\Magento\Framework\Mail\Template\SenderResolverInterface::class);
$this->mailTransportFactoryMock = $this->getMockBuilder(
\Magento\Framework\Mail\TransportInterfaceFactory::class
)->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
$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 @@ -108,7 +122,7 @@ public function testGetTransport(
$template->expects($this->once())
->method('getProcessedTemplate')
->with($vars)
->will($this->returnValue($bodyText));
->willReturn($bodyText);
$template->expects($this->once())
->method('setTemplateFilter')
->with($filter);
Expand All @@ -123,46 +137,8 @@ public function testGetTransport(
$this->returnValue($template)
);

$this->messageMock->expects(
$this->once()
)->method(
'setSubject'
)->with(
$this->equalTo('Email Subject')
)->will(
$this->returnSelf()
);
$this->messageMock->expects(
$this->once()
)->method(
'setBodyHtml'
)->with(
$this->equalTo($bodyText)
)->will(
$this->returnSelf()
);

$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);

$this->mailTransportFactoryMock->expects(
$this->at(0)
)->method(
'create'
)->with(
$this->equalTo(['message' => $this->messageMock])
)->will(
$this->returnValue($transport)
);

$this->objectManagerMock->expects(
$this->at(0)
)->method(
'create'
)->with(
$this->equalTo(\Magento\Framework\Mail\Message::class)
)->will(
$this->returnValue($transport)
);
$this->messageMock->expects($this->once())->method('setBodyHtml')->willReturnSelf();
$this->messageMock->expects($this->once())->method('setSubject')->willReturnSelf();

$this->builder->setTemplateIdentifier(
'identifier'
Expand All @@ -174,8 +150,6 @@ public function testGetTransport(
$data
);

$result = $this->builder->getTransport();

$this->assertInstanceOf(\Magento\Framework\Mail\TransportInterface::class, $result);
$this->builder->getTransport();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @api
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TransportBuilder
{
Expand Down Expand Up @@ -116,8 +117,7 @@ public function __construct(
$this->objectManager = $objectManager;
$this->_senderResolver = $senderResolver;
$this->mailTransportFactory = $mailTransportFactory;
$this->messageFactory = $messageFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(MessageInterfaceFactory::class);
$this->messageFactory = $messageFactory ?: $this->objectManager->get(MessageInterfaceFactory::class);
$this->message = $this->messageFactory->create();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Magento\Framework\Mail\MessageInterface;
use Magento\Framework\Mail\MessageInterfaceFactory;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TransportBuilderTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down

0 comments on commit 47514cc

Please sign in to comment.