Skip to content

Commit 45fb724

Browse files
Rework tests
1 parent da76a4b commit 45fb724

1 file changed

Lines changed: 34 additions & 11 deletions

File tree

tests/PHPStan/Analyser/nsrt/bug-6799.php

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44

55
use function PHPStan\Testing\assertType;
66

7+
/**
8+
* @param array<int> $items
9+
*/
10+
function functionProcessInts(array &$items): void
11+
{
12+
$items = [1, 2];
13+
}
14+
15+
/**
16+
* @param array<string> $items
17+
*/
18+
function functionProcessStrings(array &$items): void
19+
{
20+
$items = ['a', 'b'];
21+
}
22+
723
class HelloWorld
824
{
925
/**
@@ -53,41 +69,48 @@ protected function testParamOut(): void
5369
}
5470

5571
/**
56-
* @param array<mixed> $items
57-
* @param-out list<string> $items
72+
* @param array<int> $items
73+
*/
74+
protected function processInts(array &$items): void
75+
{
76+
$items = [1, 2];
77+
}
78+
79+
/**
80+
* @param array<string> $items
5881
*/
59-
protected function processWithParamOutStrings(array &$items): void
82+
protected function processStrings(array &$items): void
6083
{
6184
$items = ['a', 'b'];
6285
}
6386

6487
/**
65-
* @param 'processWithParamOut'|'processWithParamOutStrings' $method
88+
* @param 'Bug6799\functionProcessInts'|'Bug6799\functionProcessStrings' $function
6689
*/
67-
protected function testUnionStringCallbacks(string $method): void
90+
protected function testUnionStringCallbacks(string $function): void
6891
{
6992
$items = [];
70-
call_user_func_array([$this, $method], [&$items]);
71-
assertType('list<int|string>', $items);
93+
call_user_func_array($function, [&$items]);
94+
assertType('mixed', $items); // Could be array<int>|array<string>
7295
}
7396

7497
/**
75-
* @param array{$this, 'processWithParamOut'}|array{$this, 'processWithParamOutStrings'} $callback
98+
* @param array{$this, 'processInts'}|array{$this, 'processStrings'} $callback
7699
*/
77100
protected function testUnionArrayCallbacks(array $callback): void
78101
{
79102
$items = [];
80103
call_user_func_array($callback, [&$items]);
81-
assertType('list<int|string>', $items);
104+
assertType('mixed', $items); // Could be array<int>|array<string>
82105
}
83106

84107
/**
85-
* @param 'processWithParamOut'|array{$this, 'processWithParamOutStrings'} $callback
108+
* @param 'Bug6799\functionProcessInts'|array{$this, 'processStrings'} $callback
86109
*/
87110
protected function testMixedUnionCallback($callback): void
88111
{
89112
$items = [];
90113
call_user_func_array($callback, [&$items]);
91-
assertType('array{}', $items);
114+
assertType('mixed', $items); // Could be array<int>|array<string>
92115
}
93116
}

0 commit comments

Comments
 (0)