@@ -25,6 +25,7 @@ class ArrayPaginatorTest extends TestCase
2525{
2626 use BuildArrayIteratorTrait;
2727
28+ /** @var ?array<mixed> */
2829 protected static ?array $ defaultArray = null ;
2930
3031 public function testMissingDataOption (): void
@@ -70,8 +71,8 @@ public function testBadNumberCountOption(): void
7071 /**
7172 * @dataProvider getTestCountProvider
7273 *
73- * @param int<1, max> $maxPerPage
74- * @param \ArrayIterator<int|string, mixed>|array $data
74+ * @param int<1, max> $maxPerPage
75+ * @param \ArrayIterator<int|string, mixed>|array<mixed> $data
7576 */
7677 public function testCount (mixed $ page , int $ maxPerPage , \ArrayIterator |array $ data , int $ expectedValue ): void
7778 {
@@ -81,31 +82,34 @@ public function testCount(mixed $page, int $maxPerPage, \ArrayIterator|array $da
8182 $ this ->assertCount ($ expectedValue , $ paginator );
8283 }
8384
85+ /**
86+ * @return array<array{mixed, int<1, max>, \ArrayIterator<int|string, mixed>|array<mixed>, int}>
87+ */
8488 public static function getTestCountProvider (): array
8589 {
8690 return [
87- [1 , 5 , static ::getDefaultArray (), 52 ],
88- [3 , 5 , static ::getDefaultArray (), 52 ],
89- [11 , 5 , static ::getDefaultArray (), 52 ],
91+ [1 , 5 , static ::getDefaultArray (), 52 ],
92+ [3 , 5 , static ::getDefaultArray (), 52 ],
93+ [11 , 5 , static ::getDefaultArray (), 52 ],
9094 [1 , 5 , [], 0 ], // No data
91- ['page ' , 5 , static ::getDefaultArray (), 52 ], // Bad page
92- [1000 , 5 , static ::getDefaultArray (), 52 ], // Page too high
95+ ['page ' , 5 , static ::getDefaultArray (), 52 ], // Bad page
96+ [1000 , 5 , static ::getDefaultArray (), 52 ], // Page too high
9397
94- [1 , 5 , static ::getDefaultIterator (), 52 ],
95- [3 , 5 , static ::getDefaultIterator (), 52 ],
96- [11 , 5 , static ::getDefaultIterator (), 52 ],
98+ [1 , 5 , static ::getDefaultIterator (), 52 ],
99+ [3 , 5 , static ::getDefaultIterator (), 52 ],
100+ [11 , 5 , static ::getDefaultIterator (), 52 ],
97101 [1 , 5 , static ::createIterator ([]), 0 ], // No data
98- ['page ' , 5 , static ::getDefaultIterator (), 52 ], // Bad page
99- [1000 , 5 , static ::getDefaultIterator (), 52 ], // Page too high
102+ ['page ' , 5 , static ::getDefaultIterator (), 52 ], // Bad page
103+ [1000 , 5 , static ::getDefaultIterator (), 52 ], // Page too high
100104 ];
101105 }
102106
103107 /**
104108 * @dataProvider getTestGetIteratorProvider
105109 *
106- * @param int<1, max> $maxPerPage
107- * @param \ArrayIterator<int|string, mixed>|array $data
108- * @param \ArrayIterator<int|string, mixed> $expectedValue
110+ * @param int<1, max> $maxPerPage
111+ * @param \ArrayIterator<int|string, mixed>|array<mixed> $data
112+ * @param \ArrayIterator<int|string, mixed> $expectedValue
109113 */
110114 public function testGetIterator (mixed $ page , int $ maxPerPage , \ArrayIterator |array $ data , \ArrayIterator $ expectedValue ): void
111115 {
@@ -115,32 +119,35 @@ public function testGetIterator(mixed $page, int $maxPerPage, \ArrayIterator|arr
115119 $ this ->assertEquals ($ expectedValue , $ paginator ->getIterator ());
116120 }
117121
122+ /**
123+ * @return array<array{mixed, int<1, max>, \ArrayIterator<int|string, mixed>|array<mixed>, \ArrayIterator<int|string, mixed>}>
124+ */
118125 public static function getTestGetIteratorProvider (): array
119126 {
120127 return [
121- [1 , 5 , static ::getDefaultArray (), new \ ArrayIterator ([0 , 1 , 2 , 3 , 4 ])],
122- [3 , 5 , static ::getDefaultArray (), new \ ArrayIterator ([10 , 11 , 12 , 13 , 14 ])],
123- [11 , 5 , static ::getDefaultArray (), new \ ArrayIterator ([50 , 51 ])],
124- [1 , 5 , [], new \ ArrayIterator ()], // No data
125- ['page ' , 5 , static ::getDefaultArray (), new \ ArrayIterator ([0 , 1 , 2 , 3 , 4 ])], // Bad page
126- [1000 , 5 , static ::getDefaultArray (), new \ ArrayIterator ([50 , 51 ])], // Page too high
127-
128- [1 , 5 , static ::getDefaultIterator (), new \ ArrayIterator ([0 , 1 , 2 , 3 , 4 ])],
129- [3 , 5 , static ::getDefaultIterator (), new \ ArrayIterator ([10 , 11 , 12 , 13 , 14 ])],
130- [11 , 5 , static ::getDefaultIterator (), new \ ArrayIterator ([50 , 51 ])],
131- [1 , 5 , static ::createIterator ([]), new \ ArrayIterator ()], // No data
132- ['page ' , 5 , static ::getDefaultIterator (), new \ ArrayIterator ([0 , 1 , 2 , 3 , 4 ])], // Bad page
133- [1000 , 5 , static ::getDefaultIterator (), new \ ArrayIterator ([50 , 51 ])], // Page too high
128+ [1 , 5 , static ::getDefaultArray (), static :: createIterator ([0 , 1 , 2 , 3 , 4 ])],
129+ [3 , 5 , static ::getDefaultArray (), static :: createIterator ([10 , 11 , 12 , 13 , 14 ])],
130+ [11 , 5 , static ::getDefaultArray (), static :: createIterator ([50 , 51 ])],
131+ [1 , 5 , [], static :: createIterator ()], // No data
132+ ['page ' , 5 , static ::getDefaultArray (), static :: createIterator ([0 , 1 , 2 , 3 , 4 ])], // Bad page
133+ [1000 , 5 , static ::getDefaultArray (), static :: createIterator ([50 , 51 ])], // Page too high
134+
135+ [1 , 5 , static ::getDefaultIterator (), static :: createIterator ([0 , 1 , 2 , 3 , 4 ])],
136+ [3 , 5 , static ::getDefaultIterator (), static :: createIterator ([10 , 11 , 12 , 13 , 14 ])],
137+ [11 , 5 , static ::getDefaultIterator (), static :: createIterator ([50 , 51 ])],
138+ [1 , 5 , static ::createIterator ([]), static :: createIterator ()], // No data
139+ ['page ' , 5 , static ::getDefaultIterator (), static :: createIterator ([0 , 1 , 2 , 3 , 4 ])], // Bad page
140+ [1000 , 5 , static ::getDefaultIterator (), static :: createIterator ([50 , 51 ])], // Page too high
134141 ];
135142 }
136143
137144 /**
138145 * @dataProvider getTestCountWithCountProvider
139146 *
140- * @param int<1, max> $maxPerPage
141- * @param \ArrayIterator<int|string, mixed>|array $data
142- * @param \ArrayIterator<int|string, mixed> $expectedIterator
143- * @param int<0, max> $count
147+ * @param int<1, max> $maxPerPage
148+ * @param \ArrayIterator<int|string, mixed>|array<mixed> $data
149+ * @param \ArrayIterator<int|string, mixed> $expectedIterator
150+ * @param int<0, max> $count
144151 */
145152 public function testWithCount (mixed $ page , int $ maxPerPage , \ArrayIterator |array $ data , int $ count , int $ expectedCountPages , \ArrayIterator $ expectedIterator ): void
146153 {
@@ -153,28 +160,41 @@ public function testWithCount(mixed $page, int $maxPerPage, \ArrayIterator|array
153160 $ this ->assertEquals ($ expectedIterator , $ paginator ->getIterator ());
154161 }
155162
163+ /**
164+ * @return array<array{mixed, int<1, max>, \ArrayIterator<int|string, mixed>|array<mixed>, int<0, max>, int, \ArrayIterator<int|string, mixed>}>
165+ */
156166 public static function getTestCountWithCountProvider (): array
157167 {
158168 return [
159- [1 , 5 , static ::getDefaultArray (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
160- [3 , 5 , static ::getDefaultArray (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
161- [11 , 5 , static ::getDefaultArray (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
162- [1 , 5 , [], 0 , 1 , new \ ArrayIterator ()], // No data
163- ['page ' , 5 , static ::getDefaultArray (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))], // Bad page
164- [1000 , 5 , static ::getDefaultArray (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))], // Page too high
165-
166- [1 , 5 , static ::getDefaultIterator (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
167- [3 , 5 , static ::getDefaultIterator (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
168- [11 , 5 , static ::getDefaultIterator (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))],
169- [1 , 5 , static ::createIterator ([]), 0 , 1 , new \ ArrayIterator ()], // No data
170- ['page ' , 5 , static ::getDefaultIterator (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))], // Bad page
171- [1000 , 5 , static ::getDefaultIterator (), 202 , 41 , new \ ArrayIterator (range (0 , 51 ))], // Page too high
169+ [1 , 5 , static ::getDefaultArray (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
170+ [3 , 5 , static ::getDefaultArray (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
171+ [11 , 5 , static ::getDefaultArray (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
172+ [1 , 5 , [], 0 , 1 , static :: createIterator ()], // No data
173+ ['page ' , 5 , static ::getDefaultArray (), 202 , 41 , static :: createIterator (range (0 , 51 ))], // Bad page
174+ [1000 , 5 , static ::getDefaultArray (), 202 , 41 , static :: createIterator (range (0 , 51 ))], // Page too high
175+
176+ [1 , 5 , static ::getDefaultIterator (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
177+ [3 , 5 , static ::getDefaultIterator (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
178+ [11 , 5 , static ::getDefaultIterator (), 202 , 41 , static :: createIterator (range (0 , 51 ))],
179+ [1 , 5 , static ::createIterator ([]), 0 , 1 , static :: createIterator ()], // No data
180+ ['page ' , 5 , static ::getDefaultIterator (), 202 , 41 , static :: createIterator (range (0 , 51 ))], // Bad page
181+ [1000 , 5 , static ::getDefaultIterator (), 202 , 41 , static :: createIterator (range (0 , 51 ))], // Page too high
172182 ];
173183 }
174184
175185 /**
176- * @param int<1, max> $perPage
177- * @param \ArrayIterator<int|string, mixed>|array $data
186+ * @param array<mixed> $data
187+ *
188+ * @return \ArrayIterator<int|string, mixed>
189+ */
190+ public static function createIterator (array $ data = []): \ArrayIterator
191+ {
192+ return new \ArrayIterator ($ data );
193+ }
194+
195+ /**
196+ * @param int<1, max> $perPage
197+ * @param \ArrayIterator<int|string, mixed>|array<mixed> $data
178198 *
179199 * @return PaginatorOptions
180200 */
@@ -201,6 +221,9 @@ protected function createPaginator(array $options): ArrayPaginator
201221 return new ArrayPaginator ($ options );
202222 }
203223
224+ /**
225+ * @return array<mixed>
226+ */
204227 protected static function getDefaultArray (): array
205228 {
206229 if (null === static ::$ defaultArray ) {
0 commit comments