Skip to content

Commit c3bb2c4

Browse files
committed
NullCoalesceRule - test that nothing is reported on nullsafe operator
1 parent a72aea6 commit c3bb2c4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@ public function testCoalesceAssignRule(): void
145145
]);
146146
}
147147

148+
public function testNullsafe(): void
149+
{
150+
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
151+
$this->markTestSkipped('Test requires PHP 8.0.');
152+
}
153+
154+
$this->analyse([__DIR__ . '/data/null-coalesce-nullsafe.php'], []);
155+
}
156+
148157
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php // lint >= 8.0
2+
3+
namespace NullCoalesceNullsafe;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(
9+
$mixed,
10+
\Exception $nonNullable,
11+
?\Exception $nullable
12+
)
13+
{
14+
$mixed?->foo;
15+
$nonNullable?->foo;
16+
$nullable?->foo;
17+
}
18+
19+
}

0 commit comments

Comments
 (0)