From 6bcbc39a22bffe3231da05a199cee5c1f5befcb5 Mon Sep 17 00:00:00 2001 From: Pedro Carmo Date: Thu, 23 May 2024 18:03:55 +0100 Subject: [PATCH] Add interfaces to be possible the mock of the client, batch and service --- src/Client.php | 15 ++++--- src/GoogleClientInterface.php | 75 +++++++++++++++++++++++++++++++++++ src/Http/Batch.php | 8 ++-- src/Http/BatchInterface.php | 14 +++++++ src/Service.php | 11 ++--- src/ServiceInterface.php | 10 +++++ 6 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 src/GoogleClientInterface.php create mode 100644 src/Http/BatchInterface.php create mode 100644 src/ServiceInterface.php diff --git a/src/Client.php b/src/Client.php index c7724bd08..c46df16b3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -50,7 +50,7 @@ * The Google API Client * https://github.com/google/google-api-php-client */ -class Client +class Client implements GoogleClientInterface { const LIBVER = "2.12.6"; const USER_AGENT_SUFFIX = "google-api-php-client/"; @@ -65,7 +65,7 @@ class Client private $auth; /** - * @var ClientInterface $http + * @var GoogleClientInterface $http */ private $http; @@ -312,7 +312,7 @@ public function refreshTokenWithAssertion() /** * Fetches a fresh access token with a given assertion token. - * @param ClientInterface $authHttp optional. + * @param GoogleClientInterface $authHttp optional. * @return array access token */ public function fetchAccessTokenWithAssertion(ClientInterface $authHttp = null) @@ -444,9 +444,8 @@ public function createAuthUrl($scope = null, array $queryParams = []) /** * Adds auth listeners to the HTTP client based on the credentials * set in the Google API Client object - * - * @param ClientInterface $http the http client object. - * @return ClientInterface the http client object + * @param GoogleClientInterface $http the http client object. + * @return GoogleClientInterface the http client object */ public function authorize(ClientInterface $http = null) { @@ -1193,7 +1192,7 @@ protected function createDefaultCache() /** * Set the Http Client object - * @param ClientInterface $http + * @param GoogleClientInterface $http */ public function setHttpClient(ClientInterface $http) { @@ -1201,7 +1200,7 @@ public function setHttpClient(ClientInterface $http) } /** - * @return ClientInterface + * @return GoogleClientInterface */ public function getHttpClient() { diff --git a/src/GoogleClientInterface.php b/src/GoogleClientInterface.php new file mode 100644 index 000000000..143180c14 --- /dev/null +++ b/src/GoogleClientInterface.php @@ -0,0 +1,75 @@ +client = $clientOrConfig; } elseif (is_array($clientOrConfig)) { $this->client = new Client($clientOrConfig ?: []); @@ -51,8 +52,8 @@ public function __construct($clientOrConfig = []) } /** - * Return the associated Google\Client class. - * @return \Google\Client + * Return the associated Google\GoogleClientInterface class. + * @return \Google\GoogleClientInterface */ public function getClient() { @@ -62,7 +63,7 @@ public function getClient() /** * Create a new HTTP Batch handler for this service * - * @return Batch + * @return BatchInterface */ public function createBatch() { diff --git a/src/ServiceInterface.php b/src/ServiceInterface.php new file mode 100644 index 000000000..8a3fbb56f --- /dev/null +++ b/src/ServiceInterface.php @@ -0,0 +1,10 @@ +