Skip to content

Commit dafc942

Browse files
committed
added getMethodReflection and remove duplicating reflection parts
1 parent 1dde544 commit dafc942

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

test/Github/Tests/Api/AbstractApiTest.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Github\Api\AbstractApi;
66
use GuzzleHttp\Psr7\Response;
7+
use ReflectionMethod;
78

89
class AbstractApiTest extends \PHPUnit_Framework_TestCase
910
{
@@ -29,8 +30,7 @@ public function shouldPassGETRequestToClient()
2930

3031
$api = $this->getAbstractApiObject($client);
3132

32-
$method = new \ReflectionMethod($api, 'get');
33-
$method->setAccessible(true);
33+
$method = $this->getMethodReflection($api, 'get');
3434

3535
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']]));
3636
}
@@ -57,8 +57,7 @@ public function shouldPassPOSTRequestToClient()
5757
->willReturn($httpClient);
5858

5959
$api = $this->getAbstractApiObject($client);
60-
$method = new \ReflectionMethod($api, 'post');
61-
$method->setAccessible(true);
60+
$method = $this->getMethodReflection($api, 'post');
6261

6362
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
6463
}
@@ -85,8 +84,7 @@ public function shouldPassPATCHRequestToClient()
8584
->willReturn($httpClient);
8685

8786
$api = $this->getAbstractApiObject($client);
88-
$method = new \ReflectionMethod($api, 'patch');
89-
$method->setAccessible(true);
87+
$method = $this->getMethodReflection($api, 'patch');
9088

9189
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
9290
}
@@ -113,8 +111,7 @@ public function shouldPassPUTRequestToClient()
113111
->willReturn($httpClient);
114112

115113
$api = $this->getAbstractApiObject($client);
116-
$method = new \ReflectionMethod($api, 'put');
117-
$method->setAccessible(true);
114+
$method = $this->getMethodReflection($api, 'put');
118115

119116
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
120117
}
@@ -142,8 +139,7 @@ public function shouldPassDELETERequestToClient()
142139

143140

144141
$api = $this->getAbstractApiObject($client);
145-
$method = new \ReflectionMethod($api, 'delete');
146-
$method->setAccessible(true);
142+
$method = $this->getMethodReflection($api, 'delete');
147143

148144
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
149145
}
@@ -170,8 +166,7 @@ public function shouldNotPassEmptyRefToClient()
170166
->willReturn($httpClient);
171167

172168
$api = $this->getAbstractApiObject($client);
173-
$method = new \ReflectionMethod($api, 'get');
174-
$method->setAccessible(true);
169+
$method = $this->getMethodReflection($api, 'get');
175170

176171
$this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)]));
177172
}
@@ -188,6 +183,19 @@ protected function getAbstractApiObject($client)
188183
->getMock();
189184
}
190185

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+
191199
/**
192200
* @return \Github\Client
193201
*/

0 commit comments

Comments
 (0)