Skip to content
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

feat: remove guzzle 5 #2346

Closed
wants to merge 1 commit into from
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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"license": "Apache-2.0",
"require": {
"php": "^5.6|^7.0|^8.0",
"google/auth": "^1.10",
"google/auth": "^1.19",
"google/apiclient-services": "~0.200",
"firebase/php-jwt": "~2.0||~3.0||~4.0||~5.0||~6.0",
"monolog/monolog": "^1.17||^2.0||^3.0",
"phpseclib/phpseclib": "~2.0||^3.0.2",
"guzzlehttp/guzzle": "~5.3.3||~6.0||~7.0",
"guzzlehttp/guzzle": "~6.0||~7.0",
"guzzlehttp/psr7": "^1.8.4||^2.2.1"
},
"require-dev": {
Expand All @@ -21,7 +21,6 @@
"symfony/css-selector": "~2.1",
"cache/filesystem-adapter": "^0.3.2|^1.1",
"phpcompatibility/php-compatibility": "^9.2",
"composer/composer": "^1.10.22",
"yoast/phpunit-polyfills": "^1.0",
"phpspec/prophecy-phpunit": "^1.1||^2.0",
"phpunit/phpunit": "^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
Expand Down
3 changes: 0 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,3 @@ parameters:
level: 5
paths:
- src
excludePaths:
- src/AuthHandler/Guzzle5AuthHandler.php

4 changes: 1 addition & 3 deletions src/AuthHandler/AuthHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AuthHandlerFactory
/**
* Builds out a default http handler for the installed version of guzzle.
*
* @return Guzzle5AuthHandler|Guzzle6AuthHandler|Guzzle7AuthHandler
* @return Guzzle6AuthHandler|Guzzle7AuthHandler
* @throws Exception
*/
public static function build($cache = null, array $cacheConfig = [])
Expand All @@ -39,8 +39,6 @@ public static function build($cache = null, array $cacheConfig = [])
}

switch ($guzzleVersion) {
case 5:
return new Guzzle5AuthHandler($cache, $cacheConfig);
case 6:
return new Guzzle6AuthHandler($cache, $cacheConfig);
case 7:
Expand Down
108 changes: 0 additions & 108 deletions src/AuthHandler/Guzzle5AuthHandler.php

This file was deleted.

4 changes: 0 additions & 4 deletions src/aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
'Google\\Utils\\UriTemplate' => 'Google_Utils_UriTemplate',
'Google\\AuthHandler\\Guzzle6AuthHandler' => 'Google_AuthHandler_Guzzle6AuthHandler',
'Google\\AuthHandler\\Guzzle7AuthHandler' => 'Google_AuthHandler_Guzzle7AuthHandler',
'Google\\AuthHandler\\Guzzle5AuthHandler' => 'Google_AuthHandler_Guzzle5AuthHandler',
'Google\\AuthHandler\\AuthHandlerFactory' => 'Google_AuthHandler_AuthHandlerFactory',
'Google\\Http\\Batch' => 'Google_Http_Batch',
'Google\\Http\\MediaFileUpload' => 'Google_Http_MediaFileUpload',
Expand Down Expand Up @@ -52,9 +51,6 @@ class Google_AccessToken_Verify extends \Google\AccessToken\Verify
class Google_AuthHandler_AuthHandlerFactory extends \Google\AuthHandler\AuthHandlerFactory
{
}
class Google_AuthHandler_Guzzle5AuthHandler extends \Google\AuthHandler\Guzzle5AuthHandler
{
}
class Google_AuthHandler_Guzzle6AuthHandler extends \Google\AuthHandler\Guzzle6AuthHandler
{
}
Expand Down
70 changes: 0 additions & 70 deletions tests/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ private function createClient()
$options['verify'] = false;
}

// adjust constructor depending on guzzle version
if ($this->isGuzzle5()) {
$options = ['defaults' => $options];
}

$httpClient = new GuzzleClient($options);

$client = new Client();
Expand Down Expand Up @@ -220,75 +215,10 @@ protected function loadExample($example)
return false;
}

protected function isGuzzle7()
{
if (!defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
return false;
}

return (7 === ClientInterface::MAJOR_VERSION);
}

protected function isGuzzle6()
{
if (!defined('\GuzzleHttp\ClientInterface::VERSION')) {
return false;
}
$version = ClientInterface::VERSION;

return ('6' === $version[0]);
}

protected function isGuzzle5()
{
if (!defined('\GuzzleHttp\ClientInterface::VERSION')) {
return false;
}

$version = ClientInterface::VERSION;

return ('5' === $version[0]);
}

public function onlyGuzzle6()
{
if (!$this->isGuzzle6()) {
$this->markTestSkipped('Guzzle 6 only');
}
}

public function onlyPhp55AndAbove()
{
if (version_compare(PHP_VERSION, '5.5', '<')) {
$this->markTestSkipped('PHP 5.5 and above only');
}
}

public function onlyGuzzle5()
{
if (!$this->isGuzzle5()) {
$this->markTestSkipped('Guzzle 5 only');
}
}

public function onlyGuzzle6Or7()
{
if (!$this->isGuzzle6() && !$this->isGuzzle7()) {
$this->markTestSkipped('Guzzle 6 or 7 only');
}
}

protected function getGuzzle5ResponseMock()
{
$response = $this->prophesize('GuzzleHttp\Message\ResponseInterface');
$response->getStatusCode()
->willReturn(200);

$response->getHeaders()->willReturn([]);
$response->getBody()->willReturn('');
$response->getProtocolVersion()->willReturn('');
$response->getReasonPhrase()->willReturn('');

return $response;
}
}
81 changes: 1 addition & 80 deletions tests/Google/AccessToken/RevokeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,87 +27,8 @@

class RevokeTest extends BaseTest
{
public function testRevokeAccessGuzzle5()
public function testRevokeAccess()
{
$this->onlyGuzzle5();

$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 Revoke($http->reveal());
$this->assertTrue($revoke->revokeToken($t));
$this->assertEquals($accessToken, $token);

// Test with refresh token.
$revoke = new 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 Revoke($http->reveal());
$t = $accessToken;
$this->assertTrue($revoke->revokeToken($t));
$this->assertEquals($accessToken, $token);
}

public function testRevokeAccessGuzzle6Or7()
{
$this->onlyGuzzle6Or7();

$accessToken = 'ACCESS_TOKEN';
$refreshToken = 'REFRESH_TOKEN';
$token = '';
Expand Down
Loading