Skip to content

Commit ec298e0

Browse files
committed
test properties per php version
1 parent 1df7113 commit ec298e0

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function testBug11667(): void
6161
$this->analyse([__DIR__ . '/data/bug-11667.php'], []);
6262
}
6363

64+
#[RequiresPhp('>= 8.2')]
6465
public function testBug13384(): void
6566
{
6667
$this->reportTooWideBool = true;
@@ -76,6 +77,24 @@ public function testBug13384(): void
7677
]);
7778
}
7879

80+
#[RequiresPhp('< 8.2')]
81+
public function testBug13384PrePhp82(): void
82+
{
83+
$this->reportTooWideBool = true;
84+
$this->analyse([__DIR__ . '/data/bug-13384.php'], []);
85+
}
86+
87+
public function testBug13384Phpdoc(): void
88+
{
89+
$this->reportTooWideBool = true;
90+
$this->analyse([__DIR__ . '/data/bug-13384-phpdoc.php'], [
91+
[
92+
'Static property Bug13384Phpdoc\ShutdownHandlerPhpdocTypes::$registered (bool) is never assigned true so it can be removed from the property type.',
93+
12,
94+
],
95+
]);
96+
}
97+
7998
public function testBug13384b(): void
8099
{
81100
$this->reportTooWideBool = true;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug13384Phpdoc;
4+
5+
use function register_shutdown_function;
6+
7+
final class ShutdownHandlerPhpdocTypes
8+
{
9+
/**
10+
* @var bool
11+
*/
12+
private static $registered = false;
13+
private static string $message = '';
14+
15+
public static function setMessage(string $message): void
16+
{
17+
self::register();
18+
19+
self::$message = $message;
20+
}
21+
22+
private static function register(): void
23+
{
24+
if (self::$registered) {
25+
return;
26+
}
27+
28+
register_shutdown_function(static function (): void
29+
{
30+
print self::$message;
31+
});
32+
}
33+
}

0 commit comments

Comments
 (0)