Repository navigation
Expand file tree
/
Copy pathThrowsVoidFunctionWithExplicitThrowPointRuleTest.php
More file actions
114 lines (103 loc) · 2.56 KB
/
Copy pathThrowsVoidFunctionWithExplicitThrowPointRuleTest.php
File metadata and controls
114 lines (103 loc) · 2.56 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
114
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Exceptions;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use ThrowsVoidFunction\MyException;
/**
* @extends RuleTestCase<ThrowsVoidFunctionWithExplicitThrowPointRule>
*/
class ThrowsVoidFunctionWithExplicitThrowPointRuleTest extends RuleTestCase
{
private bool $missingCheckedExceptionInThrows;
/** @var string[] */
private array $checkedExceptionClasses;
protected function getRule(): Rule
{
return new ThrowsVoidFunctionWithExplicitThrowPointRule(new DefaultExceptionTypeResolver(
self::createReflectionProvider(),
[],
[],
[],
$this->checkedExceptionClasses,
), $this->missingCheckedExceptionInThrows);
}
public static function dataRule(): array
{
return [
[
true,
[],
[],
],
[
false,
['DifferentException'],
[
[
'Function ThrowsVoidFunction\foo() throws exception ThrowsVoidFunction\MyException but the PHPDoc contains @throws void.',
15,
],
],
],
[
true,
[MyException::class],
[],
],
[
true,
['DifferentException'],
[
[
'Function ThrowsVoidFunction\foo() throws exception ThrowsVoidFunction\MyException but the PHPDoc contains @throws void.',
15,
],
],
],
[
false,
[],
[
[
'Function ThrowsVoidFunction\foo() throws exception ThrowsVoidFunction\MyException but the PHPDoc contains @throws void.',
15,
],
],
],
[
false,
[MyException::class],
[
[
'Function ThrowsVoidFunction\foo() throws exception ThrowsVoidFunction\MyException but the PHPDoc contains @throws void.',
15,
],
],
],
];
}
/**
* @param string[] $checkedExceptionClasses
* @param list<array{0: string, 1: int, 2?: string}> $errors
*/
#[DataProvider('dataRule')]
public function testRule(bool $missingCheckedExceptionInThrows, array $checkedExceptionClasses, array $errors): void
{
$this->missingCheckedExceptionInThrows = $missingCheckedExceptionInThrows;
$this->checkedExceptionClasses = $checkedExceptionClasses;
$this->analyse([__DIR__ . '/data/throws-void-function.php'], $errors);
}
public function testBug13515(): void
{
$this->missingCheckedExceptionInThrows = false;
$this->checkedExceptionClasses = [];
$this->analyse([__DIR__ . '/data/bug-13515.php'], []);
}
public function testBug15392(): void
{
$this->missingCheckedExceptionInThrows = false;
$this->checkedExceptionClasses = [];
$this->analyse([__DIR__ . '/data/bug-15392.php'], []);
}
}