Skip to content

Commit da28384

Browse files
VincentLangletphpstan-bot
authored andcommitted
Add non regression tests (phpstan#5110)
1 parent 183ccc2 commit da28384

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

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

670+
#[RequiresPhp('>= 8.3')]
671+
public function testPr5105(): void
672+
{
673+
$this->analyse([__DIR__ . '/data/pr-5105.php'], [
674+
[
675+
'Dead catch - RuntimeException is never thrown in the try block.',
676+
15,
677+
],
678+
[
679+
'Dead catch - Error is never thrown in the try block.',
680+
28,
681+
],
682+
]);
683+
}
684+
670685
public function testBug9146NonStrict(): void
671686
{
672687
$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.3
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)