@@ -17,29 +17,72 @@ public function shouldAcceptClosureCallbackWithTypehint()
17
17
/** @test */
18
18
public function shouldAcceptFunctionStringCallbackWithTypehint ()
19
19
{
20
- self ::assertTrue (_checkTypehint (new TestCallbackWithTypehintClass (), new InvalidArgumentException ()));
21
- self ::assertFalse (_checkTypehint (new TestCallbackWithTypehintClass (), new Exception ()));
20
+ self ::assertTrue (_checkTypehint (new CallbackWithTypehintClass (), new InvalidArgumentException ()));
21
+ self ::assertFalse (_checkTypehint (new CallbackWithTypehintClass (), new Exception ()));
22
22
}
23
23
24
24
/** @test */
25
25
public function shouldAcceptInvokableObjectCallbackWithTypehint ()
26
26
{
27
- self ::assertTrue (_checkTypehint (new TestCallbackWithTypehintClass (), new InvalidArgumentException ()));
28
- self ::assertFalse (_checkTypehint (new TestCallbackWithTypehintClass (), new Exception ()));
27
+ self ::assertTrue (_checkTypehint (new CallbackWithTypehintClass (), new InvalidArgumentException ()));
28
+ self ::assertFalse (_checkTypehint (new CallbackWithTypehintClass (), new Exception ()));
29
29
}
30
30
31
31
/** @test */
32
32
public function shouldAcceptObjectMethodCallbackWithTypehint ()
33
33
{
34
- self ::assertTrue (_checkTypehint ([new TestCallbackWithTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
35
- self ::assertFalse (_checkTypehint ([new TestCallbackWithTypehintClass (), 'testCallback ' ], new Exception ()));
34
+ self ::assertTrue (_checkTypehint ([new CallbackWithTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
35
+ self ::assertFalse (_checkTypehint ([new CallbackWithTypehintClass (), 'testCallback ' ], new Exception ()));
36
36
}
37
37
38
38
/** @test */
39
39
public function shouldAcceptStaticClassCallbackWithTypehint ()
40
40
{
41
- self ::assertTrue (_checkTypehint ([TestCallbackWithTypehintClass::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
42
- self ::assertFalse (_checkTypehint ([TestCallbackWithTypehintClass::class, 'testCallbackStatic ' ], new Exception ()));
41
+ self ::assertTrue (_checkTypehint ([CallbackWithTypehintClass::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
42
+ self ::assertFalse (_checkTypehint ([CallbackWithTypehintClass::class, 'testCallbackStatic ' ], new Exception ()));
43
+ }
44
+
45
+ /**
46
+ * @test
47
+ * @requires PHP 8
48
+ */
49
+ public function shouldAcceptClosureCallbackWithUnionTypehint ()
50
+ {
51
+ eval (
52
+ 'namespace React\Promise; ' .
53
+ 'self::assertTrue(_checkTypehint(function (\RuntimeException|\InvalidArgumentException $e) {}, new \InvalidArgumentException())); ' .
54
+ 'self::assertFalse(_checkTypehint(function (\RuntimeException|\InvalidArgumentException $e) {}, new \Exception())); '
55
+ );
56
+ }
57
+
58
+ /**
59
+ * @test
60
+ * @requires PHP 8
61
+ */
62
+ public function shouldAcceptInvokableObjectCallbackWithUnionTypehint ()
63
+ {
64
+ self ::assertTrue (_checkTypehint (new CallbackWithUnionTypehintClass (), new InvalidArgumentException ()));
65
+ self ::assertFalse (_checkTypehint (new CallbackWithUnionTypehintClass (), new Exception ()));
66
+ }
67
+
68
+ /**
69
+ * @test
70
+ * @requires PHP 8
71
+ */
72
+ public function shouldAcceptObjectMethodCallbackWithUnionTypehint ()
73
+ {
74
+ self ::assertTrue (_checkTypehint ([new CallbackWithUnionTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
75
+ self ::assertFalse (_checkTypehint ([new CallbackWithUnionTypehintClass (), 'testCallback ' ], new Exception ()));
76
+ }
77
+
78
+ /**
79
+ * @test
80
+ * @requires PHP 8
81
+ */
82
+ public function shouldAcceptStaticClassCallbackWithUnionTypehint ()
83
+ {
84
+ self ::assertTrue (_checkTypehint ([CallbackWithUnionTypehintClass::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
85
+ self ::assertFalse (_checkTypehint ([CallbackWithUnionTypehintClass::class, 'testCallbackStatic ' ], new Exception ()));
43
86
}
44
87
45
88
/** @test */
@@ -52,25 +95,25 @@ public function shouldAcceptClosureCallbackWithoutTypehint()
52
95
/** @test */
53
96
public function shouldAcceptFunctionStringCallbackWithoutTypehint ()
54
97
{
55
- self ::assertTrue (_checkTypehint (new TestCallbackWithTypehintClass (), new InvalidArgumentException ()));
98
+ self ::assertTrue (_checkTypehint (new CallbackWithoutTypehintClass (), new InvalidArgumentException ()));
56
99
}
57
100
58
101
/** @test */
59
102
public function shouldAcceptInvokableObjectCallbackWithoutTypehint ()
60
103
{
61
- self ::assertTrue (_checkTypehint (new TestCallbackWithoutTypehintClass (), new InvalidArgumentException ()));
104
+ self ::assertTrue (_checkTypehint (new CallbackWithoutTypehintClass (), new InvalidArgumentException ()));
62
105
}
63
106
64
107
/** @test */
65
108
public function shouldAcceptObjectMethodCallbackWithoutTypehint ()
66
109
{
67
- self ::assertTrue (_checkTypehint ([new TestCallbackWithoutTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
110
+ self ::assertTrue (_checkTypehint ([new CallbackWithoutTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
68
111
}
69
112
70
113
/** @test */
71
114
public function shouldAcceptStaticClassCallbackWithoutTypehint ()
72
115
{
73
- self ::assertTrue (_checkTypehint ([TestCallbackWithoutTypehintClass ::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
116
+ self ::assertTrue (_checkTypehint ([CallbackWithoutTypehintClass ::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
74
117
}
75
118
}
76
119
@@ -81,33 +124,3 @@ function testCallbackWithTypehint(InvalidArgumentException $e)
81
124
function testCallbackWithoutTypehint ()
82
125
{
83
126
}
84
-
85
- class TestCallbackWithTypehintClass
86
- {
87
- public function __invoke (InvalidArgumentException $ e )
88
- {
89
- }
90
-
91
- public function testCallback (InvalidArgumentException $ e )
92
- {
93
- }
94
-
95
- public static function testCallbackStatic (InvalidArgumentException $ e )
96
- {
97
- }
98
- }
99
-
100
- class TestCallbackWithoutTypehintClass
101
- {
102
- public function __invoke ()
103
- {
104
- }
105
-
106
- public function testCallback ()
107
- {
108
- }
109
-
110
- public static function testCallbackStatic ()
111
- {
112
- }
113
- }
0 commit comments