templateFactoryMock = $this->createMock(\Magento\Framework\Mail\Template\FactoryInterface::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, 'messageFactory' => $this->messageFactoryMock ] ); } /** * @param int $templateType * @param string $bodyText * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function testGetTransport( $templateType = TemplateTypesInterface::TYPE_HTML, $bodyText = '

Html message

' ) { $filter = $this->createMock(\Magento\Email\Model\Template\Filter::class); $data = [ 'template_subject' => 'Email Subject', 'template_text' => $bodyText, 'template_styles' => 'Styles', 'template_type' => $templateType, 'template_filter' => $filter, ]; $vars = ['reason' => 'Reason', 'customer' => 'Customer']; $options = ['area' => 'frontend', 'store' => 1]; $template = $this->createMock(\Magento\Email\Model\Template::class); $template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->will($this->returnSelf()); $template->expects( $this->once() )->method( 'setOptions' )->with( $this->equalTo($options) )->will( $this->returnSelf() ); $template->expects($this->once())->method('getSubject')->will($this->returnValue('Email Subject')); $template->expects($this->once())->method('setData')->with($this->equalTo($data))->will($this->returnSelf()); $template->expects($this->once()) ->method('getProcessedTemplate') ->with($vars) ->willReturn($bodyText); $template->expects($this->once()) ->method('setTemplateFilter') ->with($filter); $this->templateFactoryMock->expects( $this->once() )->method( 'get' )->with( $this->equalTo('identifier') )->will( $this->returnValue($template) ); $this->messageMock->expects($this->once())->method('setBodyHtml')->willReturnSelf(); $this->messageMock->expects($this->once())->method('setSubject')->willReturnSelf(); $this->builder->setTemplateIdentifier( 'identifier' )->setTemplateVars( $vars )->setTemplateOptions( $options )->setTemplateData( $data ); $this->builder->getTransport(); } }