@@ -45,29 +45,43 @@ class TransportBuilderTest extends \PHPUnit\Framework\TestCase
45
45
*/
46
46
protected $ mailTransportFactoryMock ;
47
47
48
+ /**
49
+ * @var \Magento\Framework\Mail\MessageInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject
50
+ */
51
+ private $ messageFactoryMock ;
52
+
48
53
/**
49
54
* @return void
50
55
*/
51
56
public function setUp ()
52
57
{
53
58
$ objectManagerHelper = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
54
59
$ this ->templateFactoryMock = $ this ->createMock (\Magento \Framework \Mail \Template \FactoryInterface::class);
55
- $ this ->messageMock = $ this ->createMock (\Magento \Framework \Mail \Message::class);
60
+ $ this ->messageMock = $ this ->getMockBuilder (\Magento \Framework \Mail \MessageInterface::class)
61
+ ->disableOriginalConstructor ()
62
+ ->setMethods (['setBodyHtml ' , 'setSubject ' ])
63
+ ->getMockForAbstractClass ();
56
64
$ this ->objectManagerMock = $ this ->createMock (\Magento \Framework \ObjectManagerInterface::class);
57
65
$ this ->senderResolverMock = $ this ->createMock (\Magento \Framework \Mail \Template \SenderResolverInterface::class);
58
66
$ this ->mailTransportFactoryMock = $ this ->getMockBuilder (
59
67
\Magento \Framework \Mail \TransportInterfaceFactory::class
60
68
)->disableOriginalConstructor ()
61
69
->setMethods (['create ' ])
62
70
->getMock ();
71
+ $ this ->messageFactoryMock = $ this ->getMockBuilder (\Magento \Framework \Mail \MessageInterfaceFactory::class)
72
+ ->disableOriginalConstructor ()
73
+ ->setMethods (['create ' ])
74
+ ->getMockForAbstractClass ();
75
+ $ this ->messageFactoryMock ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturn ($ this ->messageMock );
63
76
$ this ->builder = $ objectManagerHelper ->getObject (
64
77
$ this ->builderClassName ,
65
78
[
66
79
'templateFactory ' => $ this ->templateFactoryMock ,
67
80
'message ' => $ this ->messageMock ,
68
81
'objectManager ' => $ this ->objectManagerMock ,
69
82
'senderResolver ' => $ this ->senderResolverMock ,
70
- 'mailTransportFactory ' => $ this ->mailTransportFactoryMock
83
+ 'mailTransportFactory ' => $ this ->mailTransportFactoryMock ,
84
+ 'messageFactory ' => $ this ->messageFactoryMock
71
85
]
72
86
);
73
87
}
@@ -108,7 +122,7 @@ public function testGetTransport(
108
122
$ template ->expects ($ this ->once ())
109
123
->method ('getProcessedTemplate ' )
110
124
->with ($ vars )
111
- ->will ( $ this -> returnValue ( $ bodyText) );
125
+ ->willReturn ( $ bodyText );
112
126
$ template ->expects ($ this ->once ())
113
127
->method ('setTemplateFilter ' )
114
128
->with ($ filter );
@@ -123,46 +137,8 @@ public function testGetTransport(
123
137
$ this ->returnValue ($ template )
124
138
);
125
139
126
- $ this ->messageMock ->expects (
127
- $ this ->once ()
128
- )->method (
129
- 'setSubject '
130
- )->with (
131
- $ this ->equalTo ('Email Subject ' )
132
- )->will (
133
- $ this ->returnSelf ()
134
- );
135
- $ this ->messageMock ->expects (
136
- $ this ->once ()
137
- )->method (
138
- 'setBodyHtml '
139
- )->with (
140
- $ this ->equalTo ($ bodyText )
141
- )->will (
142
- $ this ->returnSelf ()
143
- );
144
-
145
- $ transport = $ this ->createMock (\Magento \Framework \Mail \TransportInterface::class);
146
-
147
- $ this ->mailTransportFactoryMock ->expects (
148
- $ this ->at (0 )
149
- )->method (
150
- 'create '
151
- )->with (
152
- $ this ->equalTo (['message ' => $ this ->messageMock ])
153
- )->will (
154
- $ this ->returnValue ($ transport )
155
- );
156
-
157
- $ this ->objectManagerMock ->expects (
158
- $ this ->at (0 )
159
- )->method (
160
- 'create '
161
- )->with (
162
- $ this ->equalTo (\Magento \Framework \Mail \Message::class)
163
- )->will (
164
- $ this ->returnValue ($ transport )
165
- );
140
+ $ this ->messageMock ->expects ($ this ->once ())->method ('setBodyHtml ' )->willReturnSelf ();
141
+ $ this ->messageMock ->expects ($ this ->once ())->method ('setSubject ' )->willReturnSelf ();
166
142
167
143
$ this ->builder ->setTemplateIdentifier (
168
144
'identifier '
@@ -174,8 +150,6 @@ public function testGetTransport(
174
150
$ data
175
151
);
176
152
177
- $ result = $ this ->builder ->getTransport ();
178
-
179
- $ this ->assertInstanceOf (\Magento \Framework \Mail \TransportInterface::class, $ result );
153
+ $ this ->builder ->getTransport ();
180
154
}
181
155
}
0 commit comments