Skip to content

Commit bc044b7

Browse files
committed
Test MatchExpressionRule with property hooks
1 parent 7f9538c commit bc044b7

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/PHPStan/Rules/Comparison/MatchExpressionRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,18 @@ public function testBug11852(): void
503503
$this->analyse([__DIR__ . '/data/bug-11852.php'], []);
504504
}
505505

506+
public function testPropertyHooks(): void
507+
{
508+
if (PHP_VERSION_ID < 80400) {
509+
$this->markTestSkipped('Test requires PHP 8.4.');
510+
}
511+
512+
$this->analyse([__DIR__ . '/data/match-expr-property-hooks.php'], [
513+
[
514+
'Match expression does not handle remaining value: 3',
515+
13,
516+
],
517+
]);
518+
}
519+
506520
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php // lint >= 8.4
2+
3+
namespace MatchExprPropertyHooks;
4+
5+
use UnhandledMatchError;
6+
7+
class Foo
8+
{
9+
10+
/** @var 1|2|3 */
11+
public int $i {
12+
get {
13+
return match ($this->i) {
14+
1 => 'foo',
15+
2 => 'bar',
16+
};
17+
}
18+
}
19+
20+
/**
21+
* @var 1|2|3
22+
*/
23+
public int $j {
24+
/** @throws UnhandledMatchError */
25+
get {
26+
return match ($this->j) {
27+
1 => 10,
28+
2 => 20,
29+
};
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)