Add tests for _checkTypehint
Jan Sorgalla
9 years ago
0 | <?php | |
1 | ||
2 | namespace React\Promise; | |
3 | ||
4 | class FunctionCheckTypehintTest extends TestCase | |
5 | { | |
6 | /** @test */ | |
7 | public function shouldAcceptClosureCallbackWithTypehint() | |
8 | { | |
9 | $this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) { | |
10 | }, new \InvalidArgumentException())); | |
11 | $this->assertfalse(_checkTypehint(function (\InvalidArgumentException $e) { | |
12 | }, new \Exception())); | |
13 | } | |
14 | ||
15 | /** @test */ | |
16 | public function shouldAcceptFunctionStringCallbackWithTypehint() | |
17 | { | |
18 | $this->assertTrue(_checkTypehint('React\Promise\testCallbackWithTypehint', new \InvalidArgumentException())); | |
19 | $this->assertfalse(_checkTypehint('React\Promise\testCallbackWithTypehint', new \Exception())); | |
20 | } | |
21 | ||
22 | /** @test */ | |
23 | public function shouldAcceptInvokableObjectCallbackWithTypehint() | |
24 | { | |
25 | $this->assertTrue(_checkTypehint(new TestCallbackWithTypehintClass(), new \InvalidArgumentException())); | |
26 | $this->assertfalse(_checkTypehint(new TestCallbackWithTypehintClass(), new \Exception())); | |
27 | } | |
28 | ||
29 | /** @test */ | |
30 | public function shouldAcceptObjectMethodCallbackWithTypehint() | |
31 | { | |
32 | $this->assertTrue(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \InvalidArgumentException())); | |
33 | $this->assertfalse(_checkTypehint([new TestCallbackWithTypehintClass(), 'testCallback'], new \Exception())); | |
34 | } | |
35 | ||
36 | /** @test */ | |
37 | public function shouldAcceptStaticClassCallbackWithTypehint() | |
38 | { | |
39 | $this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException())); | |
40 | $this->assertfalse(_checkTypehint(['React\Promise\TestCallbackWithTypehintClass', 'testCallbackStatic'], new \Exception())); | |
41 | } | |
42 | ||
43 | /** @test */ | |
44 | public function shouldAcceptClosureCallbackWithoutTypehint() | |
45 | { | |
46 | $this->assertTrue(_checkTypehint(function (\InvalidArgumentException $e) { | |
47 | }, new \InvalidArgumentException())); | |
48 | } | |
49 | ||
50 | /** @test */ | |
51 | public function shouldAcceptFunctionStringCallbackWithoutTypehint() | |
52 | { | |
53 | $this->assertTrue(_checkTypehint('React\Promise\testCallbackWithoutTypehint', new \InvalidArgumentException())); | |
54 | } | |
55 | ||
56 | /** @test */ | |
57 | public function shouldAcceptInvokableObjectCallbackWithoutTypehint() | |
58 | { | |
59 | $this->assertTrue(_checkTypehint(new TestCallbackWithoutTypehintClass(), new \InvalidArgumentException())); | |
60 | } | |
61 | ||
62 | /** @test */ | |
63 | public function shouldAcceptObjectMethodCallbackWithoutTypehint() | |
64 | { | |
65 | $this->assertTrue(_checkTypehint([new TestCallbackWithoutTypehintClass(), 'testCallback'], new \InvalidArgumentException())); | |
66 | } | |
67 | ||
68 | /** @test */ | |
69 | public function shouldAcceptStaticClassCallbackWithoutTypehint() | |
70 | { | |
71 | $this->assertTrue(_checkTypehint(['React\Promise\TestCallbackWithoutTypehintClass', 'testCallbackStatic'], new \InvalidArgumentException())); | |
72 | } | |
73 | } | |
74 | ||
75 | function testCallbackWithTypehint(\InvalidArgumentException $e) | |
76 | { | |
77 | } | |
78 | ||
79 | function testCallbackWithoutTypehint() | |
80 | { | |
81 | } | |
82 | ||
83 | class TestCallbackWithTypehintClass | |
84 | { | |
85 | public function __invoke(\InvalidArgumentException $e) | |
86 | { | |
87 | ||
88 | } | |
89 | ||
90 | public function testCallback(\InvalidArgumentException $e) | |
91 | { | |
92 | ||
93 | } | |
94 | ||
95 | public static function testCallbackStatic(\InvalidArgumentException $e) | |
96 | { | |
97 | ||
98 | } | |
99 | } | |
100 | ||
101 | class TestCallbackWithoutTypehintClass | |
102 | { | |
103 | public function __invoke() | |
104 | { | |
105 | ||
106 | } | |
107 | ||
108 | public function testCallback() | |
109 | { | |
110 | ||
111 | } | |
112 | ||
113 | public static function testCallbackStatic() | |
114 | { | |
115 | ||
116 | } | |
117 | } |