@@ -243,6 +243,49 @@ public function testIndexValidation(): void
243243 } catch (Exception $ e ) {
244244 $ this ->assertEquals ($ errorMessage , $ e ->getMessage ());
245245 }
246+
247+
248+ $ indexes = [
249+ new Document ([
250+ '$id ' => ID ::custom ('index_negative_length ' ),
251+ 'type ' => Database::INDEX_KEY ,
252+ 'attributes ' => ['title1 ' ],
253+ 'lengths ' => [-1 ],
254+ 'orders ' => [],
255+ ]),
256+ ];
257+
258+ $ errorMessage = 'Negative index length provided for title1 ' ;
259+ $ this ->assertFalse ($ validator ->isValid ($ indexes [0 ]));
260+ $ this ->assertEquals ($ errorMessage , $ validator ->getDescription ());
261+
262+ try {
263+ static ::getDatabase ()->createCollection (ID ::unique (), $ attributes , $ indexes );
264+ $ this ->fail ('Failed to throw exception ' );
265+ } catch (Exception $ e ) {
266+ $ this ->assertEquals ($ errorMessage , $ e ->getMessage ());
267+ }
268+
269+ $ indexes = [
270+ new Document ([
271+ '$id ' => ID ::custom ('index_extra_lengths ' ),
272+ 'type ' => Database::INDEX_KEY ,
273+ 'attributes ' => ['title1 ' , 'title2 ' ],
274+ 'lengths ' => [100 , 100 , 100 ],
275+ 'orders ' => [],
276+ ]),
277+ ];
278+
279+ $ errorMessage = 'Invalid index lengths. Count of lengths must be equal or less than the number of attributes. ' ;
280+ $ this ->assertFalse ($ validator ->isValid ($ indexes [0 ]));
281+ $ this ->assertEquals ($ errorMessage , $ validator ->getDescription ());
282+
283+ try {
284+ static ::getDatabase ()->createCollection (ID ::unique (), $ attributes , $ indexes );
285+ $ this ->fail ('Failed to throw exception ' );
286+ } catch (Exception $ e ) {
287+ $ this ->assertEquals ($ errorMessage , $ e ->getMessage ());
288+ }
246289 }
247290
248291 public function testRenameIndex (): void
0 commit comments