4
4
5
5
use Github \Api \AbstractApi ;
6
6
use GuzzleHttp \Psr7 \Response ;
7
- use ReflectionMethod ;
8
7
9
- class AbstractApiTest extends \PHPUnit_Framework_TestCase
8
+ class AbstractApiTest extends TestCase
10
9
{
11
10
/**
12
11
* @test
@@ -30,9 +29,10 @@ public function shouldPassGETRequestToClient()
30
29
31
30
$ api = $ this ->getAbstractApiObject ($ client );
32
31
33
- $ method = $ this ->getMethodReflection ($ api , 'get ' );
32
+ $ actual = $ this ->getMethod ($ api , 'get ' )
33
+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['header1 ' => 'header1value ' ]]);
34
34
35
- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , [ ' param1 ' => ' param1value ' ], [ ' header1 ' => ' header1value ' ]]) );
35
+ $ this ->assertEquals ($ expectedArray , $ actual );
36
36
}
37
37
38
38
/**
@@ -57,9 +57,10 @@ public function shouldPassPOSTRequestToClient()
57
57
->willReturn ($ httpClient );
58
58
59
59
$ api = $ this ->getAbstractApiObject ($ client );
60
- $ method = $ this ->getMethodReflection ($ api , 'post ' );
60
+ $ actual = $ this ->getMethod ($ api , 'post ' )
61
+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
61
62
62
- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
63
+ $ this ->assertEquals ($ expectedArray , $ actual );
63
64
}
64
65
65
66
/**
@@ -84,9 +85,10 @@ public function shouldPassPATCHRequestToClient()
84
85
->willReturn ($ httpClient );
85
86
86
87
$ api = $ this ->getAbstractApiObject ($ client );
87
- $ method = $ this ->getMethodReflection ($ api , 'patch ' );
88
+ $ actual = $ this ->getMethod ($ api , 'patch ' )
89
+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
88
90
89
- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
91
+ $ this ->assertEquals ($ expectedArray , $ actual );
90
92
}
91
93
92
94
/**
@@ -111,9 +113,10 @@ public function shouldPassPUTRequestToClient()
111
113
->willReturn ($ httpClient );
112
114
113
115
$ api = $ this ->getAbstractApiObject ($ client );
114
- $ method = $ this ->getMethodReflection ($ api , 'put ' );
116
+ $ actual = $ this ->getMethod ($ api , 'put ' )
117
+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
115
118
116
- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
119
+ $ this ->assertEquals ($ expectedArray , $ actual );
117
120
}
118
121
119
122
/**
@@ -139,9 +142,10 @@ public function shouldPassDELETERequestToClient()
139
142
140
143
141
144
$ api = $ this ->getAbstractApiObject ($ client );
142
- $ method = $ this ->getMethodReflection ($ api , 'delete ' );
145
+ $ actual = $ this ->getMethod ($ api , 'delete ' )
146
+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
143
147
144
- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
148
+ $ this ->assertEquals ($ expectedArray , $ actual );
145
149
}
146
150
147
151
/**
@@ -166,34 +170,29 @@ public function shouldNotPassEmptyRefToClient()
166
170
->willReturn ($ httpClient );
167
171
168
172
$ api = $ this ->getAbstractApiObject ($ client );
169
- $ method = $ this ->getMethodReflection ($ api , 'get ' );
173
+ $ actual = $ this ->getMethod ($ api , 'get ' )-> invokeArgs ( $ api , [ ' /path ' , [ ' ref ' => null ]] );
170
174
171
- $ this ->assertInternalType ('array ' , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' ref ' => null )]) );
175
+ $ this ->assertInternalType ('array ' , $ actual );
172
176
}
173
177
174
178
/**
175
179
* @param $client
176
- * @return AbstractApi
180
+ * @return \PHPUnit_Framework_MockObject_MockObject
177
181
*/
178
182
protected function getAbstractApiObject ($ client )
179
183
{
180
- return $ this ->getMockBuilder (AbstractApi::class )
184
+ return $ this ->getMockBuilder ($ this -> getApiClass () )
181
185
->setMethods (null )
182
186
->setConstructorArgs ([$ client ])
183
187
->getMock ();
184
188
}
185
189
186
190
/**
187
- * @param $api
188
- * @param $methodName
189
- * @return ReflectionMethod
191
+ * @return string
190
192
*/
191
- protected function getMethodReflection ( $ api , $ methodName )
193
+ protected function getApiClass ( )
192
194
{
193
- $ method = new ReflectionMethod ($ api , $ methodName );
194
- $ method ->setAccessible (true );
195
-
196
- return $ method ;
195
+ return AbstractApi::class;
197
196
}
198
197
199
198
/**
0 commit comments