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