Skip to content

Commit 9142e19

Browse files
committed
test COUNT_RECURSIVE
1 parent 6686d85 commit 9142e19

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

tests/PHPStan/Analyser/nsrt/list-count2.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,68 @@ function dontNarrowEmpty(array $arrB): void
157157
assertType('array{}', $arrA);
158158
}
159159

160+
/**
161+
* @param non-empty-list<int> $listA
162+
* @param list<int> $listB
163+
*/
164+
public function supportsNormalCount($listA, array $listB): void
165+
{
166+
if (count($listA, COUNT_NORMAL) === count($listB)) {
167+
assertType('non-empty-list<int>', $listA);
168+
assertType('non-empty-list<int>', $listB);
169+
}
170+
assertType('non-empty-list<int>', $listA);
171+
assertType('list<int>', $listB);
172+
}
173+
174+
/**
175+
* @param array{int, int, int} $arrA
176+
* @param list $arrB
177+
*/
178+
function skipRecursiveLeftCount($arrA, array $arrB): void
179+
{
180+
if (count($arrB) < 2) {
181+
return;
182+
}
183+
184+
if (count($arrA, COUNT_RECURSIVE) == count($arrB)) {
185+
assertType('array{int, int, int}', $arrA);
186+
assertType('non-empty-list', $arrB);
187+
}
188+
assertType('array{int, int, int}', $arrA);
189+
assertType('non-empty-list', $arrB);
190+
}
191+
192+
/**
193+
* @param array{int, int, int} $arrA
194+
* @param list $arrB
195+
*/
196+
function skipRecursiveRightCount($arrA, array $arrB): void
197+
{
198+
if (count($arrB) < 2) {
199+
return;
200+
}
201+
202+
if (count($arrA) == count($arrB, COUNT_RECURSIVE)) {
203+
assertType('array{int, int, int}', $arrA);
204+
assertType('non-empty-list', $arrB);
205+
}
206+
assertType('array{int, int, int}', $arrA);
207+
assertType('non-empty-list', $arrB);
208+
}
209+
210+
/**
211+
* @param non-empty-array<int> $arrA
212+
* @param array<int> $arrB
213+
*/
214+
public function skipRecursiveCount($arrA, array $arrB): void
215+
{
216+
if (count($arrA, COUNT_RECURSIVE) == count($arrB)) {
217+
assertType('non-empty-array<int>', $arrA);
218+
assertType('non-empty-array<int>', $arrB);
219+
}
220+
assertType('non-empty-array<int>', $arrA);
221+
assertType('array<int>', $arrB);
222+
}
223+
160224
}

0 commit comments

Comments
 (0)