@@ -22,7 +22,7 @@ public function testStringBoolNotValid(): void
22
22
// false converts to empty string since we use implode
23
23
self ::assertEquals ([
24
24
Enum::INVALID => "The value 'false' not in enum list. "
25
- ],$ messages );
25
+ ], $ messages );
26
26
}
27
27
28
28
public function testStringCastsToInt ()
@@ -46,7 +46,7 @@ public function testStringWithQuotes()
46
46
self ::assertNotEmpty ($ messages = $ validator ->getMessages ());
47
47
self ::assertEquals ([
48
48
Enum::INVALID => "The value 'another' not in enum list. "
49
- ],$ messages );
49
+ ], $ messages );
50
50
}
51
51
52
52
public function testString ()
@@ -59,6 +59,78 @@ public function testString()
59
59
self ::assertNotEmpty ($ messages = $ validator ->getMessages ());
60
60
self ::assertEquals ([
61
61
Enum::INVALID => "The value 'another' not in enum list. "
62
- ],$ messages );
62
+ ], $ messages );
63
63
}
64
- }
64
+
65
+ public function testArrayInt ()
66
+ {
67
+ $ validator = new Enum (['allowed ' => [
68
+ "random " ,
69
+ "anotherRandom " ,
70
+ ]]);
71
+
72
+ self ::assertFalse ($ validator ->isValid ([1 ]));
73
+ self ::assertNotEmpty ($ messages = $ validator ->getMessages ());
74
+ self ::assertEquals ([
75
+ Enum::INVALID => "The value '1' not in enum list. "
76
+ ], $ messages );
77
+ }
78
+
79
+ public function testArrayEmpty ()
80
+ {
81
+ $ validator = new Enum (['allowed ' => [
82
+ "random " ,
83
+ "anotherRandom " ,
84
+ ]]);
85
+
86
+ self ::assertTrue ($ validator ->isValid ([]));
87
+ self ::assertEmpty ($ validator ->getMessages ());
88
+ }
89
+
90
+ public function testValidArrayOneItem ()
91
+ {
92
+ $ validator = new Enum (['allowed ' => [
93
+ "random " ,
94
+ "anotherRandom " ,
95
+ ]]);
96
+ self ::assertTrue ($ validator ->isValid (["random " ]));
97
+ self ::assertEmpty ($ validator ->getMessages ());
98
+ }
99
+
100
+ public function testValidArraySeveralItems ()
101
+ {
102
+ $ validator = new Enum (['allowed ' => [
103
+ "random " ,
104
+ "anotherRandom " ,
105
+ "anotherRandomWord " ,
106
+ ]]);
107
+ self ::assertTrue ($ validator ->isValid (["random " , "anotherRandom " ]));
108
+ self ::assertEmpty ($ validator ->getMessages ());
109
+ }
110
+
111
+ public function testInvalidArrayOneItem ()
112
+ {
113
+ $ validator = new Enum (['allowed ' => [
114
+ "random " ,
115
+ "anotherRandom " ,
116
+ ]]);
117
+ self ::assertFalse ($ validator ->isValid (["anotherRandomWord " ]));
118
+ self ::assertNotEmpty ($ messages = $ validator ->getMessages ());
119
+ self ::assertEquals ([
120
+ Enum::INVALID => "The value 'anotherRandomWord' not in enum list. "
121
+ ], $ messages );
122
+ }
123
+
124
+ public function testInvalidArraySeveralItems ()
125
+ {
126
+ $ validator = new Enum (['allowed ' => [
127
+ "random " ,
128
+ "anotherRandom " ,
129
+ ]]);
130
+ self ::assertFalse ($ validator ->isValid (["anotherRandomWord " , "sameRandomWord " ]));
131
+ self ::assertNotEmpty ($ messages = $ validator ->getMessages ());
132
+ self ::assertEquals ([
133
+ Enum::INVALID => "The value 'anotherRandomWord' not in enum list. "
134
+ ], $ messages );
135
+ }
136
+ }
0 commit comments