/** * @dataProvider getTransportDataProvider * @param int $templateType * @param string $messageType * @param string $bodyText * @param string $templateNamespace * @return void */ public function testGetTransport($templateType, $messageType, $bodyText, $templateNamespace) { $this->builder->setTemplateModel($templateNamespace); $vars = ['reason' => 'Reason', 'customer' => 'Customer']; $options = ['area' => 'frontend', 'store' => 1]; $template = $this->getMock('\\Magento\\Framework\\Mail\\TemplateInterface'); $template->expects($this->once())->method('setVars')->with($this->equalTo($vars))->willReturnSelf(); $template->expects($this->once())->method('setOptions')->with($this->equalTo($options))->willReturnSelf(); $template->expects($this->once())->method('getSubject')->willReturn('Email Subject'); $template->expects($this->once())->method('getType')->willReturn($templateType); $template->expects($this->once())->method('processTemplate')->willReturn($bodyText); $this->templateFactoryMock->expects($this->once())->method('get')->with($this->equalTo('identifier'), $this->equalTo($templateNamespace))->willReturn($template); $this->messageMock->expects($this->once())->method('setSubject')->with($this->equalTo('Email Subject'))->willReturnSelf(); $this->messageMock->expects($this->once())->method('setMessageType')->with($this->equalTo($messageType))->willReturnSelf(); $this->messageMock->expects($this->once())->method('setBody')->with($this->equalTo($bodyText))->willReturnSelf(); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->mailTransportFactoryMock->expects($this->at(0))->method('create')->with($this->equalTo(['message' => $this->messageMock]))->willReturn($transport); $this->objectManagerMock->expects($this->at(0))->method('create')->with($this->equalTo('Magento\\Framework\\Mail\\Message'))->willReturn($transport); $this->builder->setTemplateIdentifier('identifier')->setTemplateVars($vars)->setTemplateOptions($options); $this->assertInstanceOf('Magento\\Framework\\Mail\\TransportInterface', $this->builder->getTransport()); }