@@ -121,14 +121,27 @@ protected function setUp(): void
121
121
);
122
122
}
123
123
124
- public function testExtract ()
124
+ /**
125
+ * @param int $storeId
126
+ * @param int $websiteId
127
+ * @param array $customerData
128
+ * @dataProvider getDataProvider
129
+ * @return void
130
+ */
131
+ public function testExtract (int $ storeId , int $ websiteId , array $ customerData )
125
132
{
126
- $ customerData = [
127
- 'firstname ' => 'firstname ' ,
128
- 'lastname ' => 'firstname ' ,
129
- 'email ' => 'email.example.com ' ,
130
- ];
133
+ $ this ->initializeExpectation ($ storeId , $ websiteId , $ customerData );
131
134
135
+ $ this ->assertSame ($ this ->customerData , $ this ->customerExtractor ->extract ('form-code ' , $ this ->request ));
136
+ }
137
+
138
+ /**
139
+ * @param int $storeId
140
+ * @param int $websiteId
141
+ * @param array $customerData
142
+ */
143
+ private function initializeExpectation (int $ storeId , int $ websiteId , array $ customerData ): void
144
+ {
132
145
$ this ->formFactory ->expects ($ this ->once ())
133
146
->method ('create ' )
134
147
->with ('customer ' , 'form-code ' )
@@ -156,17 +169,54 @@ public function testExtract()
156
169
->willReturn ($ this ->store );
157
170
$ this ->store ->expects ($ this ->once ())
158
171
->method ('getId ' )
159
- ->willReturn (1 );
172
+ ->willReturn ($ storeId );
160
173
$ this ->store ->expects ($ this ->once ())
161
174
->method ('getWebsiteId ' )
162
- ->willReturn (1 );
175
+ ->willReturn ($ websiteId );
163
176
$ this ->customerData ->expects ($ this ->once ())
164
177
->method ('setWebsiteId ' )
165
- ->with (1 );
178
+ ->with ($ websiteId );
166
179
$ this ->customerData ->expects ($ this ->once ())
167
180
->method ('setStoreId ' )
168
- ->with (1 );
181
+ ->with ($ storeId );
182
+ }
169
183
170
- $ this ->assertSame ($ this ->customerData , $ this ->customerExtractor ->extract ('form-code ' , $ this ->request ));
184
+ /**
185
+ * @return array
186
+ */
187
+ public function getDataProvider ()
188
+ {
189
+ return [
190
+ 'extract data when group id is null ' => [
191
+ 1 ,
192
+ 1 ,
193
+ [
194
+ 'firstname ' => 'firstname-1 ' ,
195
+ 'lastname ' => 'firstname-1 ' ,
196
+ 'email ' => 'email-1.example.com ' ,
197
+ 'group_id ' => null
198
+ ]
199
+ ],
200
+ 'extract data when group id is not null and default ' => [
201
+ 1 ,
202
+ 2 ,
203
+ [
204
+ 'firstname ' => 'firstname-2 ' ,
205
+ 'lastname ' => 'firstname-3 ' ,
206
+ 'email ' => 'email-2.example.com ' ,
207
+ 'group_id ' => 1
208
+ ]
209
+ ],
210
+ 'extract data when group id is different from default ' => [
211
+ 1 ,
212
+ 1 ,
213
+ [
214
+ 'firstname ' => 'firstname-3 ' ,
215
+ 'lastname ' => 'firstname-3 ' ,
216
+ 'email ' => 'email-3.example.com ' ,
217
+ 'group_id ' => 2
218
+ ]
219
+ ],
220
+ ];
171
221
}
172
222
}
0 commit comments