7
7
use Yoti \Entity \Receipt ;
8
8
use Yoti \ActivityDetails ;
9
9
use Yoti \Util \Profile \AttributeConverter ;
10
+ use Yoti \Exception \AttributeException ;
10
11
12
+ /**
13
+ * @coversDefaultClass \Yoti\Util\Profile\AttributeConverter
14
+ */
11
15
class AttributeConverterTest extends TestCase
12
16
{
17
+ /**
18
+ * Mocks \Attrpubapi\Attribute with provided name and value.
19
+ */
20
+ private function getMockForProtobufAttribute ($ name , $ value ) {
21
+ // Setup protobuf mock.
22
+ $ protobufAttribute = $ this ->getMockBuilder (\Attrpubapi \Attribute::class)
23
+ ->disableOriginalConstructor ()
24
+ ->getMock ();
25
+ $ protobufAttribute
26
+ ->method ('getAnchors ' )
27
+ ->willReturn ($ this ->getMockBuilder (\Traversable::class)->getMock ());
28
+ $ protobufAttribute
29
+ ->method ('getName ' )
30
+ ->willReturn ($ name );
31
+ $ protobufAttribute
32
+ ->method ('getValue ' )
33
+ ->willReturn ($ value );
34
+
35
+ return $ protobufAttribute ;
36
+ }
37
+
38
+ /**
39
+ * @covers ::convertTimestampToDate
40
+ */
13
41
public function testDateTypeShouldReturnDateTime ()
14
42
{
15
43
$ dateTime = AttributeConverter::convertTimestampToDate ('1980/12/01 ' );
16
44
$ this ->assertInstanceOf (\DateTime::class, $ dateTime );
17
45
$ this ->assertEquals ('01-12-1980 ' , $ dateTime ->format ('d-m-Y ' ));
18
46
}
19
47
48
+ /**
49
+ * @covers ::convertValueBasedOnContentType
50
+ */
20
51
public function testSelfieValueShouldReturnImageObject ()
21
52
{
22
53
$ pem = file_get_contents (PEM_FILE );
@@ -27,4 +58,63 @@ public function testSelfieValueShouldReturnImageObject()
27
58
$ this ->profile = $ this ->activityDetails ->getProfile ();
28
59
$ this ->assertInstanceOf (Image::class, $ this ->profile ->getSelfie ()->getValue ());
29
60
}
30
- }
61
+
62
+ /**
63
+ * @covers ::convertToYotiAttribute
64
+ */
65
+ public function testConvertToYotiAttribute () {
66
+ $ attr = AttributeConverter::convertToYotiAttribute ($ this ->getMockForProtobufAttribute ('test_attr ' , 'my_value ' ));
67
+ $ this ->assertEquals ('test_attr ' , $ attr ->getName ());
68
+ $ this ->assertEquals ('my_value ' , $ attr ->getValue ());
69
+ }
70
+
71
+ /**
72
+ * @covers ::convertToYotiAttribute
73
+ */
74
+ public function testConvertToYotiAttributeNullValue () {
75
+ $ attr = AttributeConverter::convertToYotiAttribute ($ this ->getMockForProtobufAttribute ('test_attr ' , '' ));
76
+ $ this ->assertNull ($ attr );
77
+ }
78
+
79
+ /**
80
+ * @covers ::convertValueBasedOnContentType
81
+ * @covers ::validateInput
82
+ */
83
+ public function testConvertValueBasedOnContentTypeValidation () {
84
+ $ this ->expectException (AttributeException::class);
85
+ $ this ->expectExceptionMessage ('Warning: test_attr value is NULL ' );
86
+ $ this ->invokeStaticMethod (
87
+ AttributeConverter::class,
88
+ 'convertValueBasedOnContentType ' ,
89
+ [$ this ->getMockForProtobufAttribute ('test_attr ' , '' )]
90
+ );
91
+ }
92
+
93
+ /**
94
+ * @covers ::convertValueBasedOnAttributeName
95
+ * @covers ::validateInput
96
+ */
97
+ public function testConvertValueBasedOnAttributeNameValidation () {
98
+ $ this ->expectException (AttributeException::class);
99
+ $ this ->expectExceptionMessage ('Warning: test_attr value is NULL ' );
100
+ $ this ->invokeStaticMethod (
101
+ AttributeConverter::class,
102
+ 'convertValueBasedOnAttributeName ' ,
103
+ ['' , 'test_attr ' ]
104
+ );
105
+ }
106
+
107
+ /**
108
+ * @covers ::validateInput
109
+ */
110
+ public function testValidateInput () {
111
+ $ this ->expectException (AttributeException::class);
112
+ $ this ->expectExceptionMessage ('Warning: test_attr value is NULL ' );
113
+ $ this ->invokeStaticMethod (
114
+ AttributeConverter::class,
115
+ 'validateInput ' ,
116
+ ['' , 'test_attr ' ]
117
+ );
118
+ }
119
+
120
+ }
0 commit comments