Skip to content

Commit

Permalink
Regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 8, 2022
1 parent 652a17f commit f6c6c5e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php
Expand Up @@ -230,4 +230,26 @@ public function testBug5935(): void
$this->analyse([__DIR__ . '/data/bug-5935.php'], []);
}

public function testBug5337(): void
{
if (PHP_VERSION_ID < 70400 && !self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires PHP 7.4.');
}

$this->alwaysWrittenTags = [];
$this->alwaysReadTags = [];
$this->analyse([__DIR__ . '/data/bug-5337.php'], [
[
'Property Bug5337\Clazz::$prefix is never read, only written.',
7,
'See: https://phpstan.org/developing-extensions/always-read-written-properties',
],
[
'Property Bug5337\Foo::$field is unused.',
20,
'See: https://phpstan.org/developing-extensions/always-read-written-properties',
],
]);
}

}
27 changes: 27 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-5337.php
@@ -0,0 +1,27 @@
<?php // lint >= 7.4

namespace Bug5337;

class Clazz
{
private ?string $prefix;

public function setter(string $prefix): void
{
if (!empty($this->prefix)) {
$this->prefix = $prefix;
}
}
}

class Foo
{

private string $field;

public function __construct()
{
if (isset($this->field)) {}
}

}

0 comments on commit f6c6c5e

Please sign in to comment.