@@ -100,6 +100,101 @@ public function testRunDoesTheBasics(): void
100100 $ this ->assertFalse ($ this ->validation ->run ($ data ));
101101 }
102102
103+ /**
104+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/5368
105+ *
106+ * @dataProvider arrayDataProvider
107+ *
108+ * @param mixed $value
109+ */
110+ public function testCanValidatetArrayData ($ value , bool $ expected ): void
111+ {
112+ $ this ->validation ->setRules (['arr ' => 'is_array ' ]);
113+
114+ $ data ['arr ' ] = $ value ;
115+ $ this ->assertSame ($ expected , $ this ->validation ->run ($ data ));
116+ }
117+
118+ public function arrayDataProvider (): Generator
119+ {
120+ yield 'list array ' => [
121+ [1 , 2 , 3 , 4 , 5 ],
122+ false , // incorrect
123+ ];
124+
125+ yield 'associative array ' => [
126+ [
127+ 'username ' => 'admin001 ' ,
128+ 'role ' => 'administrator ' ,
129+ 'usepass ' => 0 ,
130+ ],
131+ false , // incorrect
132+ ];
133+
134+ yield 'int ' => [
135+ 0 ,
136+ false ,
137+ ];
138+
139+ yield 'string int ' => [
140+ '0 ' ,
141+ false ,
142+ ];
143+
144+ yield 'bool ' => [
145+ false ,
146+ false ,
147+ ];
148+
149+ yield 'null ' => [
150+ null ,
151+ false ,
152+ ];
153+ }
154+
155+ /**
156+ * @see https://github.com/codeigniter4/CodeIgniter4/issues/5374
157+ *
158+ * @dataProvider isIntInvalidTypeDataProvider
159+ *
160+ * @param mixed $value
161+ */
162+ public function testIsIntWithInvalidTypeData ($ value , bool $ expected ): void
163+ {
164+ $ this ->validation ->setRules (['foo ' => 'is_int ' ]);
165+
166+ $ data = ['foo ' => $ value ];
167+ $ this ->assertSame ($ expected , $ this ->validation ->run ($ data ));
168+ }
169+
170+ public function isIntInvalidTypeDataProvider (): Generator
171+ {
172+ yield 'array with int ' => [
173+ [555 ],
174+ true , // incorrect
175+ ];
176+
177+ yield 'empty array ' => [
178+ [],
179+ false ,
180+ ];
181+
182+ yield 'bool true ' => [
183+ true ,
184+ false ,
185+ ];
186+
187+ yield 'bool false ' => [
188+ false ,
189+ false ,
190+ ];
191+
192+ yield 'null ' => [
193+ null ,
194+ false ,
195+ ];
196+ }
197+
103198 public function testRunReturnsLocalizedErrors (): void
104199 {
105200 $ data = ['foo ' => 'notanumber ' ];
0 commit comments