Skip to content

Commit

Permalink
add regression test for phpstan/phpstan#5971 and phpstan/phpstan#6107
Browse files Browse the repository at this point in the history
  • Loading branch information
rajyan committed Apr 5, 2022
1 parent d3c7085 commit db78bf5
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php
Expand Up @@ -241,4 +241,26 @@ public function testBug5337(): void
$this->analyse([__DIR__ . '/data/bug-5337.php'], []);
}

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

$this->alwaysWrittenTags = [];
$this->alwaysReadTags = [];
$this->analyse([__DIR__ . '/data/bug-5971.php'], []);
}

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

$this->alwaysWrittenTags = [];
$this->alwaysReadTags = [];
$this->analyse([__DIR__ . '/data/bug-6107.php'], []);
}

}
33 changes: 33 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-5971.php
@@ -0,0 +1,33 @@
<?php declare(strict_types = 1); // lint >= 7.4

namespace Bug5971;

class TestEmpty
{
private ?array $test;

public function write(): void
{
$this->test = [];
}

public function read(): bool
{
return empty($this->test);
}
}

class TestIsset
{
private ?string $test;

public function write(string $string): void
{
$this->test = $string;
}

public function read(): bool
{
return isset($this->test);
}
}
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-6107.php
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1); // lint >= 7.4

namespace Bug6107;

class Test
{
private ?\stdClass $item;

public function __construct(?\stdClass $item)
{
$this->item = $item;
}

public function handle(): void
{
$value = $this->item->value ?? 'custom value';
}
}

0 comments on commit db78bf5

Please sign in to comment.