Skip to content

Commit f570ebf

Browse files
author
Oleksii Korshenko
committed
MAGETWO-67680: Replace Zend_Mail (ZF1) with Zend\Mail (ZF2) #8608
- code review changes
1 parent 212632f commit f570ebf

File tree

6 files changed

+39
-79
lines changed

6 files changed

+39
-79
lines changed

app/code/Magento/Newsletter/Model/Template.php

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@
3838
*/
3939
class Template extends \Magento\Email\Model\AbstractTemplate
4040
{
41+
/**
42+
* Mail object
43+
*
44+
* @deprecated Unused property
45+
*
46+
*/
47+
protected $_mail;
4148

4249
/**
4350
* Store manager to emulate design

lib/internal/Magento/Framework/Mail/MailMessageInterface.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
interface MailMessageInterface extends MessageInterface
1414
{
1515
/**
16+
* Set mail message body in HTML format.
17+
*
1618
* @param string $html
1719
* @return $this
1820
*/
1921
public function setBodyHtml($html);
2022

2123
/**
24+
* Set mail message body in text format.
25+
*
2226
* @param string $text
2327
* @return $this
2428
*/
2529
public function setBodyText($text);
2630

2731
/**
28-
* Get message source code
32+
* Get message source code.
2933
*
3034
* @return string
3135
*/

lib/internal/Magento/Framework/Mail/Message.php

+11-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Message implements MailMessageInterface
2525
*
2626
* @var string
2727
*/
28-
protected $messageType = self::TYPE_TEXT;
28+
private $messageType = self::TYPE_TEXT;
2929

3030
/**
3131
* Initialize dependencies.
@@ -68,8 +68,7 @@ public function setBody($body)
6868
}
6969

7070
/**
71-
* @param string $subject
72-
* @return $this
71+
* {@inheritdoc}
7372
*/
7473
public function setSubject($subject)
7574
{
@@ -78,7 +77,7 @@ public function setSubject($subject)
7877
}
7978

8079
/**
81-
* @return null|string
80+
* {@inheritdoc}
8281
*/
8382
public function getSubject()
8483
{
@@ -94,8 +93,7 @@ public function getBody()
9493
}
9594

9695
/**
97-
* @param array|string $fromAddress
98-
* @return $this
96+
* {@inheritdoc}
9997
*/
10098
public function setFrom($fromAddress)
10199
{
@@ -104,8 +102,7 @@ public function setFrom($fromAddress)
104102
}
105103

106104
/**
107-
* @param array|string $toAddress
108-
* @return $this
105+
* {@inheritdoc}
109106
*/
110107
public function addTo($toAddress)
111108
{
@@ -114,8 +111,7 @@ public function addTo($toAddress)
114111
}
115112

116113
/**
117-
* @param array|string $ccAddress
118-
* @return $this
114+
* {@inheritdoc}
119115
*/
120116
public function addCc($ccAddress)
121117
{
@@ -124,8 +120,7 @@ public function addCc($ccAddress)
124120
}
125121

126122
/**
127-
* @param array|string $bccAddress
128-
* @return $this
123+
* {@inheritdoc}
129124
*/
130125
public function addBcc($bccAddress)
131126
{
@@ -134,8 +129,7 @@ public function addBcc($bccAddress)
134129
}
135130

136131
/**
137-
* @param array|string $replyToAddress
138-
* @return $this
132+
* {@inheritdoc}
139133
*/
140134
public function setReplyTo($replyToAddress)
141135
{
@@ -144,14 +138,16 @@ public function setReplyTo($replyToAddress)
144138
}
145139

146140
/**
147-
* @return string
141+
* {@inheritdoc}
148142
*/
149143
public function getRawMessage()
150144
{
151145
return $this->zendMessage->toString();
152146
}
153147

154148
/**
149+
* Create HTML mime message from the string.
150+
*
155151
* @param string $htmlBody
156152
* @return \Zend\Mime\Message
157153
*/

lib/internal/Magento/Framework/Mail/MessageInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Mail Message interface
1010
*
1111
* @api
12-
* @deprecated
12+
* @deprecated in favor of MailMessageInterface to avoid temporal coupling (setMessageType + setBody)
1313
* @see \Magento\Framework\Mail\MailMessageInterface
1414
*/
1515
interface MessageInterface

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

-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ protected function prepareMessage()
284284
throw new LocalizedException(
285285
new Phrase('Unknown template type')
286286
);
287-
break;
288287
}
289288
$this->message->setSubject(html_entity_decode($template->getSubject(), ENT_QUOTES));
290289
return $this;

lib/internal/Magento/Framework/Mail/Test/Unit/MessageTest.php

+15-61
Original file line numberDiff line numberDiff line change
@@ -8,87 +8,41 @@
88
class MessageTest extends \PHPUnit_Framework_TestCase
99
{
1010
/**
11-
* @var \PHPUnit_Framework_MockObject
11+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Mail\Message
1212
*/
1313
protected $_messageMock;
1414

1515
protected function setUp()
1616
{
17-
$this->markTestSkipped('obsolete ZF 1 test');
1817
$this->_messageMock = $this->getMock(
1918
\Magento\Framework\Mail\Message::class,
20-
['getBodyText', 'getBodyHtml', 'setBodyText', 'setBodyHtml']
19+
['setBody', 'setMessageType']
2120
);
2221
}
2322

24-
/**
25-
* @param string $messageType
26-
* @param string $method
27-
*
28-
* @covers \Magento\Framework\Mail\Message::setBody
29-
* @covers \Magento\Framework\Mail\Message::setMessageType
30-
* @dataProvider setBodyDataProvider
31-
*/
32-
public function testSetBody($messageType, $method)
23+
public function testSetBodyHtml()
3324
{
34-
$this->_messageMock->setMessageType($messageType);
25+
$this->_messageMock->expects($this->once())
26+
->method('setMessageType')
27+
->with('text/html');
3528

3629
$this->_messageMock->expects($this->once())
37-
->method($method)
30+
->method('setBody')
3831
->with('body');
3932

40-
$this->_messageMock->setBody('body');
33+
$this->_messageMock->setBodyHtml('body');
4134
}
4235

43-
/**
44-
* @return array
45-
*/
46-
public function setBodyDataProvider()
36+
public function testSetBodyText()
4737
{
48-
return [
49-
[
50-
'messageType' => 'text/plain',
51-
'method' => 'setBodyText',
52-
],
53-
[
54-
'messageType' => 'text/html',
55-
'method' => 'setBodyHtml'
56-
]
57-
];
58-
}
59-
60-
/**
61-
* @param string $messageType
62-
* @param string $method
63-
*
64-
* @covers \Magento\Framework\Mail\Message::getBody
65-
* @covers \Magento\Framework\Mail\Message::setMessageType
66-
* @dataProvider getBodyDataProvider
67-
*/
68-
public function testGetBody($messageType, $method)
69-
{
70-
$this->_messageMock->setMessageType($messageType);
71-
7238
$this->_messageMock->expects($this->once())
73-
->method($method);
39+
->method('setMessageType')
40+
->with('text/plain');
7441

75-
$this->_messageMock->getBody('body');
76-
}
42+
$this->_messageMock->expects($this->once())
43+
->method('setBody')
44+
->with('body');
7745

78-
/**
79-
* @return array
80-
*/
81-
public function getBodyDataProvider()
82-
{
83-
return [
84-
[
85-
'messageType' => 'text/plain',
86-
'method' => 'getBodyText',
87-
],
88-
[
89-
'messageType' => 'text/html',
90-
'method' => 'getBodyHtml'
91-
]
92-
];
46+
$this->_messageMock->setBodyText('body');
9347
}
9448
}

0 commit comments

Comments
 (0)