-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathFunctionCheckTypehintTest.php
More file actions
189 lines (165 loc) · 7.18 KB
/
FunctionCheckTypehintTest.php
File metadata and controls
189 lines (165 loc) · 7.18 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace React\Promise;
use Exception;
use InvalidArgumentException;
class FunctionCheckTypehintTest extends TestCase
{
/** @test */
public function shouldAcceptClosureCallbackWithTypehint(): void
{
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {}, new InvalidArgumentException()));
self::assertFalse(_checkTypehint(function (InvalidArgumentException $e) {}, new Exception()));
}
/** @test */
public function shouldAcceptFunctionStringCallbackWithTypehint(): void
{
self::assertTrue(_checkTypehint(new CallbackWithTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new CallbackWithTypehintClass(), new Exception()));
}
/** @test */
public function shouldAcceptInvokableObjectCallbackWithTypehint(): void
{
self::assertTrue(_checkTypehint(new CallbackWithTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new CallbackWithTypehintClass(), new Exception()));
}
/** @test */
public function shouldAcceptObjectMethodCallbackWithTypehint(): void
{
self::assertTrue(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([new CallbackWithTypehintClass(), 'testCallback'], new Exception()));
}
/** @test */
public function shouldAcceptStaticClassCallbackWithTypehint(): void
{
self::assertTrue(_checkTypehint([CallbackWithTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([CallbackWithTypehintClass::class, 'testCallbackStatic'], new Exception()));
}
/**
* @test
* @requires PHP 8
*/
public function shouldAcceptClosureCallbackWithUnionTypehint(): void
{
eval(
'namespace React\Promise;' .
'self::assertTrue(_checkTypehint(function (\RuntimeException|\InvalidArgumentException $e) {}, new \InvalidArgumentException()));' .
'self::assertFalse(_checkTypehint(function (\RuntimeException|\InvalidArgumentException $e) {}, new \Exception()));'
);
}
/**
* @test
* @requires PHP 8
*/
public function shouldAcceptInvokableObjectCallbackWithUnionTypehint(): void
{
self::assertTrue(_checkTypehint(new CallbackWithUnionTypehintClass(), new InvalidArgumentException()));
self::assertFalse(_checkTypehint(new CallbackWithUnionTypehintClass(), new Exception()));
}
/**
* @test
* @requires PHP 8
*/
public function shouldAcceptObjectMethodCallbackWithUnionTypehint(): void
{
self::assertTrue(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([new CallbackWithUnionTypehintClass(), 'testCallback'], new Exception()));
}
/**
* @test
* @requires PHP 8
*/
public function shouldAcceptStaticClassCallbackWithUnionTypehint(): void
{
self::assertTrue(_checkTypehint([CallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
self::assertFalse(_checkTypehint([CallbackWithUnionTypehintClass::class, 'testCallbackStatic'], new Exception()));
}
/**
* @test
* @requires PHP 8.1
*/
public function shouldAcceptInvokableObjectCallbackWithIntersectionTypehint(): void
{
self::assertFalse(_checkTypehint(new CallbackWithIntersectionTypehintClass(), new \RuntimeException()));
self::assertTrue(_checkTypehint(new CallbackWithIntersectionTypehintClass(), new CountableException()));
}
/**
* @test
* @requires PHP 8.1
*/
public function shouldAcceptObjectMethodCallbackWithIntersectionTypehint(): void
{
self::assertFalse(_checkTypehint([new CallbackWithIntersectionTypehintClass(), 'testCallback'], new \RuntimeException()));
self::assertTrue(_checkTypehint([new CallbackWithIntersectionTypehintClass(), 'testCallback'], new CountableException()));
}
/**
* @test
* @requires PHP 8.1
*/
public function shouldAcceptStaticClassCallbackWithIntersectionTypehint(): void
{
self::assertFalse(_checkTypehint([CallbackWithIntersectionTypehintClass::class, 'testCallbackStatic'], new \RuntimeException()));
self::assertTrue(_checkTypehint([CallbackWithIntersectionTypehintClass::class, 'testCallbackStatic'], new CountableException()));
}
/**
* @test
* @requires PHP 8.2
*/
public function shouldAcceptInvokableObjectCallbackWithDNFTypehint(): void
{
self::assertFalse(_checkTypehint(new CallbackWithDNFTypehintClass(), new \RuntimeException()));
self::assertTrue(_checkTypehint(new CallbackWithDNFTypehintClass(), new IterableException()));
self::assertTrue(_checkTypehint(new CallbackWithDNFTypehintClass(), new CountableException()));
}
/**
* @test
* @requires PHP 8.2
*/
public function shouldAcceptObjectMethodCallbackWithDNFTypehint(): void
{
self::assertFalse(_checkTypehint([new CallbackWithDNFTypehintClass(), 'testCallback'], new \RuntimeException()));
self::assertTrue(_checkTypehint([new CallbackWithDNFTypehintClass(), 'testCallback'], new CountableException()));
self::assertTrue(_checkTypehint([new CallbackWithDNFTypehintClass(), 'testCallback'], new IterableException()));
}
/**
* @test
* @requires PHP 8.2
*/
public function shouldAcceptStaticClassCallbackWithDNFTypehint(): void
{
self::assertFalse(_checkTypehint([CallbackWithDNFTypehintClass::class, 'testCallbackStatic'], new \RuntimeException()));
self::assertTrue(_checkTypehint([CallbackWithDNFTypehintClass::class, 'testCallbackStatic'], new CountableException()));
self::assertTrue(_checkTypehint([CallbackWithDNFTypehintClass::class, 'testCallbackStatic'], new IterableException()));
}
/** @test */
public function shouldAcceptClosureCallbackWithoutTypehint(): void
{
self::assertTrue(_checkTypehint(function (InvalidArgumentException $e) {
}, new InvalidArgumentException()));
}
/** @test */
public function shouldAcceptFunctionStringCallbackWithoutTypehint(): void
{
self::assertTrue(_checkTypehint(new CallbackWithoutTypehintClass(), new InvalidArgumentException()));
}
/** @test */
public function shouldAcceptInvokableObjectCallbackWithoutTypehint(): void
{
self::assertTrue(_checkTypehint(new CallbackWithoutTypehintClass(), new InvalidArgumentException()));
}
/** @test */
public function shouldAcceptObjectMethodCallbackWithoutTypehint(): void
{
self::assertTrue(_checkTypehint([new CallbackWithoutTypehintClass(), 'testCallback'], new InvalidArgumentException()));
}
/** @test */
public function shouldAcceptStaticClassCallbackWithoutTypehint(): void
{
self::assertTrue(_checkTypehint([CallbackWithoutTypehintClass::class, 'testCallbackStatic'], new InvalidArgumentException()));
}
}
function testCallbackWithTypehint(InvalidArgumentException $e): void
{
}
function testCallbackWithoutTypehint(): void
{
}