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,8 +30,7 @@ public function shouldPassGETRequestToClient()
29
30
30
31
$ api = $ this ->getAbstractApiObject ($ client );
31
32
32
- $ method = new \ReflectionMethod ($ api , 'get ' );
33
- $ method ->setAccessible (true );
33
+ $ method = $ this ->getMethodReflection ($ api , 'get ' );
34
34
35
35
$ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , ['param1 ' => 'param1value ' ], ['header1 ' => 'header1value ' ]]));
36
36
}
@@ -57,8 +57,7 @@ public function shouldPassPOSTRequestToClient()
57
57
->willReturn ($ httpClient );
58
58
59
59
$ api = $ this ->getAbstractApiObject ($ client );
60
- $ method = new \ReflectionMethod ($ api , 'post ' );
61
- $ method ->setAccessible (true );
60
+ $ method = $ this ->getMethodReflection ($ api , 'post ' );
62
61
63
62
$ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )]));
64
63
}
@@ -85,8 +84,7 @@ public function shouldPassPATCHRequestToClient()
85
84
->willReturn ($ httpClient );
86
85
87
86
$ api = $ this ->getAbstractApiObject ($ client );
88
- $ method = new \ReflectionMethod ($ api , 'patch ' );
89
- $ method ->setAccessible (true );
87
+ $ method = $ this ->getMethodReflection ($ api , 'patch ' );
90
88
91
89
$ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )]));
92
90
}
@@ -113,8 +111,7 @@ public function shouldPassPUTRequestToClient()
113
111
->willReturn ($ httpClient );
114
112
115
113
$ api = $ this ->getAbstractApiObject ($ client );
116
- $ method = new \ReflectionMethod ($ api , 'put ' );
117
- $ method ->setAccessible (true );
114
+ $ method = $ this ->getMethodReflection ($ api , 'put ' );
118
115
119
116
$ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )]));
120
117
}
@@ -142,8 +139,7 @@ public function shouldPassDELETERequestToClient()
142
139
143
140
144
141
$ api = $ this ->getAbstractApiObject ($ client );
145
- $ method = new \ReflectionMethod ($ api , 'delete ' );
146
- $ method ->setAccessible (true );
142
+ $ method = $ this ->getMethodReflection ($ api , 'delete ' );
147
143
148
144
$ this ->assertEquals ($ expectedArray , $ method ->invokeArgs ($ api , ['/path ' , array ('param1 ' => 'param1value ' ), array ('option1 ' => 'option1value ' )]));
149
145
}
@@ -170,8 +166,7 @@ public function shouldNotPassEmptyRefToClient()
170
166
->willReturn ($ httpClient );
171
167
172
168
$ api = $ this ->getAbstractApiObject ($ client );
173
- $ method = new \ReflectionMethod ($ api , 'get ' );
174
- $ method ->setAccessible (true );
169
+ $ method = $ this ->getMethodReflection ($ api , 'get ' );
175
170
176
171
$ this ->assertInternalType ('array ' , $ method ->invokeArgs ($ api , ['/path ' , array ('ref ' => null )]));
177
172
}
@@ -188,6 +183,19 @@ protected function getAbstractApiObject($client)
188
183
->getMock ();
189
184
}
190
185
186
+ /**
187
+ * @param $api
188
+ * @param $methodName
189
+ * @return ReflectionMethod
190
+ */
191
+ public function getMethodReflection ($ api , $ methodName )
192
+ {
193
+ $ method = new ReflectionMethod ($ api , $ methodName );
194
+ $ method ->setAccessible (true );
195
+
196
+ return $ method ;
197
+ }
198
+
191
199
/**
192
200
* @return \Github\Client
193
201
*/
0 commit comments