forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbilityToDisableImplicitThrowsTest.php
More file actions
98 lines (89 loc) · 2.42 KB
/
AbilityToDisableImplicitThrowsTest.php
File metadata and controls
98 lines (89 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Exceptions;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\RequiresPhp;
use function array_merge;
/**
* @extends RuleTestCase<CatchWithUnthrownExceptionRule>
*/
class AbilityToDisableImplicitThrowsTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new CatchWithUnthrownExceptionRule(new DefaultExceptionTypeResolver(
self::createReflectionProvider(),
[],
[],
[],
[],
), true);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/ability-to-disable-implicit-throws.php'], [
[
'Dead catch - Throwable is never thrown in the try block.',
17,
],
]);
}
#[RequiresPhp('>= 8.4')]
public function testPropertyHooks(): void
{
$this->analyse([__DIR__ . '/data/unthrown-exception-property-hooks-implicit-throws-disabled.php'], [
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
23,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
38,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
53,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
68,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
74,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
94,
],
[
'Dead catch - UnthrownExceptionPropertyHooksImplicitThrowsDisabled\MyCustomException is never thrown in the try block.',
115,
],
]);
}
public function testBug13806(): void
{
$this->analyse([__DIR__ . '/data/bug-13806.php'], [
[
'Dead catch - Throwable is never thrown in the try block.',
8,
],
[
'Dead catch - Throwable is never thrown in the try block.',
53,
],
[
'Dead catch - Throwable is never thrown in the try block.',
64,
],
]);
}
public static function getAdditionalConfigFiles(): array
{
return array_merge(
parent::getAdditionalConfigFiles(),
[__DIR__ . '/data/ability-to-disable-implicit-throws.neon'],
);
}
}