@@ -24,6 +24,7 @@ class AttributeConverterTest extends TestCase
24
24
const CONTENT_TYPE_PNG = 4 ;
25
25
const CONTENT_TYPE_BYTES = 5 ;
26
26
const CONTENT_TYPE_MULTI_VALUE = 6 ;
27
+ const CONTENT_TYPE_INT = 7 ;
27
28
28
29
/**
29
30
* Mocks \Attrpubapi\Attribute with provided name and value.
@@ -100,17 +101,40 @@ public function testConvertToYotiAttributeEmptyStringValue()
100
101
101
102
/**
102
103
* @covers ::convertToYotiAttribute
104
+ *
105
+ * @dataProvider nonStringContentTypesDataProvider
103
106
*/
104
- public function testConvertToYotiAttributeEmptyNonStringValue ()
107
+ public function testConvertToYotiAttributeEmptyNonStringValue ($ contentType )
105
108
{
106
- foreach ($ this ->getNonStringContentTypes () as $ contentType ) {
107
- $ attr = AttributeConverter::convertToYotiAttribute ($ this ->getMockForProtobufAttribute (
108
- 'test_attr ' ,
109
- '' ,
110
- $ contentType
111
- ));
112
- $ this ->assertNull ($ attr );
113
- }
109
+ $ attr = AttributeConverter::convertToYotiAttribute ($ this ->getMockForProtobufAttribute (
110
+ 'test_attr ' ,
111
+ '' ,
112
+ $ contentType
113
+ ));
114
+ $ this ->assertNull ($ attr );
115
+ }
116
+
117
+ /**
118
+ * @covers ::convertToYotiAttribute
119
+ *
120
+ * @dataProvider validIntegerDataProvider
121
+ */
122
+ public function testConvertToYotiAttributeIntegerValue ($ int )
123
+ {
124
+ $ attr = AttributeConverter::convertToYotiAttribute ($ this ->getMockForProtobufAttribute (
125
+ 'test_attr ' ,
126
+ $ int ,
127
+ self ::CONTENT_TYPE_INT
128
+ ));
129
+ $ this ->assertSame ($ int , $ attr ->getValue ());
130
+ }
131
+
132
+ /**
133
+ * Provides list of valid integers.
134
+ */
135
+ public function validIntegerDataProvider ()
136
+ {
137
+ return [[0 ], [1 ], [123 ], [-1 ], [-10 ]];
114
138
}
115
139
116
140
/**
@@ -259,30 +283,30 @@ public function testConvertToYotiAttributeMultiValue()
259
283
* Check that empty non-string MultiValue Values result in no attribute being returned.
260
284
*
261
285
* @covers ::convertToYotiAttribute
286
+ *
287
+ * @dataProvider nonStringContentTypesDataProvider
262
288
*/
263
- public function testEmptyNonStringAttributeMultiValueValue ()
289
+ public function testEmptyNonStringAttributeMultiValueValue ($ contentType )
264
290
{
265
- foreach ($ this ->getNonStringContentTypes () as $ contentType ) {
266
- // Get MultiValue values.
267
- $ values = $ this ->createMultiValueValues ();
268
-
269
- // Add an empty MultiValue.
270
- $ values [] = $ this ->createMultiValueValue ('' , $ contentType );
271
-
272
- // Create top-level MultiValue.
273
- $ protoMultiValue = new \Attrpubapi \MultiValue ();
274
- $ protoMultiValue ->setValues ($ values );
275
-
276
- // Create mock Attribute that will return MultiValue as the value.
277
- $ protobufAttribute = $ this ->getMockForProtobufAttribute (
278
- 'test_attr ' ,
279
- $ protoMultiValue ->serializeToString (),
280
- self ::CONTENT_TYPE_MULTI_VALUE
281
- );
282
-
283
- $ attr = AttributeConverter::convertToYotiAttribute ($ protobufAttribute );
284
- $ this ->assertNull ($ attr );
285
- }
291
+ // Get MultiValue values.
292
+ $ values = $ this ->createMultiValueValues ();
293
+
294
+ // Add an empty MultiValue.
295
+ $ values [] = $ this ->createMultiValueValue ('' , $ contentType );
296
+
297
+ // Create top-level MultiValue.
298
+ $ protoMultiValue = new \Attrpubapi \MultiValue ();
299
+ $ protoMultiValue ->setValues ($ values );
300
+
301
+ // Create mock Attribute that will return MultiValue as the value.
302
+ $ protobufAttribute = $ this ->getMockForProtobufAttribute (
303
+ 'test_attr ' ,
304
+ $ protoMultiValue ->serializeToString (),
305
+ self ::CONTENT_TYPE_MULTI_VALUE
306
+ );
307
+
308
+ $ attr = AttributeConverter::convertToYotiAttribute ($ protobufAttribute );
309
+ $ this ->assertNull ($ attr );
286
310
}
287
311
288
312
/**
@@ -366,18 +390,17 @@ private function createMultiValueValue($data, $contentType)
366
390
}
367
391
368
392
/**
369
- * List of non-string content types.
370
- *
371
- * @return array
393
+ * Provides non-string content types.
372
394
*/
373
- private function getNonStringContentTypes ()
395
+ public function nonStringContentTypesDataProvider ()
374
396
{
375
397
return [
376
- self ::CONTENT_TYPE_JPEG ,
377
- self ::CONTENT_TYPE_DATE ,
378
- self ::CONTENT_TYPE_PNG ,
379
- self ::CONTENT_TYPE_BYTES ,
380
- self ::CONTENT_TYPE_MULTI_VALUE ,
398
+ [ self ::CONTENT_TYPE_JPEG ],
399
+ [ self ::CONTENT_TYPE_DATE ],
400
+ [ self ::CONTENT_TYPE_PNG ],
401
+ [ self ::CONTENT_TYPE_BYTES ],
402
+ [ self ::CONTENT_TYPE_MULTI_VALUE ],
403
+ [ self ::CONTENT_TYPE_INT ],
381
404
];
382
405
}
383
406
}
0 commit comments