Skip to content

Commit d320b4a

Browse files
committed
SDK-766: Return null when document images aren't converted to MultiValue
1 parent d8c4f29 commit d320b4a

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Yoti/Util/Profile/AttributeConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static function convertValueBasedOnAttributeName($value, $attrName)
3535

3636
case Profile::ATTR_DOCUMENT_IMAGES:
3737
if (!($value instanceof MultiValue)) {
38-
return null;
38+
throw new AttributeException('Document Images could not be decoded');
3939
}
4040
return $value
4141
->allowInstance(Image::class)

tests/Util/Profile/AttributeConverterTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,24 @@ public function testConvertToYotiAttributeDocumentImagesFiltered()
179179
$this->assertNotEmpty($multiValue[1]->getContent());
180180
}
181181

182+
/**
183+
* Check that `document_images` is null when not converted to a MultiValue object.
184+
*
185+
* @covers ::convertToYotiAttribute
186+
*/
187+
public function testConvertToYotiAttributeDocumentImagesInvalid()
188+
{
189+
// Create mock Attribute that will return MultiValue as the value.
190+
$protobufAttribute = $this->getMockForProtobufAttribute(
191+
'document_images',
192+
'invalid value',
193+
self::CONTENT_TYPE_STRING
194+
);
195+
196+
$attr = AttributeConverter::convertToYotiAttribute($protobufAttribute);
197+
$this->assertNull($attr);
198+
}
199+
182200
/**
183201
* Check that MultiValue object is returned for MultiValue attributes by default.
184202
*

0 commit comments

Comments
 (0)