Skip to content

Commit 637fce5

Browse files
committed
removed unit test shouldNotUpdateHookWithoutName for #442
AbstractApiTest cleanup with ReflectionMethod createMock removed in ResultPagerTest like in #438 comment written
1 parent 7089069 commit 637fce5

File tree

4 files changed

+34
-89
lines changed

4 files changed

+34
-89
lines changed

test/Github/Tests/Api/AbstractApiTest.php

Lines changed: 28 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ public function shouldPassGETRequestToClient()
2929

3030
$api = $this->getAbstractApiObject($client);
3131

32-
$this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value')));
32+
$method = new \ReflectionMethod($api, 'get');
33+
$method->setAccessible(true);
34+
35+
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('header1' => 'header1value')]));
3336
}
3437

3538
/**
@@ -54,8 +57,10 @@ public function shouldPassPOSTRequestToClient()
5457
->willReturn($httpClient);
5558

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

58-
$this->assertEquals($expectedArray, $api->post('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
63+
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
5964
}
6065

6166
/**
@@ -80,8 +85,10 @@ public function shouldPassPATCHRequestToClient()
8085
->willReturn($httpClient);
8186

8287
$api = $this->getAbstractApiObject($client);
88+
$method = new \ReflectionMethod($api, 'patch');
89+
$method->setAccessible(true);
8390

84-
$this->assertEquals($expectedArray, $api->patch('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
91+
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
8592
}
8693

8794
/**
@@ -106,8 +113,10 @@ public function shouldPassPUTRequestToClient()
106113
->willReturn($httpClient);
107114

108115
$api = $this->getAbstractApiObject($client);
116+
$method = new \ReflectionMethod($api, 'put');
117+
$method->setAccessible(true);
109118

110-
$this->assertEquals($expectedArray, $api->put('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
119+
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
111120
}
112121

113122
/**
@@ -133,8 +142,10 @@ public function shouldPassDELETERequestToClient()
133142

134143

135144
$api = $this->getAbstractApiObject($client);
145+
$method = new \ReflectionMethod($api, 'delete');
146+
$method->setAccessible(true);
136147

137-
$this->assertEquals($expectedArray, $api->delete('/path', array('param1' => 'param1value'), array('option1' => 'option1value')));
148+
$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', array('param1' => 'param1value'), array('option1' => 'option1value')]));
138149
}
139150

140151
/**
@@ -159,12 +170,22 @@ public function shouldNotPassEmptyRefToClient()
159170
->willReturn($httpClient);
160171

161172
$api = $this->getAbstractApiObject($client);
162-
$api->get('/path', array('ref' => null));
173+
$method = new \ReflectionMethod($api, 'get');
174+
$method->setAccessible(true);
175+
176+
$this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)]));
163177
}
164178

179+
/**
180+
* @param $client
181+
* @return AbstractApi
182+
*/
165183
protected function getAbstractApiObject($client)
166184
{
167-
return new AbstractApiTestInstance($client);
185+
return $this->getMockBuilder(AbstractApi::class)
186+
->setMethods(null)
187+
->setConstructorArgs([$client])
188+
->getMock();
168189
}
169190

170191
/**
@@ -223,68 +244,3 @@ private function getPSR7Response($expectedArray)
223244
);
224245
}
225246
}
226-
227-
class AbstractApiTestInstance extends AbstractApi
228-
{
229-
/**
230-
* {@inheritDoc}
231-
*/
232-
public function get($path, array $parameters = 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(), $requestHeaders = array())
241-
{
242-
return parent::post($path, $parameters, $requestHeaders);
243-
}
244-
245-
/**
246-
* {@inheritDoc}
247-
*/
248-
public function postRaw($path, $body, $requestHeaders = array())
249-
{
250-
return parent::postRaw($path, $body, $requestHeaders);
251-
}
252-
253-
/**
254-
* {@inheritDoc}
255-
*/
256-
public function patch($path, array $parameters = 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(), $requestHeaders = array())
265-
{
266-
return parent::put($path, $parameters, $requestHeaders);
267-
}
268-
269-
/**
270-
* {@inheritDoc}
271-
*/
272-
public function delete($path, array $parameters = 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(), $requestHeaders = array())
287-
{
288-
return parent::get($path, $parameters, $requestHeaders);
289-
}
290-
}

test/Github/Tests/Api/Repository/HooksTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,6 @@ public function shouldCreateHook()
101101
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
102102
}
103103

104-
/**
105-
* @test
106-
* @expectedException \Github\Exception\MissingArgumentException
107-
*/
108-
public function shouldNotUpdateHookWithoutName()
109-
{
110-
$data = array('config' => 'someconf');
111-
112-
$api = $this->getApiMock();
113-
$api->expects($this->never())
114-
->method('patch');
115-
116-
$api->update('KnpLabs', 'php-github-api', 123, $data);
117-
}
118-
119104
/**
120105
* @test
121106
* @expectedException \Github\Exception\MissingArgumentException

test/Github/Tests/Api/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
66
{
77
abstract protected function getApiClass();
88

9+
/**
10+
* @return \PHPUnit_Framework_MockObject_MockObject
11+
*/
912
protected function getApiMock()
1013
{
11-
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
14+
$httpClient = $this->getMockBuilder(\Http\Client\HttpClient::class)
1215
->setMethods(array('sendRequest'))
1316
->getMock();
1417
$httpClient

test/Github/Tests/ResultPagerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public function testFetch()
101101
$result = 'foo';
102102
$method = 'bar';
103103
$parameters = array('baz');
104-
$api = $this->createMock('Github\Api\ApiInterface');
104+
$api = $this->getMockBuilder('Github\Api\ApiInterface')
105+
->getMock();
105106

106107
$paginator = $this->getMockBuilder('Github\ResultPager')
107108
->disableOriginalConstructor()

0 commit comments

Comments
 (0)