44
55use Github \Api \AbstractApi ;
66use GuzzleHttp \Psr7 \Response ;
7- use ReflectionMethod ;
87
9- class AbstractApiTest extends \PHPUnit_Framework_TestCase
8+ class AbstractApiTest extends TestCase
109{
1110 /**
1211 * @test
@@ -30,9 +29,10 @@ public function shouldPassGETRequestToClient()
3029
3130 $ api = $ this ->getAbstractApiObject ($ client );
3231
33- $ method = $ this ->getMethodReflection ($ api , 'get ' );
32+ $ actual = $ this ->getMethod ($ api , 'get ' )
33+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['header1 ' => 'header1value ' ]]);
3434
35- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , [ ' param1 ' => ' param1value ' ], [ ' header1 ' => ' header1value ' ]]) );
35+ $ this ->assertEquals ($ expectedArray , $ actual );
3636 }
3737
3838 /**
@@ -57,9 +57,10 @@ public function shouldPassPOSTRequestToClient()
5757 ->willReturn ($ httpClient );
5858
5959 $ api = $ this ->getAbstractApiObject ($ client );
60- $ method = $ this ->getMethodReflection ($ api , 'post ' );
60+ $ actual = $ this ->getMethod ($ api , 'post ' )
61+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
6162
62- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
63+ $ this ->assertEquals ($ expectedArray , $ actual );
6364 }
6465
6566 /**
@@ -84,9 +85,10 @@ public function shouldPassPATCHRequestToClient()
8485 ->willReturn ($ httpClient );
8586
8687 $ api = $ this ->getAbstractApiObject ($ client );
87- $ method = $ this ->getMethodReflection ($ api , 'patch ' );
88+ $ actual = $ this ->getMethod ($ api , 'patch ' )
89+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
8890
89- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
91+ $ this ->assertEquals ($ expectedArray , $ actual );
9092 }
9193
9294 /**
@@ -111,9 +113,10 @@ public function shouldPassPUTRequestToClient()
111113 ->willReturn ($ httpClient );
112114
113115 $ api = $ this ->getAbstractApiObject ($ client );
114- $ method = $ this ->getMethodReflection ($ api , 'put ' );
116+ $ actual = $ this ->getMethod ($ api , 'put ' )
117+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
115118
116- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
119+ $ this ->assertEquals ($ expectedArray , $ actual );
117120 }
118121
119122 /**
@@ -139,9 +142,10 @@ public function shouldPassDELETERequestToClient()
139142
140143
141144 $ api = $ this ->getAbstractApiObject ($ client );
142- $ method = $ this ->getMethodReflection ($ api , 'delete ' );
145+ $ actual = $ this ->getMethod ($ api , 'delete ' )
146+ ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['option1 ' => 'option1value ' ]]);
143147
144- $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' param1 ' => ' param1value ' ), array ( ' option1 ' => ' option1value ' )]) );
148+ $ this ->assertEquals ($ expectedArray , $ actual );
145149 }
146150
147151 /**
@@ -166,34 +170,29 @@ public function shouldNotPassEmptyRefToClient()
166170 ->willReturn ($ httpClient );
167171
168172 $ api = $ this ->getAbstractApiObject ($ client );
169- $ method = $ this ->getMethodReflection ($ api , 'get ' );
173+ $ actual = $ this ->getMethod ($ api , 'get ' )-> invokeArgs ( $ api , [ ' /path ' , [ ' ref ' => null ]] );
170174
171- $ this ->assertInternalType ('array ' , $ method -> invokeArgs ( $ api , [ ' /path ' , array ( ' ref ' => null )]) );
175+ $ this ->assertInternalType ('array ' , $ actual );
172176 }
173177
174178 /**
175179 * @param $client
176- * @return AbstractApi
180+ * @return \PHPUnit_Framework_MockObject_MockObject
177181 */
178182 protected function getAbstractApiObject ($ client )
179183 {
180- return $ this ->getMockBuilder (AbstractApi::class )
184+ return $ this ->getMockBuilder ($ this -> getApiClass () )
181185 ->setMethods (null )
182186 ->setConstructorArgs ([$ client ])
183187 ->getMock ();
184188 }
185189
186190 /**
187- * @param $api
188- * @param $methodName
189- * @return ReflectionMethod
191+ * @return string
190192 */
191- protected function getMethodReflection ( $ api , $ methodName )
193+ protected function getApiClass ( )
192194 {
193- $ method = new ReflectionMethod ($ api , $ methodName );
194- $ method ->setAccessible (true );
195-
196- return $ method ;
195+ return AbstractApi::class;
197196 }
198197
199198 /**
0 commit comments