1
- <?php
1
+ <?php /** @noinspection PhpDeprecationInspection */
2
+ /** @noinspection PhpUndefinedClassInspection */
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
7
8
8
9
namespace Magento \Newsletter \Test \Unit \Model \Queue ;
9
10
11
+ use Magento \Email \Model \Template ;
12
+ use Magento \Email \Model \Template \Filter ;
10
13
use Magento \Framework \App \TemplateTypesInterface ;
14
+ use Magento \Framework \Mail \EmailMessageInterface ;
15
+ use Magento \Framework \Mail \EmailMessageInterfaceFactory ;
16
+ use Magento \Framework \Mail \Message ;
11
17
use Magento \Framework \Mail \MessageInterface ;
18
+ use Magento \Framework \Mail \MessageInterfaceFactory ;
19
+ use Magento \Framework \Mail \MimePartInterface ;
20
+ use Magento \Framework \Mail \MimePartInterfaceFactory ;
21
+ use Magento \Framework \Mail \Template \FactoryInterface ;
22
+ use Magento \Framework \Mail \Template \SenderResolverInterface ;
23
+ use Magento \Framework \Mail \TransportInterfaceFactory ;
24
+ use Magento \Framework \ObjectManagerInterface ;
25
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
26
+ use Magento \Newsletter \Model \Queue \TransportBuilder ;
27
+ use PHPUnit \Framework \MockObject \MockObject ;
28
+ use PHPUnit \Framework \TestCase ;
29
+ use PHPUnit_Framework_MockObject_MockObject ;
12
30
13
31
/**
14
32
* Class TransportBuilderTest
15
33
*/
16
- class TransportBuilderTest extends \ PHPUnit \ Framework \ TestCase
34
+ class TransportBuilderTest extends TestCase
17
35
{
18
36
/**
19
37
* @var string
20
38
*/
21
- protected $ builderClassName = \ Magento \ Newsletter \ Model \ Queue \ TransportBuilder::class;
39
+ protected $ builderClassName = TransportBuilder::class;
22
40
23
41
/**
24
- * @var \Magento\Newsletter\Model\Queue\ TransportBuilder
42
+ * @var TransportBuilder
25
43
*/
26
44
protected $ builder ;
27
45
28
46
/**
29
- * @var \Magento\Framework\Mail\Template\ FactoryInterface | \ PHPUnit_Framework_MockObject_MockObject
47
+ * @var FactoryInterface| PHPUnit_Framework_MockObject_MockObject
30
48
*/
31
49
protected $ templateFactoryMock ;
32
50
33
51
/**
34
- * @var \Magento\Framework\Mail\ Message | \ PHPUnit_Framework_MockObject_MockObject
52
+ * @var Message| PHPUnit_Framework_MockObject_MockObject
35
53
*/
36
54
protected $ messageMock ;
37
55
38
56
/**
39
- * @var \Magento\Framework\ ObjectManagerInterface | \ PHPUnit_Framework_MockObject_MockObject
57
+ * @var ObjectManagerInterface| PHPUnit_Framework_MockObject_MockObject
40
58
*/
41
59
protected $ objectManagerMock ;
42
60
43
61
/**
44
- * @var \Magento\Framework\Mail\Template\ SenderResolverInterface | \ PHPUnit_Framework_MockObject_MockObject
62
+ * @var SenderResolverInterface| PHPUnit_Framework_MockObject_MockObject
45
63
*/
46
64
protected $ senderResolverMock ;
47
65
48
66
/**
49
- * @var \ PHPUnit_Framework_MockObject_MockObject
67
+ * @var PHPUnit_Framework_MockObject_MockObject
50
68
*/
51
69
protected $ mailTransportFactoryMock ;
52
70
53
71
/**
54
- * @var \Magento\Framework\Mail\ MessageInterfaceFactory | \ PHPUnit_Framework_MockObject_MockObject
72
+ * @var MessageInterfaceFactory| PHPUnit_Framework_MockObject_MockObject
55
73
*/
56
74
private $ messageFactoryMock ;
57
75
76
+ /**
77
+ * @var MockObject
78
+ */
79
+ private $ emailMessageInterfaceFactoryMock ;
80
+
81
+ /**
82
+ * @var MockObject
83
+ */
84
+ private $ mimePartFactoryMock ;
85
+
58
86
/**
59
87
* @return void
60
88
*/
61
- public function setUp ()
89
+ public function setUp (): void
62
90
{
63
- $ objectManagerHelper = new \ Magento \ Framework \ TestFramework \ Unit \ Helper \ ObjectManager ($ this );
64
- $ this ->templateFactoryMock = $ this ->createMock (\ Magento \ Framework \ Mail \ Template \ FactoryInterface::class);
65
- $ this ->messageMock = $ this ->getMockBuilder (\ Magento \ Framework \ Mail \ MessageInterface::class)
91
+ $ objectManagerHelper = new ObjectManager ($ this );
92
+ $ this ->templateFactoryMock = $ this ->createMock (FactoryInterface::class);
93
+ $ this ->messageMock = $ this ->getMockBuilder (MessageInterface::class)
66
94
->disableOriginalConstructor ()
67
95
->setMethods (['setBodyHtml ' , 'setSubject ' ])
68
96
->getMockForAbstractClass ();
69
- $ this ->objectManagerMock = $ this ->createMock (\Magento \Framework \ObjectManagerInterface::class);
70
- $ this ->senderResolverMock = $ this ->createMock (\Magento \Framework \Mail \Template \SenderResolverInterface::class);
71
- $ this ->mailTransportFactoryMock = $ this ->getMockBuilder (
72
- \Magento \Framework \Mail \TransportInterfaceFactory::class
73
- )->disableOriginalConstructor ()
97
+
98
+ $ this ->emailMessageInterfaceFactoryMock = $ this ->createMock (EmailMessageInterfaceFactory::class);
99
+ $ this ->mimePartFactoryMock = $ this ->createMock (MimePartInterfaceFactory::class);
100
+
101
+ $ this ->objectManagerMock = $ this ->createMock (ObjectManagerInterface::class);
102
+ $ this ->senderResolverMock = $ this ->createMock (SenderResolverInterface::class);
103
+ $ this ->mailTransportFactoryMock = $ this ->getMockBuilder (TransportInterfaceFactory::class)
104
+ ->disableOriginalConstructor ()
74
105
->setMethods (['create ' ])
75
106
->getMock ();
76
107
@@ -82,7 +113,9 @@ public function setUp()
82
113
'objectManager ' => $ this ->objectManagerMock ,
83
114
'senderResolver ' => $ this ->senderResolverMock ,
84
115
'mailTransportFactory ' => $ this ->mailTransportFactoryMock ,
85
- 'messageFactory ' => $ this ->messageFactoryMock
116
+ 'messageFactory ' => $ this ->messageFactoryMock ,
117
+ 'emailMessageInterfaceFactory ' => $ this ->emailMessageInterfaceFactoryMock ,
118
+ 'mimePartInterfaceFactory ' => $ this ->mimePartFactoryMock ,
86
119
]
87
120
);
88
121
}
@@ -92,12 +125,13 @@ public function setUp()
92
125
* @param string $bodyText
93
126
* @return void
94
127
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
128
+ * @throws \Magento\Framework\Exception\LocalizedException
95
129
*/
96
130
public function testGetTransport (
97
131
$ templateType = TemplateTypesInterface::TYPE_HTML ,
98
132
$ bodyText = '<h1>Html message</h1> '
99
- ) {
100
- $ filter = $ this ->createMock (\ Magento \ Email \ Model \ Template \ Filter::class);
133
+ ): void {
134
+ $ filter = $ this ->createMock (Filter::class);
101
135
$ data = [
102
136
'template_subject ' => 'Email Subject ' ,
103
137
'template_text ' => $ bodyText ,
@@ -107,36 +141,33 @@ public function testGetTransport(
107
141
];
108
142
$ vars = ['reason ' => 'Reason ' , 'customer ' => 'Customer ' ];
109
143
$ options = ['area ' => 'frontend ' , 'store ' => 1 ];
110
- $ template = $ this ->createMock (\Magento \Email \Model \Template::class);
144
+
145
+ /** @var MimePartInterface|MockObject $mimePartMock */
146
+ $ mimePartMock = $ this ->createMock (MimePartInterface::class);
147
+
148
+ $ this ->mimePartFactoryMock ->expects ($ this ->any ())
149
+ ->method ('create ' )
150
+ ->willReturn ($ mimePartMock );
151
+
152
+ /** @var EmailMessageInterface|MockObject $emailMessage */
153
+ $ emailMessage = $ this ->createMock (EmailMessageInterface::class);
154
+
155
+ $ this ->emailMessageInterfaceFactoryMock ->expects ($ this ->any ())
156
+ ->method ('create ' )
157
+ ->willReturn ($ emailMessage );
158
+
159
+ $ template = $ this ->createMock (Template::class);
111
160
$ template ->expects ($ this ->once ())->method ('setVars ' )->with ($ this ->equalTo ($ vars ))->will ($ this ->returnSelf ());
112
- $ template ->expects (
113
- $ this ->once ()
114
- )->method (
115
- 'setOptions '
116
- )->with (
117
- $ this ->equalTo ($ options )
118
- )->will (
119
- $ this ->returnSelf ()
120
- );
121
- $ template ->expects ($ this ->once ())->method ('getSubject ' )->will ($ this ->returnValue ('Email Subject ' ));
161
+ $ template ->expects ($ this ->once ())->method ('setOptions ' )->with ($ this ->equalTo ($ options ))->will ($ this ->returnSelf ());
162
+ $ template ->expects ($ this ->once ())->method ('getSubject ' )->willReturn ('Email Subject ' );
122
163
$ template ->expects ($ this ->once ())->method ('setData ' )->with ($ this ->equalTo ($ data ))->will ($ this ->returnSelf ());
123
- $ template ->expects ($ this ->once ())
124
- ->method ('getProcessedTemplate ' )
125
- ->with ($ vars )
126
- ->willReturn ($ bodyText );
127
- $ template ->expects ($ this ->once ())
128
- ->method ('setTemplateFilter ' )
129
- ->with ($ filter );
130
-
131
- $ this ->templateFactoryMock ->expects (
132
- $ this ->once ()
133
- )->method (
134
- 'get '
135
- )->with (
136
- $ this ->equalTo ('identifier ' )
137
- )->will (
138
- $ this ->returnValue ($ template )
139
- );
164
+ $ template ->expects ($ this ->once ())->method ('getProcessedTemplate ' )->with ($ vars )->willReturn ($ bodyText );
165
+ $ template ->expects ($ this ->once ())->method ('setTemplateFilter ' )->with ($ filter );
166
+
167
+ $ this ->templateFactoryMock ->expects ($ this ->once ())
168
+ ->method ('get ' )
169
+ ->with ($ this ->equalTo ('identifier ' ))
170
+ ->willReturn ($ template );
140
171
141
172
$ this ->builder ->setTemplateIdentifier (
142
173
'identifier '
0 commit comments