Skip to content

Commit 53e193b

Browse files
committed
ReadingWriteOnlyPropertiesRuleTest - test with nullsafe
1 parent c3bb2c4 commit 53e193b

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,19 @@ public function testReadingWriteOnlyPropertiesCheckThisOnly(): void
7070
]);
7171
}
7272

73+
public function testNullsafe(): void
74+
{
75+
if (PHP_VERSION_ID < 80000 && !self::$useStaticReflectionProvider) {
76+
$this->markTestSkipped('Test requires PHP 8.0.');
77+
}
78+
79+
$this->checkThisOnly = false;
80+
$this->analyse([__DIR__ . '/data/reading-write-only-properties-nullsafe.php'], [
81+
[
82+
'Property ReadingWriteOnlyProperties\Foo::$writeOnlyProperty is not readable.',
83+
9,
84+
],
85+
]);
86+
}
87+
7388
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php // lint >= 8.0
2+
3+
namespace ReadingWriteOnlyProperties;
4+
5+
function (?Foo $foo): void
6+
{
7+
echo $foo?->readOnlyProperty;
8+
echo $foo?->usualProperty;
9+
echo $foo?->writeOnlyProperty;
10+
};

0 commit comments

Comments
 (0)