forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-11569.php
More file actions
74 lines (63 loc) · 1.63 KB
/
bug-11569.php
File metadata and controls
74 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php declare(strict_types = 1);
namespace Bug11569;
use function PHPStan\Testing\assertType;
class HelloWorld
{
/** @return array{name: string, age: int} */
public function getFoo(): array
{
return ['name' => 'John Doe', 'age' => 30];
}
public function testKsort(): void
{
$value = ['name' => 'John Doe', 'age' => 30];
ksort($value);
assertType("array{age: 30, name: 'John Doe'}", $value);
}
public function testKrsort(): void
{
$value = ['name' => 'John Doe', 'age' => 30];
krsort($value);
assertType("array{name: 'John Doe', age: 30}", $value);
}
public function testKsortWithArrayValues(): void
{
$data = $this->getFoo();
ksort($data);
assertType('array{age: int, name: string}', $data);
$values = array_values($data);
assertType('array{int, string}', $values);
}
public function testKsortWithArrayCombine(): void
{
$data = $this->getFoo();
ksort($data);
$values = array_values($data);
$result = array_combine(['age', 'name'], $values);
assertType('array{age: int, name: string}', $result);
}
public function testKsortIntegerKeys(): void
{
$list = ['A', 'C', 'B'];
ksort($list);
assertType("array{'A', 'C', 'B'}", $list);
}
public function testKrsortIntegerKeys(): void
{
$list = ['A', 'C', 'B'];
krsort($list);
assertType("array{2: 'B', 1: 'C', 0: 'A'}", $list);
}
public function testKsortStringKeys(): void
{
$value = ['c' => 3, 'a' => 1, 'b' => 2];
ksort($value);
assertType('array{a: 1, b: 2, c: 3}', $value);
}
public function testKrsortStringKeys(): void
{
$value = ['c' => 3, 'a' => 1, 'b' => 2];
krsort($value);
assertType('array{c: 3, b: 2, a: 1}', $value);
}
}