@@ -42,6 +42,49 @@ public function shouldAcceptStaticClassCallbackWithTypehint()
4242 self ::assertFalse (_checkTypehint ([TestCallbackWithTypehintClass::class, 'testCallbackStatic ' ], new Exception ()));
4343 }
4444
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 TestCallbackWithUnionTypehintClass (), new InvalidArgumentException ()));
65+ self ::assertFalse (_checkTypehint (new TestCallbackWithUnionTypehintClass (), new Exception ()));
66+ }
67+
68+ /**
69+ * @test
70+ * @requires PHP 8
71+ */
72+ public function shouldAcceptObjectMethodCallbackWithUnionTypehint ()
73+ {
74+ self ::assertTrue (_checkTypehint ([new TestCallbackWithUnionTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
75+ self ::assertFalse (_checkTypehint ([new TestCallbackWithUnionTypehintClass (), 'testCallback ' ], new Exception ()));
76+ }
77+
78+ /**
79+ * @test
80+ * @requires PHP 8
81+ */
82+ public function shouldAcceptStaticClassCallbackWithUnionTypehint ()
83+ {
84+ self ::assertTrue (_checkTypehint ([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
85+ self ::assertFalse (_checkTypehint ([TestCallbackWithUnionTypehintClass::class, 'testCallbackStatic ' ], new Exception ()));
86+ }
87+
4588 /** @test */
4689 public function shouldAcceptClosureCallbackWithoutTypehint ()
4790 {
@@ -52,7 +95,7 @@ public function shouldAcceptClosureCallbackWithoutTypehint()
5295 /** @test */
5396 public function shouldAcceptFunctionStringCallbackWithoutTypehint ()
5497 {
55- self ::assertTrue (_checkTypehint (new TestCallbackWithTypehintClass (), new InvalidArgumentException ()));
98+ self ::assertTrue (_checkTypehint (new TestCallbackWithoutTypehintClass (), new InvalidArgumentException ()));
5699 }
57100
58101 /** @test */
@@ -97,6 +140,27 @@ public static function testCallbackStatic(InvalidArgumentException $e)
97140 }
98141}
99142
143+ if (defined ('PHP_MAJOR_VERSION ' ) && (PHP_MAJOR_VERSION >= 8 )) {
144+ eval (<<<EOT
145+ namespace React\Promise;
146+ class TestCallbackWithUnionTypehintClass
147+ {
148+ public function __invoke(\RuntimeException|\InvalidArgumentException \$e)
149+ {
150+ }
151+
152+ public function testCallback(\RuntimeException|\InvalidArgumentException \$e)
153+ {
154+ }
155+
156+ public static function testCallbackStatic(\RuntimeException|\InvalidArgumentException \$e)
157+ {
158+ }
159+ }
160+ EOT
161+ );
162+ }
163+
100164class TestCallbackWithoutTypehintClass
101165{
102166 public function __invoke ()
0 commit comments