Skip to content

phpunit update #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 36 additions & 72 deletions test/Github/Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Github\Api\AbstractApi;
use GuzzleHttp\Psr7\Response;
use ReflectionMethod;

class AbstractApiTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -29,7 +30,9 @@ public function shouldPassGETRequestToClient()

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

$this->assertEquals($expectedArray, $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value')));
$method = $this->getMethodReflection($api, 'get');

$this->assertEquals($expectedArray, $method->invokeArgs($api, ['/path', ['param1' => 'param1value'], ['header1' => 'header1value']]));
}

/**
Expand All @@ -54,8 +57,9 @@ public function shouldPassPOSTRequestToClient()
->willReturn($httpClient);

$api = $this->getAbstractApiObject($client);
$method = $this->getMethodReflection($api, 'post');

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

/**
Expand All @@ -80,8 +84,9 @@ public function shouldPassPATCHRequestToClient()
->willReturn($httpClient);

$api = $this->getAbstractApiObject($client);
$method = $this->getMethodReflection($api, 'patch');

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

/**
Expand All @@ -106,8 +111,9 @@ public function shouldPassPUTRequestToClient()
->willReturn($httpClient);

$api = $this->getAbstractApiObject($client);
$method = $this->getMethodReflection($api, 'put');

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

/**
Expand All @@ -133,8 +139,9 @@ public function shouldPassDELETERequestToClient()


$api = $this->getAbstractApiObject($client);
$method = $this->getMethodReflection($api, 'delete');

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

/**
Expand All @@ -159,12 +166,34 @@ public function shouldNotPassEmptyRefToClient()
->willReturn($httpClient);

$api = $this->getAbstractApiObject($client);
$api->get('/path', array('ref' => null));
$method = $this->getMethodReflection($api, 'get');

$this->assertInternalType('array', $method->invokeArgs($api, ['/path', array('ref' => null)]));
}

/**
* @param $client
* @return AbstractApi
*/
protected function getAbstractApiObject($client)
{
return new AbstractApiTestInstance($client);
return $this->getMockBuilder(AbstractApi::class)
->setMethods(null)
->setConstructorArgs([$client])
->getMock();
}

/**
* @param $api
* @param $methodName
* @return ReflectionMethod
*/
protected function getMethodReflection($api, $methodName)
{
$method = new ReflectionMethod($api, $methodName);
$method->setAccessible(true);

return $method;
}

/**
Expand Down Expand Up @@ -223,68 +252,3 @@ private function getPSR7Response($expectedArray)
);
}
}

class AbstractApiTestInstance extends AbstractApi
{
/**
* {@inheritDoc}
*/
public function get($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::get($path, $parameters, $requestHeaders);
}

/**
* {@inheritDoc}
*/
public function post($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::post($path, $parameters, $requestHeaders);
}

/**
* {@inheritDoc}
*/
public function postRaw($path, $body, array $requestHeaders = array())
{
return parent::postRaw($path, $body, $requestHeaders);
}

/**
* {@inheritDoc}
*/
public function patch($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::patch($path, $parameters, $requestHeaders);
}

/**
* {@inheritDoc}
*/
public function put($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::put($path, $parameters, $requestHeaders);
}

/**
* {@inheritDoc}
*/
public function delete($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::delete($path, $parameters, $requestHeaders);
}
}

/**
* @deprecated
*/
class ExposedAbstractApiTestInstance extends AbstractApi
{
/**
* {@inheritDoc}
*/
public function get($path, array $parameters = array(), array $requestHeaders = array())
{
return parent::get($path, $parameters, $requestHeaders);
}
}
5 changes: 4 additions & 1 deletion test/Github/Tests/Api/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
{
abstract protected function getApiClass();

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getApiMock()
{
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
$httpClient = $this->getMockBuilder(\Http\Client\HttpClient::class)
->setMethods(array('sendRequest'))
->getMock();
$httpClient
Expand Down
3 changes: 2 additions & 1 deletion test/Github/Tests/ResultPagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public function testFetch()
$result = 'foo';
$method = 'bar';
$parameters = array('baz');
$api = $this->createMock('Github\Api\ApiInterface');
$api = $this->getMockBuilder('Github\Api\ApiInterface')
->getMock();

$paginator = $this->getMockBuilder('Github\ResultPager')
->disableOriginalConstructor()
Expand Down