forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReturnTypeRuleTest.php
119 lines (106 loc) · 3.02 KB
/
ReturnTypeRuleTest.php
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
115
116
117
118
119
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Functions;
use PHPStan\Rules\FunctionReturnTypeCheck;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleLevelHelper;
use PHPStan\Testing\RuleTestCase;
/**
* @extends RuleTestCase<ReturnTypeRule>
*/
class ReturnTypeRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
return new ReturnTypeRule(new FunctionReturnTypeCheck(new RuleLevelHelper($this->createReflectionProvider(), true, false, true, false)));
}
public function testReturnTypeRule(): void
{
require_once __DIR__ . '/data/returnTypes.php';
$this->analyse([__DIR__ . '/data/returnTypes.php'], [
[
'Function ReturnTypes\returnInteger() should return int but returns string.',
17,
],
[
'Function ReturnTypes\returnObject() should return ReturnTypes\Bar but returns int.',
27,
],
[
'Function ReturnTypes\returnObject() should return ReturnTypes\Bar but returns ReturnTypes\Foo.',
31,
],
[
'Function ReturnTypes\returnChild() should return ReturnTypes\Foo but returns ReturnTypes\OtherInterfaceImpl.',
50,
],
[
'Function ReturnTypes\returnVoid() with return type void returns null but should not return anything.',
83,
],
[
'Function ReturnTypes\returnVoid() with return type void returns int but should not return anything.',
87,
],
[
'Function ReturnTypes\returnFromGeneratorString() should return string but empty return statement found.',
152,
],
[
'Function ReturnTypes\returnFromGeneratorString() should return string but returns int.',
155,
],
[
'Function ReturnTypes\returnVoidFromGenerator2() with return type void returns int but should not return anything.',
173,
],
[
'Function ReturnTypes\returnNever() should never return but return statement found.',
181,
],
]);
}
public function testReturnTypeRulePhp70(): void
{
$this->analyse([__DIR__ . '/data/returnTypes-7.0.php'], [
[
'Function ReturnTypes\Php70\returnInteger() should return int but empty return statement found.',
7,
],
]);
}
public function testIsGenerator(): void
{
if (!self::$useStaticReflectionProvider) {
$this->markTestSkipped('Test requires static reflection.');
}
$this->analyse([__DIR__ . '/data/is-generator.php'], []);
}
public function testBug2568(): void
{
require_once __DIR__ . '/data/bug-2568.php';
$this->analyse([__DIR__ . '/data/bug-2568.php'], [
[
'Function Bug2568\my_array_keys() should return array<int, T> but returns array<int, (int&T)|(string&T)>.',
12,
],
]);
}
public function testBug2723(): void
{
require_once __DIR__ . '/data/bug-2723.php';
$this->analyse([__DIR__ . '/data/bug-2723.php'], [
[
'Function Bug2723\baz() should return Bug2723\Bar<Bug2723\Foo<T4>> but returns Bug2723\BarOfFoo<string>.',
55,
],
]);
}
public function testBug5706(): void
{
$this->analyse([__DIR__ . '/data/bug-5706.php'], []);
}
public function testBug5844(): void
{
$this->analyse([__DIR__ . '/data/bug-5844.php'], []);
}
}