44
55use Github \Api \AbstractApi ;
66use GuzzleHttp \Psr7 \Response ;
7+ use ReflectionMethod ;
78
89class AbstractApiTest extends \PHPUnit_Framework_TestCase
910{
@@ -29,7 +30,9 @@ public function shouldPassGETRequestToClient()
2930
3031 $ api = $ this ->getAbstractApiObject ($ client );
3132
32- $ this ->assertEquals ($ expectedArray , $ api ->get ('/path ' , array ('param1 ' => 'param1value ' ), array ('header1 ' => 'header1value ' )));
33+ $ method = $ this ->getMethodReflection ($ api , 'get ' );
34+
35+ $ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['header1 ' => 'header1value ' ]]));
3336 }
3437
3538 /**
@@ -54,8 +57,9 @@ public function shouldPassPOSTRequestToClient()
5457 ->willReturn ($ httpClient );
5558
5659 $ api = $ this ->getAbstractApiObject ($ client );
60+ $ method = $ this ->getMethodReflection ($ api , 'post ' );
5761
58- $ this ->assertEquals ($ expectedArray , $ api -> post ( '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )));
62+ $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )] ));
5963 }
6064
6165 /**
@@ -80,8 +84,9 @@ public function shouldPassPATCHRequestToClient()
8084 ->willReturn ($ httpClient );
8185
8286 $ api = $ this ->getAbstractApiObject ($ client );
87+ $ method = $ this ->getMethodReflection ($ api , 'patch ' );
8388
84- $ this ->assertEquals ($ expectedArray , $ api -> patch ( '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )));
89+ $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )] ));
8590 }
8691
8792 /**
@@ -106,8 +111,9 @@ public function shouldPassPUTRequestToClient()
106111 ->willReturn ($ httpClient );
107112
108113 $ api = $ this ->getAbstractApiObject ($ client );
114+ $ method = $ this ->getMethodReflection ($ api , 'put ' );
109115
110- $ this ->assertEquals ($ expectedArray , $ api -> put ( '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )));
116+ $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )] ));
111117 }
112118
113119 /**
@@ -133,8 +139,9 @@ public function shouldPassDELETERequestToClient()
133139
134140
135141 $ api = $ this ->getAbstractApiObject ($ client );
142+ $ method = $ this ->getMethodReflection ($ api , 'delete ' );
136143
137- $ this ->assertEquals ($ expectedArray , $ api -> delete ( '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )));
144+ $ this ->assertEquals ($ expectedArray , $ method -> invokeArgs ( $ api , [ '/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )] ));
138145 }
139146
140147 /**
@@ -159,12 +166,34 @@ public function shouldNotPassEmptyRefToClient()
159166 ->willReturn ($ httpClient );
160167
161168 $ api = $ this ->getAbstractApiObject ($ client );
162- $ api ->get ('/path ' , array ('ref ' => null ));
169+ $ method = $ this ->getMethodReflection ($ api , 'get ' );
170+
171+ $ this ->assertInternalType ('array ' , $ method ->invokeArgs ($ api , ['/path ' , array ('ref ' => null )]));
163172 }
164173
174+ /**
175+ * @param $client
176+ * @return AbstractApi
177+ */
165178 protected function getAbstractApiObject ($ client )
166179 {
167- return new AbstractApiTestInstance ($ client );
180+ return $ this ->getMockBuilder (AbstractApi::class)
181+ ->setMethods (null )
182+ ->setConstructorArgs ([$ client ])
183+ ->getMock ();
184+ }
185+
186+ /**
187+ * @param $api
188+ * @param $methodName
189+ * @return ReflectionMethod
190+ */
191+ protected function getMethodReflection ($ api , $ methodName )
192+ {
193+ $ method = new ReflectionMethod ($ api , $ methodName );
194+ $ method ->setAccessible (true );
195+
196+ return $ method ;
168197 }
169198
170199 /**
@@ -223,68 +252,3 @@ private function getPSR7Response($expectedArray)
223252 );
224253 }
225254}
226-
227- class AbstractApiTestInstance extends AbstractApi
228- {
229- /**
230- * {@inheritDoc}
231- */
232- public function get ($ path , array $ parameters = array (), array $ requestHeaders = array ())
233- {
234- return parent ::get ($ path , $ parameters , $ requestHeaders );
235- }
236-
237- /**
238- * {@inheritDoc}
239- */
240- public function post ($ path , array $ parameters = array (), array $ requestHeaders = array ())
241- {
242- return parent ::post ($ path , $ parameters , $ requestHeaders );
243- }
244-
245- /**
246- * {@inheritDoc}
247- */
248- public function postRaw ($ path , $ body , array $ requestHeaders = array ())
249- {
250- return parent ::postRaw ($ path , $ body , $ requestHeaders );
251- }
252-
253- /**
254- * {@inheritDoc}
255- */
256- public function patch ($ path , array $ parameters = array (), array $ requestHeaders = array ())
257- {
258- return parent ::patch ($ path , $ parameters , $ requestHeaders );
259- }
260-
261- /**
262- * {@inheritDoc}
263- */
264- public function put ($ path , array $ parameters = array (), array $ requestHeaders = array ())
265- {
266- return parent ::put ($ path , $ parameters , $ requestHeaders );
267- }
268-
269- /**
270- * {@inheritDoc}
271- */
272- public function delete ($ path , array $ parameters = array (), array $ requestHeaders = array ())
273- {
274- return parent ::delete ($ path , $ parameters , $ requestHeaders );
275- }
276- }
277-
278- /**
279- * @deprecated
280- */
281- class ExposedAbstractApiTestInstance extends AbstractApi
282- {
283- /**
284- * {@inheritDoc}
285- */
286- public function get ($ path , array $ parameters = array (), array $ requestHeaders = array ())
287- {
288- return parent ::get ($ path , $ parameters , $ requestHeaders );
289- }
290- }
0 commit comments