@@ -132,4 +132,130 @@ public function testCheckExistsIndexArrayRecursive(): void
132132 self ::assertTrue (Arrays::checkExistIndexArrayRecursive ($ array , 'subcategoria1 ' ));
133133 self ::assertFalse (Arrays::checkExistIndexArrayRecursive ($ array , 'mercado ' ));
134134 }
135+
136+ public function testCheckExistsIndexArrayRecursiveWithNull (): void
137+ {
138+ self ::assertFalse (Arrays::checkExistIndexArrayRecursive (null , 'key ' ));
139+ self ::assertFalse (Arrays::checkExistIndexArrayRecursive (['key ' => 'value ' ], null ));
140+ self ::assertFalse (Arrays::checkExistIndexArrayRecursive (null , null ));
141+ }
142+
143+ public function testSearchKeyReturnsCorrectPosition (): void
144+ {
145+ self ::assertSame (0 , Arrays::searchKey ($ this ->simpleArray , 'primeiro ' ));
146+ self ::assertSame (1 , Arrays::searchKey ($ this ->simpleArray , 'segundo ' ));
147+ }
148+
149+ public function testRenameKeyPreservesOrder (): void
150+ {
151+ $ array = ['a ' => 1 , 'b ' => 2 , 'c ' => 3 ];
152+ Arrays::renameKey ($ array , 'b ' , 'novo_b ' );
153+ $ keys = array_keys ($ array );
154+ self ::assertSame (['a ' , 'novo_b ' , 'c ' ], $ keys );
155+ self ::assertSame (2 , $ array ['novo_b ' ]);
156+ }
157+
158+ public function testCheckExistIndexByValueInNestedArray (): void
159+ {
160+ self ::assertTrue (Arrays::checkExistIndexByValue ($ this ->fruitArray , 'Maçã ' ));
161+ self ::assertTrue (Arrays::checkExistIndexByValue ($ this ->fruitArray , 'Acelga ' ));
162+ self ::assertFalse (Arrays::checkExistIndexByValue ($ this ->fruitArray , 'Banana ' ));
163+ }
164+
165+ public function testFindValueByKeyCaseInsensitive (): void
166+ {
167+ $ result = Arrays::findValueByKey ($ this ->fruitArray , 'FRUTA_1 ' );
168+ self ::assertNotEmpty ($ result );
169+ }
170+
171+ public function testFindValueByKeyNested (): void
172+ {
173+ $ result = Arrays::findValueByKey ($ this ->fruitArray , 'verdura_1 ' );
174+ self ::assertArrayHasKey ('verduras ' , $ result );
175+ }
176+
177+ public function testFindValueByKeyNotFound (): void
178+ {
179+ $ result = Arrays::findValueByKey ($ this ->fruitArray , 'nao_existe ' );
180+ self ::assertEmpty ($ result );
181+ }
182+
183+ public function testFindIndexByValueWithInt (): void
184+ {
185+ $ array = ['a ' => 1 , 'b ' => 2 , 'nested ' => ['c ' => 3 ]];
186+ $ result = Arrays::findIndexByValue ($ array , 2 );
187+ self ::assertArrayHasKey ('b ' , $ result );
188+ self ::assertSame (2 , $ result ['b ' ]);
189+ }
190+
191+ public function testFindIndexByValueWithBool (): void
192+ {
193+ $ array = ['ativo ' => true , 'inativo ' => false ];
194+ $ result = Arrays::findIndexByValue ($ array , true );
195+ self ::assertArrayHasKey ('ativo ' , $ result );
196+ }
197+
198+ public function testFindIndexByValueNested (): void
199+ {
200+ $ array = ['nivel1 ' => ['nivel2 ' => ['chave ' => 'valor_buscado ' ]]];
201+ $ result = Arrays::findIndexByValue ($ array , 'valor_buscado ' );
202+ self ::assertNotEmpty ($ result );
203+ self ::assertArrayHasKey ('nivel1 ' , $ result );
204+ }
205+
206+ public function testFindIndexByValueNotFound (): void
207+ {
208+ $ result = Arrays::findIndexByValue ($ this ->fruitArray , 'nao_existe ' );
209+ self ::assertEmpty ($ result );
210+ }
211+
212+ public function testConvertArrayToXmlWithAttrKey (): void
213+ {
214+ $ array = [
215+ ['@attr ' => 'item ' , 'nome ' => 'Produto 1 ' ],
216+ ['@attr ' => 'item ' , 'nome ' => 'Produto 2 ' ],
217+ ];
218+ $ xml = new SimpleXMLElement ('<root/> ' );
219+ Arrays::convertArrayToXml ($ array , $ xml );
220+ $ xmlString = $ xml ->asXML ();
221+ self ::assertIsString ($ xmlString );
222+ self ::assertTrue ($ this ->isValidXml ($ xmlString ));
223+ self ::assertStringContainsString ('<item> ' , $ xmlString );
224+ }
225+
226+ public function testConvertArrayToXmlWithSpecialChars (): void
227+ {
228+ $ array = ['texto ' => 'Valor com <tag> & "aspas" ' ];
229+ $ xml = new SimpleXMLElement ('<root/> ' );
230+ Arrays::convertArrayToXml ($ array , $ xml );
231+ $ xmlString = $ xml ->asXML ();
232+ self ::assertIsString ($ xmlString );
233+ self ::assertTrue ($ this ->isValidXml ($ xmlString ));
234+ }
235+
236+ public function testConvertJsonIndexToArrayInvalidJson (): void
237+ {
238+ $ array = ['campo ' => 'texto normal não é json ' ];
239+ Arrays::convertJsonIndexToArray ($ array );
240+ self ::assertSame ('texto normal não é json ' , $ array ['campo ' ]);
241+ }
242+
243+ public function testConvertJsonIndexToArrayEmptyString (): void
244+ {
245+ $ array = ['campo ' => '' ];
246+ Arrays::convertJsonIndexToArray ($ array );
247+ self ::assertSame ('' , $ array ['campo ' ]);
248+ }
249+
250+ public function testConvertJsonIndexToArrayNestedJson (): void
251+ {
252+ $ array = [
253+ 'nivel1 ' => [
254+ 'dados ' => '{"chave": "valor"} ' ,
255+ ],
256+ ];
257+ Arrays::convertJsonIndexToArray ($ array );
258+ self ::assertIsArray ($ array ['nivel1 ' ]['dados ' ]);
259+ self ::assertSame ('valor ' , $ array ['nivel1 ' ]['dados ' ]['chave ' ]);
260+ }
135261}
0 commit comments