Skip to content
Closed
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
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"phpunit/phpunit": "^4.0 || ^5.5",
"php-http/guzzle6-adapter": "^1.0",
"guzzlehttp/psr7": "^1.2",
"sllh/php-cs-fixer-styleci-bridge": "^1.3"
"sllh/php-cs-fixer-styleci-bridge": "^1.3",
"nyholm/nsa": "^1.0"
},
"autoload": {
"psr-4": { "Github\\": "lib/Github/" }
Expand Down
40 changes: 7 additions & 33 deletions test/Github/Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

class AbstractApiTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -29,10 +29,7 @@ public function shouldPassGETRequestToClient()
->willReturn($httpClient);

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

$method = $this->getMethodReflection($api, 'get');

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

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

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

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

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

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

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

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

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

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

/**
Expand All @@ -139,9 +130,7 @@ public function shouldPassDELETERequestToClient()


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

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

/**
Expand All @@ -166,9 +155,7 @@ public function shouldNotPassEmptyRefToClient()
->willReturn($httpClient);

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

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

/**
Expand All @@ -183,19 +170,6 @@ protected function getAbstractApiObject($client)
->getMock();
}

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

return $method;
}

/**
* @return \Github\Client
*/
Expand Down