Skip to content

Commit 68876bc

Browse files
VincentLangletondrejmirtes
authored andcommitted
Add non regression test
1 parent 69d0151 commit 68876bc

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Bug11488Nsrt;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Foo
8+
{
9+
/**
10+
* @param array{mixed}|array{mixed, string|null, mixed} $row
11+
*/
12+
protected function test(array $row): string
13+
{
14+
if (count($row) !== 1) {
15+
assertType('array{mixed, string|null, mixed}', $row);
16+
17+
[$field, $operator, $value] = $row;
18+
assertType('string|null', $operator);
19+
} else {
20+
assertType('array{mixed}', $row);
21+
}
22+
23+
if (count($row) === 1) {
24+
assertType('array{mixed}', $row);
25+
} else {
26+
assertType('array{mixed, string|null, mixed}', $row);
27+
}
28+
29+
if (count($row) === 2) {
30+
assertType('*NEVER*', $row);
31+
} else {
32+
assertType('array{mixed, string|null, mixed}|array{mixed}', $row);
33+
}
34+
35+
if (count($row) !== 2) {
36+
assertType('array{mixed, string|null, mixed}|array{mixed}', $row);
37+
} else {
38+
assertType('*NEVER*', $row);
39+
}
40+
41+
if (count($row) === 3) {
42+
assertType('array{mixed, string|null, mixed}', $row);
43+
} else {
44+
assertType('array{mixed}', $row);
45+
}
46+
47+
return '';
48+
}
49+
50+
/**
51+
* @param array{bool}|array{mixed, string|null, mixed} $row
52+
*/
53+
protected function test2(array $row): string
54+
{
55+
if (count($row) !== 1) {
56+
assertType('array{mixed, string|null, mixed}', $row);
57+
58+
[$field, $operator, $value] = $row;
59+
assertType('string|null', $operator);
60+
} else {
61+
assertType('array{bool}', $row);
62+
}
63+
64+
if (count($row) === 1) {
65+
assertType('array{bool}', $row);
66+
} else {
67+
assertType('array{mixed, string|null, mixed}', $row);
68+
}
69+
70+
if (count($row) === 2) {
71+
assertType('*NEVER*', $row);
72+
} else {
73+
assertType('array{bool}|array{mixed, string|null, mixed}', $row);
74+
}
75+
76+
if (count($row) !== 2) {
77+
assertType('array{bool}|array{mixed, string|null, mixed}', $row);
78+
} else {
79+
assertType('*NEVER*', $row);
80+
}
81+
82+
if (count($row) === 3) {
83+
assertType('array{mixed, string|null, mixed}', $row);
84+
} else {
85+
assertType('array{bool}', $row);
86+
}
87+
88+
return '';
89+
}
90+
}

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,11 @@ public function testBug14213(): void
362362
]);
363363
}
364364

365+
public function testBug11488(): void
366+
{
367+
$this->analyse([__DIR__ . '/data/bug-11488.php'], []);
368+
}
369+
365370
public function testBug13921(): void
366371
{
367372
$this->analyse([__DIR__ . '/data/bug-13921.php'], [
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Bug11488;
4+
5+
class Foo
6+
{
7+
/**
8+
* @param array{mixed}|array{mixed, string|null, mixed} $row
9+
*/
10+
protected function test(array $row): string
11+
{
12+
if (count($row) !== 1) {
13+
[$field, $operator, $value] = $row;
14+
return $operator ?? '=';
15+
}
16+
17+
return '';
18+
}
19+
}

0 commit comments

Comments
 (0)