4
4
5
5
use Github \Api \AbstractApi ;
6
6
use GuzzleHttp \Psr7 \Response ;
7
+ use ReflectionMethod ;
7
8
8
9
class AbstractApiTest extends \PHPUnit_Framework_TestCase
9
10
{
@@ -29,7 +30,9 @@ public function shouldPassGETRequestToClient()
29
30
30
31
$ api = $ this ->getAbstractApiObject ($ client );
31
32
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 ' ]]));
33
36
}
34
37
35
38
/**
@@ -54,8 +57,9 @@ public function shouldPassPOSTRequestToClient()
54
57
->willReturn ($ httpClient );
55
58
56
59
$ api = $ this ->getAbstractApiObject ($ client );
60
+ $ method = $ this ->getMethodReflection ($ api , 'post ' );
57
61
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 ' )] ));
59
63
}
60
64
61
65
/**
@@ -80,8 +84,9 @@ public function shouldPassPATCHRequestToClient()
80
84
->willReturn ($ httpClient );
81
85
82
86
$ api = $ this ->getAbstractApiObject ($ client );
87
+ $ method = $ this ->getMethodReflection ($ api , 'patch ' );
83
88
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 ' )] ));
85
90
}
86
91
87
92
/**
@@ -106,8 +111,9 @@ public function shouldPassPUTRequestToClient()
106
111
->willReturn ($ httpClient );
107
112
108
113
$ api = $ this ->getAbstractApiObject ($ client );
114
+ $ method = $ this ->getMethodReflection ($ api , 'put ' );
109
115
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 ' )] ));
111
117
}
112
118
113
119
/**
@@ -133,8 +139,9 @@ public function shouldPassDELETERequestToClient()
133
139
134
140
135
141
$ api = $ this ->getAbstractApiObject ($ client );
142
+ $ method = $ this ->getMethodReflection ($ api , 'delete ' );
136
143
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 ' )] ));
138
145
}
139
146
140
147
/**
@@ -159,12 +166,34 @@ public function shouldNotPassEmptyRefToClient()
159
166
->willReturn ($ httpClient );
160
167
161
168
$ 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 )]));
163
172
}
164
173
174
+ /**
175
+ * @param $client
176
+ * @return AbstractApi
177
+ */
165
178
protected function getAbstractApiObject ($ client )
166
179
{
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 ;
168
197
}
169
198
170
199
/**
@@ -223,68 +252,3 @@ private function getPSR7Response($expectedArray)
223
252
);
224
253
}
225
254
}
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