Skip to content

Commit 981f732

Browse files
committed
regression tests
1 parent 59ccfb9 commit 981f732

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Bug10482;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
class Test
8+
{
9+
public ?int $id;
10+
}
11+
12+
$test = new Test();
13+
if (rand(0, 1)) {
14+
$test = null;
15+
}
16+
17+
$testId = $test?->id;
18+
if (null !== $testId) {
19+
assertType('Bug10482\Test', $test);
20+
}
21+
22+
if ($testId) {
23+
assertType('Bug10482\Test', $test);
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Bug13709;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doFOo(string $shortName): void
8+
{
9+
$pos = strpos($shortName, '\\');
10+
if ($pos === false) {
11+
return;
12+
}
13+
14+
assertType('non-falsy-string', $shortName);
15+
}
16+
17+

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3891,4 +3891,13 @@ public function testBug9820(): void
38913891
]);
38923892
}
38933893

3894+
#[RequiresPhp('>= 8.1')]
3895+
public function testBug6120(): void
3896+
{
3897+
$this->checkThisOnly = false;
3898+
$this->checkNullables = true;
3899+
$this->checkUnionTypes = true;
3900+
$this->analyse([__DIR__ . '/data/bug-6120.php'], []);
3901+
}
3902+
38943903
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php // lint >= 8.0
2+
3+
declare(strict_types=1);
4+
5+
namespace Bug6120;
6+
7+
class Clazz
8+
{
9+
10+
public int $foo = 0;
11+
12+
public function bar(?Clazz $clazz): void
13+
{
14+
$result = $clazz?->foo;
15+
if ($result !== null) {
16+
$clazz->bar(null);
17+
}
18+
}
19+
20+
}

0 commit comments

Comments
 (0)