@@ -210,6 +210,33 @@ public function testNonSequentialError(callable $arrayGetter)
210210 ArrayView::toView ($ nonSequentialArray );
211211 }
212212
213+ /**
214+ * @dataProvider dataProviderForBadIndexList
215+ */
216+ public function testReadBadIndexList (array $ source , array $ indexes )
217+ {
218+ $ view = ArrayView::toView ($ source );
219+ $ this ->expectException (IndexError::class);
220+ $ this ->expectExceptionMessage ('Some indexes are out of range. ' );
221+ $ _ = $ view [new IndexListSelector ($ indexes )];
222+ }
223+
224+ /**
225+ * @dataProvider dataProviderForBadIndexList
226+ */
227+ public function testWriteBadIndexList (array $ source , array $ indexes )
228+ {
229+ $ initialSource = [...$ source ];
230+ $ view = ArrayView::toView ($ source );
231+
232+ try {
233+ $ view [new IndexListSelector ($ indexes )] = $ indexes ;
234+ } catch (IndexError $ e ) {
235+ $ this ->assertSame ($ initialSource , [...$ view ]);
236+ $ this ->assertSame ('Some indexes are out of range. ' , $ e ->getMessage ());
237+ }
238+ }
239+
213240 public function dataProviderForOutOfRangeIndexes (): array
214241 {
215242 return [
@@ -379,6 +406,25 @@ public function dataProviderForUnsetError(): array
379406 ];
380407 }
381408
409+ public function dataProviderForBadIndexList (): array
410+ {
411+ return [
412+ [[1 ], [0 , 1 ]],
413+ [[1 ], [1 , -1 , -2 ]],
414+ [[1 ], [0 , 1 , 0 , -1 , -2 ]],
415+ [[1 ], [1 , -1 ]],
416+ [[1 ], [0 , 0 , -2 ]],
417+ [[1 , 2 ], [2 ]],
418+ [[1 , 2 ], [1 , 2 ]],
419+ [[1 , 2 ], [0 , 1 , 2 ]],
420+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 3 , 5 , -10 ]],
421+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [9 , 5 , 3 , 1 ]],
422+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 10 , 9 , 7 ]],
423+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [-10 , 1 , 7 , 10 ]],
424+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 1 , 50 , 5 , 3 ]],
425+ ];
426+ }
427+
382428 public function dataProviderForNonSequentialError (): array
383429 {
384430 return [
0 commit comments