-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathMissingCheckedExceptionInMethodThrowsRuleTest.php
More file actions
113 lines (105 loc) · 3.62 KB
/
MissingCheckedExceptionInMethodThrowsRuleTest.php
File metadata and controls
113 lines (105 loc) · 3.62 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Exceptions;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
use PHPStan\Testing\RuleTestCase;
use function sprintf;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<MissingCheckedExceptionInMethodThrowsRule>
*/
class MissingCheckedExceptionInMethodThrowsRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new MissingCheckedExceptionInMethodThrowsRule(
new MissingCheckedExceptionInThrowsCheck(new DefaultExceptionTypeResolver(
self::createReflectionProvider(),
[],
[ShouldNotHappenException::class],
[],
[],
)),
);
}
public function testRule(): void
{
$errors = [
[
'Method MissingExceptionMethodThrows\Foo::doBaz() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
23,
],
[
'Method MissingExceptionMethodThrows\Foo::doLorem() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
29,
],
[
'Method MissingExceptionMethodThrows\Foo::doLorem2() throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
34,
],
[
sprintf(
'Method MissingExceptionMethodThrows\Foo::dateTimeZoneDoesThrows() throws checked exception %s but it\'s missing from the PHPDoc @throws tag.',
PHP_VERSION_ID >= 80300 ? 'DateInvalidTimeZoneException' : 'Exception',
),
95,
],
[
sprintf(
'Method MissingExceptionMethodThrows\Foo::dateIntervalDoesThrows() throws checked exception %s but it\'s missing from the PHPDoc @throws tag.',
PHP_VERSION_ID >= 80300 ? 'DateMalformedIntervalStringException' : 'Exception',
),
105,
],
];
if (PHP_VERSION_ID >= 80300) {
$errors[] = [
'Method MissingExceptionMethodThrows\Foo::dateTimeModifyDoesThrows() throws checked exception DateMalformedStringException but it\'s missing from the PHPDoc @throws tag.',
121,
];
$errors[] = [
'Method MissingExceptionMethodThrows\Foo::dateTimeModifyDoesThrows() throws checked exception DateMalformedStringException but it\'s missing from the PHPDoc @throws tag.',
122,
];
}
$this->analyse([__DIR__ . '/data/missing-exception-method-throws.php'], $errors);
}
public function testBugArrayOffset(): void
{
$this->analyse([__DIR__ . '/data/bug-array-offset.php'], [
[
"Method BugArrayOffset\Foo::__construct() throws checked exception BugArrayOffset\ParameterNotFoundException but it's missing from the PHPDoc @throws tag.",
19,
],
[
"Method BugArrayOffset\Foo2::__construct() throws checked exception BugArrayOffset\ParameterNotFoundException but it's missing from the PHPDoc @throws tag.",
27,
],
[
"Method BugArrayOffset\Foo3::__construct() throws checked exception BugArrayOffset\ParameterNotFoundException but it's missing from the PHPDoc @throws tag.",
35,
],
[
"Method BugArrayOffset\Foo4::__construct() throws checked exception BugArrayOffset\ParameterNotFoundException but it's missing from the PHPDoc @throws tag.",
43,
],
]);
}
public function testBug13792(): void
{
$this->analyse([__DIR__ . '/data/bug-13792.php'], [
[
'Method Bug13792\Foo::dynamicName() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
20,
],
[
'Method Bug13792\Foo::invalidConstantName() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
25,
],
[
'Method Bug13792\Foo::unions() throws checked exception DOMException but it\'s missing from the PHPDoc @throws tag.',
35,
],
]);
}
}