-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
tests: Upgrade unit tests for PHP 7.4 compat #1710
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Client; | ||
use Prophecy\Argument; | ||
|
||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
|
@@ -23,128 +23,133 @@ | |
|
||
class Google_AccessToken_RevokeTest extends BaseTest | ||
{ | ||
public function testRevokeAccessGuzzle5() | ||
{ | ||
$this->onlyGuzzle5(); | ||
|
||
$accessToken = 'ACCESS_TOKEN'; | ||
$refreshToken = 'REFRESH_TOKEN'; | ||
$token = ''; | ||
|
||
$response = $this->getMock('GuzzleHttp\Message\ResponseInterface'); | ||
$response->expects($this->exactly(3)) | ||
->method('getStatusCode') | ||
->will($this->returnValue(200)); | ||
$http = $this->getMock('GuzzleHttp\ClientInterface'); | ||
$http->expects($this->exactly(3)) | ||
->method('send') | ||
->will($this->returnCallback( | ||
function ($request) use (&$token, $response) { | ||
parse_str((string) $request->getBody(), $fields); | ||
$token = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $response; | ||
} | ||
)); | ||
|
||
$requestToken = null; | ||
$request = $this->getMock('GuzzleHttp\Message\RequestInterface'); | ||
$request->expects($this->exactly(3)) | ||
->method('getBody') | ||
->will($this->returnCallback( | ||
function () use (&$requestToken) { | ||
return 'token='.$requestToken; | ||
})); | ||
$http->expects($this->exactly(3)) | ||
->method('createRequest') | ||
->will($this->returnCallback( | ||
function ($method, $url, $params) use (&$requestToken, $request) { | ||
parse_str((string) $params['body'], $fields); | ||
$requestToken = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $request; | ||
} | ||
)); | ||
|
||
$t = array( | ||
'access_token' => $accessToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
); | ||
|
||
// Test with access token. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
|
||
// Test with refresh token. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$t = array( | ||
'access_token' => $accessToken, | ||
'refresh_token' => $refreshToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($refreshToken, $token); | ||
|
||
// Test with token string. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$t = $accessToken; | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
} | ||
|
||
public function testRevokeAccessGuzzle6() | ||
{ | ||
$this->onlyGuzzle6(); | ||
|
||
$accessToken = 'ACCESS_TOKEN'; | ||
$refreshToken = 'REFRESH_TOKEN'; | ||
$token = ''; | ||
|
||
$response = $this->getMock('Psr\Http\Message\ResponseInterface'); | ||
$response->expects($this->exactly(3)) | ||
->method('getStatusCode') | ||
->will($this->returnValue(200)); | ||
$http = $this->getMock('GuzzleHttp\ClientInterface'); | ||
$http->expects($this->exactly(3)) | ||
->method('send') | ||
->will($this->returnCallback( | ||
function ($request) use (&$token, $response) { | ||
parse_str((string) $request->getBody(), $fields); | ||
$token = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $response; | ||
} | ||
)); | ||
|
||
$t = array( | ||
'access_token' => $accessToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
); | ||
|
||
// Test with access token. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
|
||
// Test with refresh token. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$t = array( | ||
'access_token' => $accessToken, | ||
'refresh_token' => $refreshToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($refreshToken, $token); | ||
|
||
// Test with token string. | ||
$revoke = new Google_AccessToken_Revoke($http); | ||
$t = $accessToken; | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
} | ||
public function testRevokeAccessGuzzle5() | ||
{ | ||
$this->onlyGuzzle5(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you fix the spaces here but not in the other tests? Is it because you realized that arduous task would crush your soul? FWIW I think this is great, and if we want we can have a follow-up PR for just converting 2 spaces to 4 spaces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, that's a fairly good description of what happened. |
||
|
||
$accessToken = 'ACCESS_TOKEN'; | ||
$refreshToken = 'REFRESH_TOKEN'; | ||
$token = ''; | ||
|
||
$response = $this->prophesize('GuzzleHttp\Message\ResponseInterface'); | ||
$response->getStatusCode() | ||
->shouldBeCalledTimes(3) | ||
->willReturn(200); | ||
|
||
$response->getHeaders()->willReturn([]); | ||
$response->getBody()->willReturn(''); | ||
$response->getProtocolVersion()->willReturn(''); | ||
$response->getReasonPhrase()->willReturn(''); | ||
|
||
$http = $this->prophesize('GuzzleHttp\ClientInterface'); | ||
$http->send(Argument::type('GuzzleHttp\Message\RequestInterface')) | ||
->shouldBeCalledTimes(3) | ||
->will(function ($args) use (&$token, $response) { | ||
$request = $args[0]; | ||
parse_str((string) $request->getBody(), $fields); | ||
$token = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $response->reveal(); | ||
}); | ||
|
||
$requestToken = null; | ||
$request = $this->prophesize('GuzzleHttp\Message\RequestInterface'); | ||
$request->getBody() | ||
->shouldBeCalledTimes(3) | ||
->will(function () use (&$requestToken) { | ||
return 'token='.$requestToken; | ||
}); | ||
|
||
$http->createRequest(Argument::any(), Argument::any(), Argument::any()) | ||
->shouldBeCalledTimes(3) | ||
->will(function ($args) use (&$requestToken, $request) { | ||
$params = $args[2]; | ||
parse_str((string) $params['body'], $fields); | ||
$requestToken = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $request; | ||
}); | ||
|
||
$t = [ | ||
'access_token' => $accessToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
]; | ||
|
||
// Test with access token. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
|
||
// Test with refresh token. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$t = [ | ||
'access_token' => $accessToken, | ||
'refresh_token' => $refreshToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
]; | ||
|
||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($refreshToken, $token); | ||
|
||
// Test with token string. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$t = $accessToken; | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
} | ||
|
||
public function testRevokeAccessGuzzle6() | ||
{ | ||
$this->onlyGuzzle6(); | ||
|
||
$accessToken = 'ACCESS_TOKEN'; | ||
$refreshToken = 'REFRESH_TOKEN'; | ||
$token = ''; | ||
|
||
$response = $this->prophesize('Psr\Http\Message\ResponseInterface'); | ||
$response->getStatusCode() | ||
->shouldBeCalledTimes(3) | ||
->willReturn(200); | ||
|
||
$http = $this->prophesize('GuzzleHttp\ClientInterface'); | ||
$http->send(Argument::type('Psr\Http\Message\RequestInterface'), []) | ||
->shouldBeCalledTimes(3) | ||
->will(function ($args) use (&$token, $response) { | ||
parse_str((string) $args[0]->getBody(), $fields); | ||
$token = isset($fields['token']) ? $fields['token'] : null; | ||
|
||
return $response->reveal(); | ||
}); | ||
|
||
$t = [ | ||
'access_token' => $accessToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
]; | ||
|
||
// Test with access token. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
|
||
// Test with refresh token. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$t = [ | ||
'access_token' => $accessToken, | ||
'refresh_token' => $refreshToken, | ||
'created' => time(), | ||
'expires_in' => '3600' | ||
]; | ||
|
||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($refreshToken, $token); | ||
|
||
// Test with token string. | ||
$revoke = new Google_AccessToken_Revoke($http->reveal()); | ||
$t = $accessToken; | ||
$this->assertTrue($revoke->revokeToken($t)); | ||
$this->assertEquals($accessToken, $token); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a PHPUnit version that already has the namespaced
TestCase
class alias.