Skip to content

Commit 1bcaea8

Browse files
committed
SDK-766: Tidy up unit tests
1 parent ad04d69 commit 1bcaea8

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

tests/Util/Profile/AttributeConverterTest.php

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testConvertToYotiAttributeDocumentImages()
101101
$protobufAttribute->mergeFromString(base64_decode(MULTI_VALUE_ATTRIBUTE));
102102

103103
$attr = AttributeConverter::convertToYotiAttribute($protobufAttribute);
104-
$this->assertEquals(2, count($attr->getValue()));
104+
$this->assertCount(2, $attr->getValue());
105105
$this->assertInstanceOf(MultiValue::class, $attr->getValue());
106106

107107
$this->assertIsExpectedImage($attr->getValue()[0], 'image/jpeg', 'vWgD//2Q==');
@@ -132,7 +132,7 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
132132
{
133133
// Create top-level MultiValue.
134134
$protoMultiValue = new \Attrpubapi\MultiValue();
135-
$protoMultiValue->setValues($this->createTestMultiValueItems());
135+
$protoMultiValue->setValues($this->createMultiValueValues());
136136

137137
// Create mock Attribute that will return MultiValue as the value.
138138
$protobufAttribute = $this->getMockForProtobufAttribute(
@@ -144,7 +144,7 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
144144
$attr = AttributeConverter::convertToYotiAttribute($protobufAttribute);
145145
$multiValue = $attr->getValue();
146146

147-
$this->assertEquals(2, count($multiValue));
147+
$this->assertCount(2, $multiValue);
148148
$this->assertInstanceOf(MultiValue::class, $multiValue);
149149

150150
$this->assertInstanceOf(Image::class, $multiValue[0]);
@@ -164,10 +164,10 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
164164
public function testConvertToYotiAttributeMultiValue()
165165
{
166166
// Get MultiValue values.
167-
$values = $this->createTestMultiValueItems();
167+
$values = $this->createMultiValueValues();
168168

169169
// Add a nested MultiValue.
170-
$values[] = $this->createTestNestedMultiValueItem();
170+
$values[] = $this->createNestedMultiValueValue();
171171

172172
// Create top-level MultiValue.
173173
$protoMultiValue = new \Attrpubapi\MultiValue();
@@ -185,7 +185,7 @@ public function testConvertToYotiAttributeMultiValue()
185185
$multiValue = $attr->getValue();
186186

187187
// Check top-level items.
188-
$this->assertEquals(count($values), count($multiValue));
188+
$this->assertCount(5, $multiValue);
189189
$this->assertInstanceOf(MultiValue::class, $multiValue);
190190

191191
$this->assertInstanceOf(Image::class, $multiValue[0]);
@@ -198,12 +198,10 @@ public function testConvertToYotiAttributeMultiValue()
198198

199199
$this->assertEquals('test string', $multiValue[2]);
200200

201-
$this->assertNull($multiValue[3]);
202-
203201
$this->assertInstanceOf(MultiValue::class, $multiValue[4]);
204202

205203
// Check nested items.
206-
$this->assertEquals(4, count($multiValue[4]));
204+
$this->assertCount(4, $multiValue[4]);
207205

208206
$this->assertInstanceOf(Image::class, $multiValue[4][0]);
209207
$this->assertEquals('image/jpeg', $multiValue[4][0]->getMimeType());
@@ -221,22 +219,20 @@ public function testConvertToYotiAttributeMultiValue()
221219
*
222220
* @return \Attrpubapi\MultiValue\Value
223221
*/
224-
private function createTestNestedMultiValueItem()
222+
private function createNestedMultiValueValue()
225223
{
226224
$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);
232228
}
233229

234230
/**
235231
* Created an array of MultiValue image items.
236232
*
237233
* @return \Attrpubapi\MultiValue\Value[]
238234
*/
239-
private function createTestMultiValueItems()
235+
private function createMultiValueValues()
240236
{
241237
$createValues = [
242238
['image 1', self::CONTENT_TYPE_JPEG],
@@ -245,15 +241,28 @@ private function createTestMultiValueItems()
245241
['', self::CONTENT_TYPE_STRING],
246242
];
247243

248-
$values = [];
244+
$items = [];
249245

250246
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]);
255248
}
256249

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;
258267
}
259268
}

0 commit comments

Comments
 (0)