Skip to content

Commit 2ac1771

Browse files
authored
Merge pull request KnpLabs#438 from MartinPeverelli/update_tests_for_phpunit55
Update tests for PHPUnit 5.5
2 parents 828f4d6 + 374ba99 commit 2ac1771

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"php-http/cache-plugin": "^1.2"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^4.0",
30+
"phpunit/phpunit": "^4.0 || ^5.5",
3131
"php-http/guzzle6-adapter": "^1.0",
3232
"guzzlehttp/psr7": "^1.2",
3333
"sllh/php-cs-fixer-styleci-bridge": "^1.3"

test/Github/Tests/Api/AbstractApiTest.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ public function shouldPassGETRequestToClient()
2020
->method('get')
2121
->with('/path?param1=param1value', array('header1' => 'header1value'))
2222
->will($this->returnValue($this->getPSR7Response($expectedArray)));
23-
$client = $this->getMock('Github\Client', array('getHttpClient'));
23+
$client = $this->getMockBuilder('Github\Client')
24+
->setMethods(array('getHttpClient'))
25+
->getMock();
2426
$client->expects($this->any())
2527
->method('getHttpClient')
2628
->willReturn($httpClient);
@@ -44,7 +46,9 @@ public function shouldPassPOSTRequestToClient()
4446
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
4547
->will($this->returnValue($this->getPSR7Response($expectedArray)));
4648

47-
$client = $this->getMock('Github\Client', array('getHttpClient'));
49+
$client = $this->getMockBuilder('Github\Client')
50+
->setMethods(array('getHttpClient'))
51+
->getMock();
4852
$client->expects($this->any())
4953
->method('getHttpClient')
5054
->willReturn($httpClient);
@@ -68,7 +72,9 @@ public function shouldPassPATCHRequestToClient()
6872
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
6973
->will($this->returnValue($this->getPSR7Response($expectedArray)));
7074

71-
$client = $this->getMock('Github\Client', array('getHttpClient'));
75+
$client = $this->getMockBuilder('Github\Client')
76+
->setMethods(array('getHttpClient'))
77+
->getMock();
7278
$client->expects($this->any())
7379
->method('getHttpClient')
7480
->willReturn($httpClient);
@@ -92,7 +98,9 @@ public function shouldPassPUTRequestToClient()
9298
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
9399
->will($this->returnValue($this->getPSR7Response($expectedArray)));
94100

95-
$client = $this->getMock('Github\Client', array('getHttpClient'));
101+
$client = $this->getMockBuilder('Github\Client')
102+
->setMethods(array('getHttpClient'))
103+
->getMock();
96104
$client->expects($this->any())
97105
->method('getHttpClient')
98106
->willReturn($httpClient);
@@ -116,7 +124,9 @@ public function shouldPassDELETERequestToClient()
116124
->with('/path', array('option1' => 'option1value'), json_encode(array('param1' => 'param1value')))
117125
->will($this->returnValue($this->getPSR7Response($expectedArray)));
118126

119-
$client = $this->getMock('Github\Client', array('getHttpClient'));
127+
$client = $this->getMockBuilder('Github\Client')
128+
->setMethods(array('getHttpClient'))
129+
->getMock();
120130
$client->expects($this->any())
121131
->method('getHttpClient')
122132
->willReturn($httpClient);
@@ -141,7 +151,9 @@ public function shouldNotPassEmptyRefToClient()
141151
->with('/path', array())
142152
->will($this->returnValue($this->getPSR7Response($expectedArray)));
143153

144-
$client = $this->getMock('Github\Client', array('getHttpClient'));
154+
$client = $this->getMockBuilder('Github\Client')
155+
->setMethods(array('getHttpClient'))
156+
->getMock();
145157
$client->expects($this->any())
146158
->method('getHttpClient')
147159
->willReturn($httpClient);
@@ -166,12 +178,16 @@ protected function getClientMock()
166178
/**
167179
* Return a HttpMethods client mock
168180
*
181+
* @param array $methods
169182
* @return \Http\Client\Common\HttpMethodsClient
170183
*/
171184
protected function getHttpMethodsMock(array $methods = array())
172185
{
173186
$methods = array_merge(array('sendRequest'), $methods);
174-
$mock = $this->getMock('Http\Client\Common\HttpMethodsClient', $methods, array(), '', false);
187+
$mock = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
188+
->disableOriginalConstructor()
189+
->setMethods($methods)
190+
->getMock();
175191
$mock
176192
->expects($this->any())
177193
->method('sendRequest');
@@ -183,7 +199,9 @@ protected function getHttpMethodsMock(array $methods = array())
183199
*/
184200
protected function getHttpClientMock()
185201
{
186-
$mock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
202+
$mock = $this->getMockBuilder('Http\Client\HttpClient')
203+
->setMethods(array('sendRequest'))
204+
->getMock();
187205
$mock
188206
->expects($this->any())
189207
->method('sendRequest');

test/Github/Tests/Api/TestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ abstract protected function getApiClass();
88

99
protected function getApiMock()
1010
{
11-
$httpClient = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
11+
$httpClient = $this->getMockBuilder('Http\Client\HttpClient')
12+
->setMethods(array('sendRequest'))
13+
->getMock();
1214
$httpClient
1315
->expects($this->any())
1416
->method('sendRequest');

test/Github/Tests/ClientTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ public function shouldNotHaveToPassHttpClientToConstructor()
2424
*/
2525
public function shouldPassHttpClientInterfaceToConstructor()
2626
{
27-
$client = new Client($this->getMock('Http\Client\HttpClient'));
27+
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
28+
->getMock();
29+
$client = new Client($httpClientMock);
2830

2931
$this->assertInstanceOf('Http\Client\HttpClient', $client->getHttpClient());
3032
}
@@ -35,7 +37,9 @@ public function shouldPassHttpClientInterfaceToConstructor()
3537
*/
3638
public function shouldAuthenticateUsingAllGivenParameters($login, $password, $method)
3739
{
38-
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
40+
$client = $this->getMockBuilder('Github\Client')
41+
->setMethods(array('addPlugin', 'removePlugin'))
42+
->getMock();
3943
$client->expects($this->once())
4044
->method('addPlugin')
4145
->with($this->equalTo(new Authentication($login, $password, $method)));
@@ -63,7 +67,9 @@ public function getAuthenticationFullData()
6367
*/
6468
public function shouldAuthenticateUsingGivenParameters($token, $method)
6569
{
66-
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
70+
$client = $this->getMockBuilder('Github\Client')
71+
->setMethods(array('addPlugin', 'removePlugin'))
72+
->getMock();
6773
$client->expects($this->once())
6874
->method('addPlugin')
6975
->with($this->equalTo(new Authentication($token, null, $method)));
@@ -99,7 +105,9 @@ public function shouldThrowExceptionWhenAuthenticatingWithoutMethodSet()
99105
*/
100106
public function shouldClearHeaders()
101107
{
102-
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
108+
$client = $this->getMockBuilder('Github\Client')
109+
->setMethods(array('addPlugin', 'removePlugin'))
110+
->getMock();
103111
$client->expects($this->once())
104112
->method('addPlugin')
105113
->with($this->isInstanceOf(Plugin\HeaderAppendPlugin::class));
@@ -118,7 +126,9 @@ public function shouldAddHeaders()
118126
{
119127
$headers = array('header1', 'header2');
120128

121-
$client = $this->getMock('Github\Client', array('addPlugin', 'removePlugin'));
129+
$client = $this->getMockBuilder('Github\Client')
130+
->setMethods(array('addPlugin', 'removePlugin'))
131+
->getMock();
122132
$client->expects($this->once())
123133
->method('addPlugin')
124134
// TODO verify that headers exists

test/Github/Tests/ResultPagerTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function shouldGetAllResults()
3131
$response = new PaginatedResponse($amountLoops, $content);
3232

3333
// httpClient mock
34-
$httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
34+
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
35+
->setMethods(array('sendRequest'))
36+
->getMock();
3537
$httpClientMock
3638
->expects($this->exactly($amountLoops))
3739
->method('sendRequest')
@@ -76,7 +78,9 @@ public function shouldGetAllSearchResults()
7678
$response = new PaginatedResponse($amountLoops, $content);
7779

7880
// httpClient mock
79-
$httpClientMock = $this->getMock('Http\Client\HttpClient', array('sendRequest'));
81+
$httpClientMock = $this->getMockBuilder('Http\Client\HttpClient')
82+
->setMethods(array('sendRequest'))
83+
->getMock();
8084
$httpClientMock
8185
->expects($this->exactly($amountLoops))
8286
->method('sendRequest')
@@ -97,9 +101,12 @@ public function testFetch()
97101
$result = 'foo';
98102
$method = 'bar';
99103
$parameters = array('baz');
100-
$api = $this->getMock('Github\Api\ApiInterface');
104+
$api = $this->createMock('Github\Api\ApiInterface');
101105

102-
$paginator = $this->getMock('Github\ResultPager', array('callApi', 'postFetch'), array(), '', false);
106+
$paginator = $this->getMockBuilder('Github\ResultPager')
107+
->disableOriginalConstructor()
108+
->setMethods(array('callApi', 'postFetch'))
109+
->getMock();
103110
$paginator->expects($this->once())
104111
->method('callApi')
105112
->with($api, $method, $parameters)

0 commit comments

Comments
 (0)