Skip to content

Update tests for PHPUnit 5.5 #438

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 1 commit into from
Oct 14, 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"php-http/cache-plugin": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "^4.0",
"phpunit/phpunit": "^4.0 || ^5.5",
"php-http/guzzle6-adapter": "^1.0",
"guzzlehttp/psr7": "^1.2",
"sllh/php-cs-fixer-styleci-bridge": "^1.3"
Expand Down
34 changes: 26 additions & 8 deletions test/Github/Tests/Api/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public function shouldPassGETRequestToClient()
->method('get')
->with('/path?param1=param1value', array('header1' => 'header1value'))
->will($this->returnValue($this->getPSR7Response($expectedArray)));
$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -44,7 +46,9 @@ public function shouldPassPOSTRequestToClient()
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
->will($this->returnValue($this->getPSR7Response($expectedArray)));

$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -68,7 +72,9 @@ public function shouldPassPATCHRequestToClient()
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
->will($this->returnValue($this->getPSR7Response($expectedArray)));

$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -92,7 +98,9 @@ public function shouldPassPUTRequestToClient()
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
->will($this->returnValue($this->getPSR7Response($expectedArray)));

$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -116,7 +124,9 @@ public function shouldPassDELETERequestToClient()
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
->will($this->returnValue($this->getPSR7Response($expectedArray)));

$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -141,7 +151,9 @@ public function shouldNotPassEmptyRefToClient()
->with('/path', array())
->will($this->returnValue($this->getPSR7Response($expectedArray)));

$client = $this->getMock('Github\Client', array('getHttpClient'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('getHttpClient'))
->getMock();
$client->expects($this->any())
->method('getHttpClient')
->willReturn($httpClient);
Expand All @@ -166,12 +178,16 @@ protected function getClientMock()
/**
* Return a HttpMethods client mock
*
* @param array $methods
* @return \Http\Client\Common\HttpMethodsClient
*/
protected function getHttpMethodsMock(array $methods = array())
{
$methods = array_merge(array('sendRequest'), $methods);
$mock = $this->getMock('Http\Client\Common\HttpMethodsClient', $methods, array(), '', false);
$mock = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
->disableOriginalConstructor()
->setMethods($methods)
->getMock();
$mock
->expects($this->any())
->method('sendRequest');
Expand All @@ -183,7 +199,9 @@ protected function getHttpMethodsMock(array $methods = array())
*/
protected function getHttpClientMock()
{
$mock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
$mock = $this->getMockBuilder('Http\Client\HttpClient')
->setMethods(array('sendRequest'))
->getMock();
$mock
->expects($this->any())
->method('sendRequest');
Expand Down
4 changes: 3 additions & 1 deletion test/Github/Tests/Api/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ abstract protected function getApiClass();

protected function getApiMock()
{
$httpClient = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
->setMethods(array('sendRequest'))
->getMock();
$httpClient
->expects($this->any())
->method('sendRequest');
Expand Down
20 changes: 15 additions & 5 deletions test/Github/Tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function shouldNotHaveToPassHttpClientToConstructor()
*/
public function shouldPassHttpClientInterfaceToConstructor()
{
$client = new Client($this->getMock('Http\Client\HttpClient'));
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
->getMock();
$client = new Client($httpClientMock);

$this->assertInstanceOf('Http\Client\HttpClient', $client->getHttpClient());
}
Expand All @@ -35,7 +37,9 @@ public function shouldPassHttpClientInterfaceToConstructor()
*/
public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method)
{
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('addPlugin', 'removePlugin'))
->getMock();
$client->expects($this->once())
->method('addPlugin')
->with($this->equalTo(new Authentication($login, $password, $method)));
Expand Down Expand Up @@ -63,7 +67,9 @@ public function getAuthenticationFullData()
*/
public function shouldAuthenticateUsingGivenParameters($token, $method)
{
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('addPlugin', 'removePlugin'))
->getMock();
$client->expects($this->once())
->method('addPlugin')
->with($this->equalTo(new Authentication($token, null, $method)));
Expand Down Expand Up @@ -99,7 +105,9 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet()
*/
public function shouldClearHeaders()
{
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('addPlugin', 'removePlugin'))
->getMock();
$client->expects($this->once())
->method('addPlugin')
->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class));
Expand All @@ -118,7 +126,9 @@ public function shouldAddHeaders()
{
$headers = array('header1', 'header2');

$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
$client = $this->getMockBuilder('Github\Client')
->setMethods(array('addPlugin', 'removePlugin'))
->getMock();
$client->expects($this->once())
->method('addPlugin')
// TODO verify that headers exists
Expand Down
15 changes: 11 additions & 4 deletions test/Github/Tests/ResultPagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ public function shouldGetAllResults()
$response = new PaginatedResponse($amountLoops, $content);

// httpClient mock
$httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
->setMethods(array('sendRequest'))
->getMock();
$httpClientMock
->expects($this->exactly($amountLoops))
->method('sendRequest')
Expand Down Expand Up @@ -76,7 +78,9 @@ public function shouldGetAllSearchResults()
$response = new PaginatedResponse($amountLoops, $content);

// httpClient mock
$httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
->setMethods(array('sendRequest'))
->getMock();
$httpClientMock
->expects($this->exactly($amountLoops))
->method('sendRequest')
Expand All @@ -97,9 +101,12 @@ public function testFetch()
$result = 'foo';
$method = 'bar';
$parameters = array('baz');
$api = $this->getMock('Github\Api\ApiInterface');
$api = $this->createMock('Github\Api\ApiInterface');
Copy link
Contributor

@kokspflanze kokspflanze Sep 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createMock was added in PHPUnit 5.4 and PHPUnit 5.X is min PHP 5.6

https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0#new-features

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use getMockBuilder() instead which works on all supported PHPUnit versions without triggering deprecations.


$paginator = $this->getMock('Github\ResultPager', array('callApi', 'postFetch'), array(), '', false);
$paginator = $this->getMockBuilder('Github\ResultPager')
->disableOriginalConstructor()
->setMethods(array('callApi', 'postFetch'))
->getMock();
$paginator->expects($this->once())
->method('callApi')
->with($api, $method, $parameters)
Expand Down