@@ -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,35 +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
81
116
82
$ this ->senderBuilder = new SenderBuilder (
117
83
$ this ->templateContainerMock ,
@@ -122,6 +88,7 @@ protected function setUp()
122
88
123
89
public function testSend ()
124
90
{
91
+ $ this ->setExpectedCount (1 );
125
92
$ customerName = 'test_name ' ;
126
93
$ customerEmail = 'test_email ' ;
127
94
$ identity = 'email_identity_test ' ;
@@ -142,20 +109,20 @@ public function testSend()
142
109
$ this ->identityContainerMock ->expects ($ this ->once ())
143
110
->method ('getCustomerName ' )
144
111
->will ($ this ->returnValue ($ customerName ));
145
- $ this ->identityContainerMock ->expects ($ this ->once ( ))
112
+ $ this ->identityContainerMock ->expects ($ this ->exactly ( 1 ))
146
113
->method ('getStore ' )
147
114
->willReturn ($ this ->storeMock );
148
115
$ this ->storeMock ->expects ($ this ->once ())
149
116
->method ('getId ' )
150
117
->willReturn (1 );
151
- $ this ->transportBuilder ->expects ($ this ->once ( ))
118
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
152
119
->method ('setFromByScope ' )
153
120
->with ($ identity , 1 );
154
- $ this ->transportBuilder ->expects ($ this ->once ( ))
121
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
155
122
->method ('addTo ' )
156
123
->with ($ this ->equalTo ($ customerEmail ), $ this ->equalTo ($ customerName ));
157
124
158
- $ this ->transportBuilder ->expects ($ this ->once ( ))
125
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 1 ))
159
126
->method ('getTransport ' )
160
127
->will ($ this ->returnValue ($ transportMock ));
161
128
@@ -164,6 +131,7 @@ public function testSend()
164
131
165
132
public function testSendCopyTo ()
166
133
{
134
+ $ this ->setExpectedCount (2 );
167
135
$ identity = 'email_identity_test ' ;
168
136
$ transportMock = $ this ->createMock (
169
137
\Magento \Sales \Test \Unit \Model \Order \Email \Stub \TransportInterfaceMock::class
@@ -172,22 +140,66 @@ public function testSendCopyTo()
172
140
->method ('getCustomerEmail ' );
173
141
$ this ->identityContainerMock ->expects ($ this ->never ())
174
142
->method ('getCustomerName ' );
175
- $ this ->transportBuilder ->expects ($ this ->once ())
176
- ->method ('addTo ' )
177
- ->with ($ this ->equalTo ('example@mail.com ' ));
178
- $ this ->transportBuilder ->expects ($ this ->once ())
143
+ $ this ->transportBuilder ->expects ($ this ->exactly (2 ))
144
+ ->method ('addTo ' );
145
+ $ this ->transportBuilder ->expects ($ this ->exactly (2 ))
179
146
->method ('setFromByScope ' )
180
147
->with ($ identity , 1 );
181
- $ this ->identityContainerMock ->expects ($ this ->once ( ))
148
+ $ this ->identityContainerMock ->expects ($ this ->exactly ( 2 ))
182
149
->method ('getStore ' )
183
150
->willReturn ($ this ->storeMock );
184
- $ this ->storeMock ->expects ($ this ->once ( ))
151
+ $ this ->storeMock ->expects ($ this ->exactly ( 2 ))
185
152
->method ('getId ' )
186
153
->willReturn (1 );
187
- $ this ->transportBuilder ->expects ($ this ->once ( ))
154
+ $ this ->transportBuilder ->expects ($ this ->exactly ( 2 ))
188
155
->method ('getTransport ' )
189
156
->will ($ this ->returnValue ($ transportMock ));
190
157
191
158
$ this ->senderBuilder ->sendCopyTo ();
192
159
}
160
+
161
+ /**
162
+ * Sets expected count invocation.
163
+ *
164
+ * @param int $count
165
+ */
166
+ private function setExpectedCount (int $ count = 1 )
167
+ {
168
+
169
+ $ templateId = 'test_template_id ' ;
170
+ $ templateOptions = ['option1 ' , 'option2 ' ];
171
+ $ templateVars = ['var1 ' , 'var2 ' ];
172
+ $ emailIdentity = 'email_identity_test ' ;
173
+ $ emailCopyTo = ['example@mail.com ' , 'example2@mail.com ' ];
174
+
175
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
176
+ ->method ('getTemplateId ' )
177
+ ->will ($ this ->returnValue ($ templateId ));
178
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
179
+ ->method ('setTemplateIdentifier ' )
180
+ ->with ($ this ->equalTo ($ templateId ));
181
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
182
+ ->method ('getTemplateOptions ' )
183
+ ->will ($ this ->returnValue ($ templateOptions ));
184
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
185
+ ->method ('setTemplateOptions ' )
186
+ ->with ($ this ->equalTo ($ templateOptions ));
187
+ $ this ->templateContainerMock ->expects ($ this ->exactly ($ count ))
188
+ ->method ('getTemplateVars ' )
189
+ ->will ($ this ->returnValue ($ templateVars ));
190
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
191
+ ->method ('setTemplateVars ' )
192
+ ->with ($ this ->equalTo ($ templateVars ));
193
+
194
+ $ this ->identityContainerMock ->expects ($ this ->exactly ($ count ))
195
+ ->method ('getEmailIdentity ' )
196
+ ->will ($ this ->returnValue ($ emailIdentity ));
197
+ $ this ->transportBuilder ->expects ($ this ->exactly ($ count ))
198
+ ->method ('setFromByScope ' )
199
+ ->with ($ this ->equalTo ($ emailIdentity ), 1 );
200
+
201
+ $ this ->identityContainerMock ->expects ($ this ->once ())
202
+ ->method ('getEmailCopyTo ' )
203
+ ->will ($ this ->returnValue ($ emailCopyTo ));
204
+ }
193
205
}
0 commit comments