@@ -23,22 +23,65 @@ public function shouldAcceptFunctionStringCallbackWithTypehint()
2323 /** @test */
2424 public function shouldAcceptInvokableObjectCallbackWithTypehint ()
2525 {
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 ()));
2828 }
2929
3030 /** @test */
3131 public function shouldAcceptObjectMethodCallbackWithTypehint ()
3232 {
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 ()));
3535 }
3636
3737 /** @test */
3838 public function shouldAcceptStaticClassCallbackWithTypehint ()
3939 {
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 ()));
4285 }
4386
4487 /** @test */
@@ -57,19 +100,19 @@ public function shouldAcceptFunctionStringCallbackWithoutTypehint()
57100 /** @test */
58101 public function shouldAcceptInvokableObjectCallbackWithoutTypehint ()
59102 {
60- $ this ->assertTrue (_checkTypehint (new TestCallbackWithoutTypehintClass (), new \InvalidArgumentException ()));
103+ $ this ->assertTrue (_checkTypehint (new CallbackWithoutTypehintClass (), new \InvalidArgumentException ()));
61104 }
62105
63106 /** @test */
64107 public function shouldAcceptObjectMethodCallbackWithoutTypehint ()
65108 {
66- $ this ->assertTrue (_checkTypehint ([new TestCallbackWithoutTypehintClass (), 'testCallback ' ], new \InvalidArgumentException ()));
109+ $ this ->assertTrue (_checkTypehint ([new CallbackWithoutTypehintClass (), 'testCallback ' ], new \InvalidArgumentException ()));
67110 }
68111
69112 /** @test */
70113 public function shouldAcceptStaticClassCallbackWithoutTypehint ()
71114 {
72- $ this ->assertTrue (_checkTypehint (['React\Promise\TestCallbackWithoutTypehintClass ' , 'testCallbackStatic ' ], new \InvalidArgumentException ()));
115+ $ this ->assertTrue (_checkTypehint (['React\Promise\CallbackWithoutTypehintClass ' , 'testCallbackStatic ' ], new \InvalidArgumentException ()));
73116 }
74117}
75118
@@ -80,39 +123,3 @@ function testCallbackWithTypehint(\InvalidArgumentException $e)
80123function testCallbackWithoutTypehint ()
81124{
82125}
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