Skip to content

Commit 1c73212

Browse files
Add non regression tests
1 parent 1bbe9dc commit 1c73212

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,20 @@ public function testBug9146(): void
667667
]);
668668
}
669669

670+
public function testPr5105(): void
671+
{
672+
$this->analyse([__DIR__ . '/data/pr-5105.php'], [
673+
[
674+
'Dead catch - RuntimeException is never thrown in the try block.',
675+
15,
676+
],
677+
[
678+
'Dead catch - Error is never thrown in the try block.',
679+
28,
680+
],
681+
]);
682+
}
683+
670684
public function testBug9146NonStrict(): void
671685
{
672686
$this->analyse([__DIR__ . '/data/bug-9146-non-strict.php'], [
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php // lint >= 8.1
2+
3+
declare(strict_types = 1);
4+
5+
namespace Pr5105;
6+
7+
enum ReactionType: string
8+
{
9+
case EMOJI_HEART = '❤️';
10+
11+
public static function tryFromName1(string $name): ?self
12+
{
13+
try {
14+
return ReactionType::{$name};
15+
} catch (\RuntimeException) {
16+
return null;
17+
}
18+
}
19+
20+
public static function tryFromName2(string $name): ?self
21+
{
22+
if ($name !== 'EMOJI_HEART') {
23+
return null;
24+
}
25+
26+
try {
27+
return ReactionType::{$name};
28+
} catch (\Error) {
29+
return null;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)