@@ -17,32 +17,75 @@ public function shouldAcceptClosureCallbackWithTypehint()
1717 /** @test */
1818 public function shouldAcceptFunctionStringCallbackWithTypehint ()
1919 {
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 ()));
2222 }
2323
2424 /** @test */
2525 public function shouldAcceptInvokableObjectCallbackWithTypehint ()
2626 {
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 ()));
2929 }
3030
3131 /** @test */
3232 public function shouldAcceptObjectMethodCallbackWithTypehint ()
3333 {
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 ()));
3636 }
3737
3838 /** @test */
3939 public function shouldAcceptStaticClassCallbackWithTypehint ()
4040 {
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 ()));
4343 }
4444
45- /** @test */
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 ()));
86+ }
87+
88+ /** @test */
4689 public function shouldAcceptClosureCallbackWithoutTypehint ()
4790 {
4891 self ::assertTrue (_checkTypehint (function (InvalidArgumentException $ e ) {
@@ -52,25 +95,25 @@ public function shouldAcceptClosureCallbackWithoutTypehint()
5295 /** @test */
5396 public function shouldAcceptFunctionStringCallbackWithoutTypehint ()
5497 {
55- self ::assertTrue (_checkTypehint (new TestCallbackWithTypehintClass (), new InvalidArgumentException ()));
98+ self ::assertTrue (_checkTypehint (new CallbackWithoutTypehintClass (), new InvalidArgumentException ()));
5699 }
57100
58101 /** @test */
59102 public function shouldAcceptInvokableObjectCallbackWithoutTypehint ()
60103 {
61- self ::assertTrue (_checkTypehint (new TestCallbackWithoutTypehintClass (), new InvalidArgumentException ()));
104+ self ::assertTrue (_checkTypehint (new CallbackWithoutTypehintClass (), new InvalidArgumentException ()));
62105 }
63106
64107 /** @test */
65108 public function shouldAcceptObjectMethodCallbackWithoutTypehint ()
66109 {
67- self ::assertTrue (_checkTypehint ([new TestCallbackWithoutTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
110+ self ::assertTrue (_checkTypehint ([new CallbackWithoutTypehintClass (), 'testCallback ' ], new InvalidArgumentException ()));
68111 }
69112
70113 /** @test */
71114 public function shouldAcceptStaticClassCallbackWithoutTypehint ()
72115 {
73- self ::assertTrue (_checkTypehint ([TestCallbackWithoutTypehintClass ::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
116+ self ::assertTrue (_checkTypehint ([CallbackWithoutTypehintClass ::class, 'testCallbackStatic ' ], new InvalidArgumentException ()));
74117 }
75118}
76119
@@ -81,33 +124,3 @@ function testCallbackWithTypehint(InvalidArgumentException $e)
81124function testCallbackWithoutTypehint ()
82125{
83126}
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