@@ -101,7 +101,7 @@ public function testConvertToYotiAttributeDocumentImages()
101
101
$ protobufAttribute ->mergeFromString (base64_decode (MULTI_VALUE_ATTRIBUTE ));
102
102
103
103
$ attr = AttributeConverter::convertToYotiAttribute ($ protobufAttribute );
104
- $ this ->assertEquals (2 , count ( $ attr ->getValue () ));
104
+ $ this ->assertCount (2 , $ attr ->getValue ());
105
105
$ this ->assertInstanceOf (MultiValue::class, $ attr ->getValue ());
106
106
107
107
$ this ->assertIsExpectedImage ($ attr ->getValue ()[0 ], 'image/jpeg ' , 'vWgD//2Q== ' );
@@ -132,7 +132,7 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
132
132
{
133
133
// Create top-level MultiValue.
134
134
$ protoMultiValue = new \Attrpubapi \MultiValue ();
135
- $ protoMultiValue ->setValues ($ this ->createTestMultiValueItems ());
135
+ $ protoMultiValue ->setValues ($ this ->createMultiValueValues ());
136
136
137
137
// Create mock Attribute that will return MultiValue as the value.
138
138
$ protobufAttribute = $ this ->getMockForProtobufAttribute (
@@ -144,7 +144,7 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
144
144
$ attr = AttributeConverter::convertToYotiAttribute ($ protobufAttribute );
145
145
$ multiValue = $ attr ->getValue ();
146
146
147
- $ this ->assertEquals (2 , count ( $ multiValue) );
147
+ $ this ->assertCount (2 , $ multiValue );
148
148
$ this ->assertInstanceOf (MultiValue::class, $ multiValue );
149
149
150
150
$ this ->assertInstanceOf (Image::class, $ multiValue [0 ]);
@@ -164,10 +164,10 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
164
164
public function testConvertToYotiAttributeMultiValue ()
165
165
{
166
166
// Get MultiValue values.
167
- $ values = $ this ->createTestMultiValueItems ();
167
+ $ values = $ this ->createMultiValueValues ();
168
168
169
169
// Add a nested MultiValue.
170
- $ values [] = $ this ->createTestNestedMultiValueItem ();
170
+ $ values [] = $ this ->createNestedMultiValueValue ();
171
171
172
172
// Create top-level MultiValue.
173
173
$ protoMultiValue = new \Attrpubapi \MultiValue ();
@@ -185,7 +185,7 @@ public function testConvertToYotiAttributeMultiValue()
185
185
$ multiValue = $ attr ->getValue ();
186
186
187
187
// Check top-level items.
188
- $ this ->assertEquals ( count ( $ values ), count ( $ multiValue) );
188
+ $ this ->assertCount ( 5 , $ multiValue );
189
189
$ this ->assertInstanceOf (MultiValue::class, $ multiValue );
190
190
191
191
$ this ->assertInstanceOf (Image::class, $ multiValue [0 ]);
@@ -198,12 +198,10 @@ public function testConvertToYotiAttributeMultiValue()
198
198
199
199
$ this ->assertEquals ('test string ' , $ multiValue [2 ]);
200
200
201
- $ this ->assertNull ($ multiValue [3 ]);
202
-
203
201
$ this ->assertInstanceOf (MultiValue::class, $ multiValue [4 ]);
204
202
205
203
// Check nested items.
206
- $ this ->assertEquals (4 , count ( $ multiValue [4 ]) );
204
+ $ this ->assertCount (4 , $ multiValue [4 ]);
207
205
208
206
$ this ->assertInstanceOf (Image::class, $ multiValue [4 ][0 ]);
209
207
$ this ->assertEquals ('image/jpeg ' , $ multiValue [4 ][0 ]->getMimeType ());
@@ -221,22 +219,20 @@ public function testConvertToYotiAttributeMultiValue()
221
219
*
222
220
* @return \Attrpubapi\MultiValue\Value
223
221
*/
224
- private function createTestNestedMultiValueItem ()
222
+ private function createNestedMultiValueValue ()
225
223
{
226
224
$ multiValue = new \Attrpubapi \MultiValue ();
227
- $ multiValue ->setValues ($ this ->createTestMultiValueItems ());
228
- $ multiValueValue = new \Attrpubapi \MultiValue \Value ();
229
- $ multiValueValue ->setData ($ multiValue ->serializeToString ());
230
- $ multiValueValue ->setContentType (self ::CONTENT_TYPE_MULTI_VALUE );
231
- return $ multiValueValue ;
225
+ $ multiValue ->setValues ($ this ->createMultiValueValues ());
226
+
227
+ return $ this ->createMultiValueValue ($ multiValue ->serializeToString (), self ::CONTENT_TYPE_MULTI_VALUE );
232
228
}
233
229
234
230
/**
235
231
* Created an array of MultiValue image items.
236
232
*
237
233
* @return \Attrpubapi\MultiValue\Value[]
238
234
*/
239
- private function createTestMultiValueItems ()
235
+ private function createMultiValueValues ()
240
236
{
241
237
$ createValues = [
242
238
['image 1 ' , self ::CONTENT_TYPE_JPEG ],
@@ -245,15 +241,28 @@ private function createTestMultiValueItems()
245
241
['' , self ::CONTENT_TYPE_STRING ],
246
242
];
247
243
248
- $ values = [];
244
+ $ items = [];
249
245
250
246
foreach ($ createValues as $ createValue ) {
251
- $ protoMultiValueValue = new \Attrpubapi \MultiValue \Value ();
252
- $ protoMultiValueValue ->setData ($ createValue [0 ]);
253
- $ protoMultiValueValue ->setContentType ($ createValue [1 ]);
254
- $ values [] = $ protoMultiValueValue ;
247
+ $ items [] = $ this ->createMultiValueValue ($ createValue [0 ], $ createValue [1 ]);
255
248
}
256
249
257
- return $ values ;
250
+ return $ items ;
251
+ }
252
+
253
+ /**
254
+ * Create MultiValue Value.
255
+ *
256
+ * @param string $data
257
+ * @param int $contentType
258
+ *
259
+ * @return \Attrpubapi\MultiValue\Value
260
+ */
261
+ private function createMultiValueValue ($ data , $ contentType )
262
+ {
263
+ $ protoMultiValueValue = new \Attrpubapi \MultiValue \Value ();
264
+ $ protoMultiValueValue ->setData ($ data );
265
+ $ protoMultiValueValue ->setContentType ($ contentType );
266
+ return $ protoMultiValueValue ;
258
267
}
259
268
}
0 commit comments