@@ -37,11 +37,6 @@ class SenderBuilderTest extends \PHPUnit\Framework\TestCase
37
37
38
38
protected function setUp ()
39
39
{
40
- $ templateId = 'test_template_id ' ;
41
- $ templateOptions = ['option1 ' , 'option2 ' ];
42
- $ templateVars = ['var1 ' , 'var2 ' ];
43
- $ emailIdentity = 'email_identity_test ' ;
44
- $ emailCopyTo = ['example@mail.com ' ];
45
40
46
41
$ this ->templateContainerMock = $ this ->createPartialMock (
47
42
\Magento \Sales \Model \Order \Email \Container \Template::class,
@@ -83,36 +78,6 @@ protected function setUp()
83
78
]
84
79
);
85
80
86
- $ this ->templateContainerMock ->expects ($ this ->once ())
87
- ->method ('getTemplateId ' )
88
- ->will ($ this ->returnValue ($ templateId ));
89
- $ this ->transportBuilder ->expects ($ this ->once ())
90
- ->method ('setTemplateIdentifier ' )
91
- ->with ($ this ->equalTo ($ templateId ));
92
- $ this ->templateContainerMock ->expects ($ this ->once ())
93
- ->method ('getTemplateOptions ' )
94
- ->will ($ this ->returnValue ($ templateOptions ));
95
- $ this ->transportBuilder ->expects ($ this ->once ())
96
- ->method ('setTemplateOptions ' )
97
- ->with ($ this ->equalTo ($ templateOptions ));
98
- $ this ->templateContainerMock ->expects ($ this ->once ())
99
- ->method ('getTemplateVars ' )
100
- ->will ($ this ->returnValue ($ templateVars ));
101
- $ this ->transportBuilder ->expects ($ this ->once ())
102
- ->method ('setTemplateVars ' )
103
- ->with ($ this ->equalTo ($ templateVars ));
104
-
105
- $ this ->identityContainerMock ->expects ($ this ->once ())
106
- ->method ('getEmailIdentity ' )
107
- ->will ($ this ->returnValue ($ emailIdentity ));
108
- $ this ->transportBuilder ->expects ($ this ->once ())
109
- ->method ('setFromByScope ' )
110
- ->with ($ this ->equalTo ($ emailIdentity ), 1 );
111
-
112
- $ this ->identityContainerMock ->expects ($ this ->once ())
113
- ->method ('getEmailCopyTo ' )
114
- ->will ($ this ->returnValue ($ emailCopyTo ));
115
-
116
81
$ this ->senderBuilder = new SenderBuilder (
117
82
$ this ->templateContainerMock ,
118
83
$ this ->identityContainerMock ,
@@ -122,6 +87,7 @@ protected function setUp()
122
87
123
88
public function testSend ()
124
89
{
90
+ $ this ->setExpectedCount (1 );
125
91
$ customerName = 'test_name ' ;
126
92
$ customerEmail = 'test_email ' ;
127
93
$ identity = 'email_identity_test ' ;
@@ -142,20 +108,20 @@ public function testSend()
142
108
$ this ->identityContainerMock ->expects ($ this ->once ())
143
109
->method ('getCustomerName ' )
144
110
->will ($ this ->returnValue ($ customerName ));
145
- $ this ->identityContainerMock ->expects ($ this ->once ( ))
111
+ $ this ->identityContainerMock ->expects ($ this ->exactly ( 1 ))
146
112
->method ('getStore ' )
147
113
->willReturn ($ this ->storeMock );
148
114
$ this ->storeMock ->expects ($ this ->once ())
149
115
->method ('getId ' )
150
116
->willReturn (1 );
151
- $ this ->transportBuilder ->expects ($ this ->once ( ))
117
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
152
118
->method ('setFromByScope ' )
153
119
->with ($ identity , 1 );
154
- $ this ->transportBuilder ->expects ($ this ->once ( ))
120
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
155
121
->method ('addTo ' )
156
122
->with ($ this ->equalTo ($ customerEmail ), $ this ->equalTo ($ customerName ));
157
123
158
- $ this ->transportBuilder ->expects ($ this ->once ( ))
124
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
159
125
->method ('getTransport ' )
160
126
->will ($ this ->returnValue ($ transportMock ));
161
127
@@ -164,6 +130,7 @@ public function testSend()
164
130
165
131
public function testSendCopyTo ()
166
132
{
133
+ $ this ->setExpectedCount (2 );
167
134
$ identity = 'email_identity_test ' ;
168
135
$ transportMock = $ this ->createMock (
169
136
\Magento \Sales \Test \Unit \Model \Order \Email \Stub \TransportInterfaceMock::class
@@ -172,22 +139,66 @@ public function testSendCopyTo()
172
139
->method ('getCustomerEmail ' );
173
140
$ this ->identityContainerMock ->expects ($ this ->never ())
174
141
->method ('getCustomerName ' );
175
- $ this ->transportBuilder ->expects ($ this ->once ())
176
- ->method ('addTo ' )
177
- ->with ($ this ->equalTo ('example@mail.com ' ));
178
- $ this ->transportBuilder ->expects ($ this ->once ())
142
+ $ this ->transportBuilder ->expects ($ this ->exactly (2 ))
143
+ ->method ('addTo ' );
144
+ $ this ->transportBuilder ->expects ($ this ->exactly (2 ))
179
145
->method ('setFromByScope ' )
180
146
->with ($ identity , 1 );
181
- $ this ->identityContainerMock ->expects ($ this ->once ( ))
147
+ $ this ->identityContainerMock ->expects ($ this ->exactly ( 2 ))
182
148
->method ('getStore ' )
183
149
->willReturn ($ this ->storeMock );
184
- $ this ->storeMock ->expects ($ this ->once ( ))
150
+ $ this ->storeMock ->expects ($ this ->exactly ( 2 ))
185
151
->method ('getId ' )
186
152
->willReturn (1 );
187
- $ this ->transportBuilder ->expects ($ this ->once ( ))
153
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 2 ))
188
154
->method ('getTransport ' )
189
155
->will ($ this ->returnValue ($ transportMock ));
190
156
191
157
$ this ->senderBuilder ->sendCopyTo ();
192
158
}
159
+
160
+ /**
161
+ * Sets expected count invocation.
162
+ *
163
+ * @param int $count
164
+ */
165
+ private function setExpectedCount (int $ count = 1 )
166
+ {
167
+
168
+ $ templateId = 'test_template_id ' ;
169
+ $ templateOptions = ['option1 ' , 'option2 ' ];
170
+ $ templateVars = ['var1 ' , 'var2 ' ];
171
+ $ emailIdentity = 'email_identity_test ' ;
172
+ $ emailCopyTo = ['example@mail.com ' , 'example2@mail.com ' ];
173
+
174
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
175
+ ->method ('getTemplateId ' )
176
+ ->will ($ this ->returnValue ($ templateId ));
177
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
178
+ ->method ('setTemplateIdentifier ' )
179
+ ->with ($ this ->equalTo ($ templateId ));
180
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
181
+ ->method ('getTemplateOptions ' )
182
+ ->will ($ this ->returnValue ($ templateOptions ));
183
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
184
+ ->method ('setTemplateOptions ' )
185
+ ->with ($ this ->equalTo ($ templateOptions ));
186
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
187
+ ->method ('getTemplateVars ' )
188
+ ->will ($ this ->returnValue ($ templateVars ));
189
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
190
+ ->method ('setTemplateVars ' )
191
+ ->with ($ this ->equalTo ($ templateVars ));
192
+
193
+ $ this ->identityContainerMock ->expects ($ this ->exactly ($ count ))
194
+ ->method ('getEmailIdentity ' )
195
+ ->will ($ this ->returnValue ($ emailIdentity ));
196
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
197
+ ->method ('setFromByScope ' )
198
+ ->with ($ this ->equalTo ($ emailIdentity ), 1 );
199
+
200
+ $ this ->identityContainerMock ->expects ($ this ->once ())
201
+ ->method ('getEmailCopyTo ' )
202
+ ->will ($ this ->returnValue ($ emailCopyTo ));
203
+ }
193
204
}
0 commit comments