Skip to content

Commit 08c8bd4

Browse files
Add test
1 parent 01f7ac0 commit 08c8bd4

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug9456;
4+
5+
use ArrayAccess;
6+
7+
use function PHPStan\Testing\assertType;
8+
9+
/**
10+
* @template TKey of array-key
11+
* @template TValue of mixed
12+
*
13+
* @implements ArrayAccess<TKey, TValue>
14+
*/
15+
class Collection implements ArrayAccess {
16+
/**
17+
* @param (callable(TValue, TKey): bool)|TValue|string $key
18+
* @param TValue|string|null $operator
19+
* @param TValue|null $value
20+
* @return static<int<0, 1>, static<TKey, TValue>>
21+
*/
22+
public function partition($key, $operator = null, $value = null) {} // @phpstan-ignore-line
23+
24+
/**
25+
* @param TKey $key
26+
* @return TValue
27+
*/
28+
public function offsetGet($key): mixed { return null; } // @phpstan-ignore-line
29+
30+
/**
31+
* @param TKey $key
32+
* @return bool
33+
*/
34+
public function offsetExists($key): bool { return true; }
35+
36+
/**
37+
* @param TKey|null $key
38+
* @param TValue $value
39+
* @return void
40+
*/
41+
public function offsetSet($key, $value): void {}
42+
43+
/**
44+
* @param TKey $key
45+
* @return void
46+
*/
47+
public function offsetUnset($key): void {}
48+
}
49+
50+
class HelloWorld
51+
{
52+
/**
53+
* @param Collection<int, string> $collection
54+
*/
55+
public function sayHello(Collection $collection): void
56+
{
57+
$result = $collection->partition('key');
58+
59+
assertType(
60+
'Bug9456\Collection<int<0, 1>, Bug9456\Collection<int, string>>',
61+
$result
62+
);
63+
assertType('Bug9456\Collection<int, string>', $result[0]);
64+
assertType('Bug9456\Collection<int, string>', $result[1]);
65+
66+
[$one, $two] = $collection->partition('key');
67+
68+
assertType('Bug9456\Collection<int, string>', $one);
69+
assertType('Bug9456\Collection<int, string>', $two);
70+
}
71+
}

0 commit comments

Comments
 (0)