Repository navigation
Expand file tree
/
Copy pathMissingCheckedExceptionInFunctionThrowsRuleTest.php
More file actions
97 lines (89 loc) · 3.06 KB
/
Copy pathMissingCheckedExceptionInFunctionThrowsRuleTest.php
File metadata and controls
97 lines (89 loc) · 3.06 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
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Exceptions;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\RuleTestCase;
/**
* @extends RuleTestCase<MissingCheckedExceptionInFunctionThrowsRule>
*/
class MissingCheckedExceptionInFunctionThrowsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new MissingCheckedExceptionInFunctionThrowsRule(
new MissingCheckedExceptionInThrowsCheck(new DefaultExceptionTypeResolver(
self::createReflectionProvider(),
[],
[ShouldNotHappenException::class],
[],
[],
)),
);
}
public function testRule(): void
{
require_once __DIR__ . '/data/missing-exception-function-throws.php';
$this->analyse([__DIR__ . '/data/missing-exception-function-throws.php'], [
[
'Function MissingExceptionFunctionThrows\doBaz() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
20,
],
[
'Function MissingExceptionFunctionThrows\doLorem() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
26,
],
[
'Function MissingExceptionFunctionThrows\doLorem2() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
31,
],
[
'Function MissingExceptionFunctionThrows\doBar2() throws checked exception LogicException but it\'s missing from the PHPDoc @throws tag.',
51,
],
[
'Function MissingExceptionFunctionThrows\doBar3() throws checked exception LogicException but it\'s missing from the PHPDoc @throws tag.',
57,
],
]);
}
public function testConditionalThrows(): void
{
require_once __DIR__ . '/data/conditional-throws-function.php';
$this->analyse([__DIR__ . '/data/conditional-throws-function.php'], [
[
'Function ConditionalThrowsFunction\callsZero() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
23,
],
[
'Function ConditionalThrowsFunction\callsUnknown() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
35,
],
[
'Function ConditionalThrowsFunction\lookupString() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
68,
],
[
'Function ConditionalThrowsFunction\lookupUnknown() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
77,
],
[
'Function ConditionalThrowsFunction\nestedCallsOuterZero() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
97,
],
[
'Function ConditionalThrowsFunction\nestedCallsInnerZero() throws checked exception Exception but it\'s missing from the PHPDoc @throws tag.',
103,
],
]);
}
public function testBug15392(): void
{
require_once __DIR__ . '/data/bug-15392.php';
$this->analyse([__DIR__ . '/data/bug-15392.php'], [
[
'Function Bug15392\\multiCatchLeaksOtherSubtype() throws checked exception Bug15392\\SubB but it\'s missing from the PHPDoc @throws tag.',
84,
],
]);
}
}