22
33namespace Smoren \ArrayView \Tests \Unit \ArrayIndexListView ;
44
5+ use Smoren \ArrayView \Exceptions \IndexError ;
56use Smoren \ArrayView \Selectors \IndexListSelector ;
6- use Smoren \ArrayView \Selectors \MaskSelector ;
7- use Smoren \ArrayView \Views \ArrayIndexListView ;
87use Smoren \ArrayView \Views \ArrayView ;
98
109class IssetTest extends \Codeception \Test \Unit
1110{
1211 /**
13- * @dataProvider dataProviderForIssetTrue
12+ * @dataProvider dataProviderForIssetSingleTrue
1413 */
15- public function testIssetTrue (array $ source , array $ indexes )
14+ public function testIssetSingleTrue (array $ source , array $ indexes )
1615 {
1716 $ view = ArrayView::toView ($ source );
1817 $ subview = $ view ->subview (new IndexListSelector ($ indexes ));
@@ -28,9 +27,9 @@ public function testIssetTrue(array $source, array $indexes)
2827 }
2928
3029 /**
31- * @dataProvider dataProviderForIssetFalse
30+ * @dataProvider dataProviderForIssetSingleFalse
3231 */
33- public function testIssetFalse (array $ source , array $ indexes , array $ expected )
32+ public function testIssetSingleFalse (array $ source , array $ indexes , array $ expected )
3433 {
3534 $ view = ArrayView::toView ($ source );
3635 $ subview = $ view ->subview (new IndexListSelector ($ indexes ));
@@ -40,7 +39,36 @@ public function testIssetFalse(array $source, array $indexes, array $expected)
4039 }
4140 }
4241
43- public function dataProviderForIssetTrue (): array
42+ /**
43+ * @dataProvider dataProviderForIssetSelectorTrue
44+ */
45+ public function testIssetSelectorTrue (array $ source , array $ indexes )
46+ {
47+ $ view = ArrayView::toView ($ source );
48+
49+ $ this ->assertTrue (isset ($ view [new IndexListSelector ($ indexes )]));
50+
51+ $ subview = $ view ->subview (new IndexListSelector ($ indexes ));
52+ $ this ->assertSame (\count ($ indexes ), \count ($ subview ));
53+
54+ $ subview = $ view [new IndexListSelector ($ indexes )];
55+ $ this ->assertSame (\count ($ indexes ), \count ($ subview ));
56+ }
57+
58+ /**
59+ * @dataProvider dataProviderForIssetSelectorFalse
60+ */
61+ public function testIssetSelectorFalse (array $ source , array $ indexes )
62+ {
63+ $ view = ArrayView::toView ($ source );
64+
65+ $ this ->assertFalse (isset ($ view [new IndexListSelector ($ indexes )]));
66+
67+ $ this ->expectException (IndexError::class);
68+ $ _ = $ view [new IndexListSelector ($ indexes )];
69+ }
70+
71+ public function dataProviderForIssetSingleTrue (): array
4472 {
4573 return [
4674 [[1 ], [0 ]],
@@ -57,7 +85,7 @@ public function dataProviderForIssetTrue(): array
5785 ];
5886 }
5987
60- public static function dataProviderForIssetFalse (): array
88+ public function dataProviderForIssetSingleFalse (): array
6189 {
6290 return [
6391 [[], [], [-2 , -1 , 0 , 1 , 2 ]],
@@ -76,4 +104,46 @@ public static function dataProviderForIssetFalse(): array
76104 [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 1 , 5 , 5 , 3 ], [-8 , -7 , -6 , 5 , 6 , 7 ]],
77105 ];
78106 }
107+
108+ public function dataProviderForIssetSelectorTrue (): array
109+ {
110+ return [
111+ [[1 ], []],
112+ [[1 ], [0 ]],
113+ [[1 ], [-1 ]],
114+ [[1 ], [0 , 0 ]],
115+ [[1 ], [0 , 0 , 0 ]],
116+ [[1 , 2 ], []],
117+ [[1 , 2 ], [0 ]],
118+ [[1 , 2 ], [-1 , -2 ]],
119+ [[1 , 2 ], [1 ]],
120+ [[1 , 2 ], [0 , 1 ]],
121+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], []],
122+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 3 , 5 , 7 ]],
123+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [7 , 5 , 3 , 1 ]],
124+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 5 , 3 , 7 ]],
125+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [0 , 1 , 7 , 8 ]],
126+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], []],
127+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 1 , 5 , 5 , 3 ]],
128+ ];
129+ }
130+
131+ public function dataProviderForIssetSelectorFalse (): array
132+ {
133+ return [
134+ [[1 ], [0 , 1 ]],
135+ [[1 ], [1 , -1 , -2 ]],
136+ [[1 ], [0 , 1 , 0 , -1 , -2 ]],
137+ [[1 ], [1 , -1 ]],
138+ [[1 ], [0 , 0 , -2 ]],
139+ [[1 , 2 ], [2 ]],
140+ [[1 , 2 ], [1 , 2 ]],
141+ [[1 , 2 ], [0 , 1 , 2 ]],
142+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 3 , 5 , -10 ]],
143+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [9 , 5 , 3 , 1 ]],
144+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 10 , 9 , 7 ]],
145+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [-10 , 1 , 7 , 10 ]],
146+ [[1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ], [1 , 1 , 50 , 5 , 3 ]],
147+ ];
148+ }
79149}
0 commit comments