diff --git a/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php b/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php index 5ce6292..81810d4 100644 --- a/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php +++ b/src/Libraries/Storage/Adapters/Dropbox/DropboxApp.php @@ -96,17 +96,17 @@ class DropboxApp /** * @var string */ - private $appKey = null; + private $appKey; /** * @var string */ - private $appSecret = null; + private $appSecret; /** * @var TokenServiceInterface */ - private $tokenService = null; + private $tokenService; /** * DropboxApp constructor @@ -125,8 +125,11 @@ public function __construct(string $appKey, string $appSecret, TokenServiceInter /** * Gets the auth URL - * @throws CryptorException + * @param string $redirectUrl + * @param string $tokenAccessType + * @return string * @throws AppException + * @throws CryptorException * @throws DatabaseException */ public function getAuthUrl(string $redirectUrl, string $tokenAccessType = 'offline'): string diff --git a/src/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php b/src/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php index dbd61b4..0bbdc9f 100644 --- a/src/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php +++ b/src/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapter.php @@ -59,7 +59,7 @@ public static function getInstance(DropboxApp $dropboxApp): DropboxFileSystemAda /** * @inheritDoc */ - public function makeDirectory(string $dirname): bool + public function makeDirectory(string $dirname, ?string $parentId = null): bool { try { $this->dropboxApp->rpcRequest(DropboxApp::ENDPOINT_CREATE_FOLDER, $this->dropboxApp->path($dirname)); @@ -97,7 +97,7 @@ public function get(string $filename) /** * @inheritDoc */ - public function put(string $filename, string $content) + public function put(string $filename, string $content, ?string $parentId = null) { try { $response = $this->dropboxApp->contentRequest(DropboxApp::ENDPOINT_UPLOAD_FILE, diff --git a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php new file mode 100644 index 0000000..57a8448 --- /dev/null +++ b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveApp.php @@ -0,0 +1,251 @@ +appKey = $appKey; + $this->appSecret = $appSecret; + $this->tokenService = $tokenService; + $this->httpClient = $httpClient; + } + + /** + * Gets Auth URL + * @param string $redirectUrl + * @param string $accessType + * @return string + * @throws AppException + * @throws CryptorException + * @throws DatabaseException + */ + public function getAuthUrl(string $redirectUrl, string $accessType = "offline"): string + { + $params = [ + 'client_id' => $this->appKey, + 'response_type' => 'code', + 'state' => csrf_token(), + 'scope' => self::AUTH_SCOPE, + 'redirect_uri' => $redirectUrl, + 'access_type' => $accessType, + ]; + + return self::AUTH_URL . '?' . http_build_query($params, '', '&'); + } + + /** + * Fetch tokens + * @param string $code + * @param string $redirectUrl + * @param bool $byRefresh + * @return object|null + * @throws Exception + */ + public function fetchTokens(string $code, string $redirectUrl = ''): ?object + { + + $params = [ + 'code' => $code, + 'grant_type' => 'authorization_code', + 'client_id' => $this->appKey, + 'client_secret' => $this->appSecret, + 'redirect_uri' => $redirectUrl + ]; + + $response = $this->sendRequest(self::AUTH_TOKEN_URL, $params); + + $this->tokenService->saveTokens($response->access_token, $response->refresh_token); + + return $response; + } + + /** + * Fetches the access token by refresh token + * @param string $refreshToken + * @return string + * @throws Exception + */ + private function fetchAccessTokenByRefreshToken(string $refreshToken): string + { + $params = [ + 'refresh_token' => $refreshToken, + 'grant_type' => 'refresh_token', + 'client_id' => $this->appKey, + 'client_secret' => $this->appSecret + ]; + + $response = $this->sendRequest(self::AUTH_TOKEN_URL, $params); + + $this->tokenService->saveTokens($response->access_token); + + return $response->access_token; + } + + /** + * Sends rpc request + * @param string $uri + * @param mixed|null $data + * @param array $headers + * @param string $method + * @return mixed|null + * @throws Exception + */ + public function sendRequest(string $uri, $data = null, array $headers = [], string $method = 'POST') + { + $this->httpClient + ->createRequest($uri) + ->setMethod($method) + ->setData($data) + ->setHeaders($headers) + ->start(); + + $responseBody = $this->httpClient->getResponseBody(); + + if ($errors = $this->httpClient->getErrors()) { + $code = $errors['code']; + + if ($this->accessTokenNeedsRefresh($code)) { + $prevUrl = $this->httpClient->url(); + $prevData = $this->httpClient->getData(); + $prevHeaders = $this->httpClient->getRequestHeaders(); + + $refreshToken = $this->tokenService->getRefreshToken(); + + $accessToken = $this->fetchAccessTokenByRefreshToken($refreshToken); + + $prevHeaders['Authorization'] = 'Bearer ' . $accessToken; + + $responseBody = $this->sendRequest($prevUrl, $prevData, $prevHeaders); + + } else { + throw new Exception(json_encode($responseBody ?? $errors), E_ERROR); + } + } + + return $responseBody; + } + + /** + * Sends rpc request + * @param string $url + * @param mixed $params + * @param string $method + * @param string $contentType + * @return mixed|null + * @throws Exception + */ + public function rpcRequest(string $url, $params = [], string $method = 'POST', string $contentType = 'application/json') + { + try { + $headers = [ + 'Authorization' => 'Bearer ' . $this->tokenService->getAccessToken(), + 'Content-Type' => $contentType + ]; + return $this->sendRequest($url, $params, $headers, $method); + }catch (Exception $e){ + throw new Exception($e->getMessage(), (int)$e->getCode()); + } + } + + /** + * Gets file information + * @param string $fileId + * @param bool $media + * @param array $params + * @return mixed|null + * @throws Exception + */ + public function getFileInfo(string $fileId, bool $media = false, array $params = []){ + $queryParam = $media ? '?alt=media' : '?fields=*'; + return $this->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $fileId . $queryParam, $params, 'GET'); + } + + /** + * Checks if the access token need refresh + * @param int $code + * @return bool + */ + private function accessTokenNeedsRefresh(int $code): bool + { + if ($code != 401) { + return false; + } + + return true; + } +} \ No newline at end of file diff --git a/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php new file mode 100644 index 0000000..6d82efb --- /dev/null +++ b/src/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapter.php @@ -0,0 +1,243 @@ +googleDriveApp = $googleDriveApp; + } + + /** + * Get Instance + * @param GoogleDriveApp $googleDriveApp + * @return GoogleDriveFileSystemAdapter + */ + public static function getInstance(GoogleDriveApp $googleDriveApp): GoogleDriveFileSystemAdapter + { + if (self::$instance === null) { + self::$instance = new self($googleDriveApp); + } + + return self::$instance; + } + + /** + * @inheritDoc + */ + public function makeDirectory(string $dirname, ?string $parentId = null): bool + { + try{ + $data = [ + 'name' => $dirname, + 'mimeType' => GoogleDriveApp::FOLDER_MIMETYPE, + 'parents' => $parentId ? [$parentId] : ['root'] + ]; + + $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL, $data); + return true; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function removeDirectory(string $dirname): bool + { + return $this->remove($dirname); + } + + /** + * @inheritDoc + */ + public function get(string $filename) + { + try { + return (string)$this->googleDriveApp->getFileInfo($filename, true); + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function put(string $filename, string $content, ?string $parentId = null) + { + try { + if($this->isFile($filename)){ + return $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_MEDIA_URL . '/' . $filename . '?uploadType=media', $content, 'PATCH', 'application/octet-stream'); + }else{ + $data = [ + 'name' => $filename, + 'parents' => $parentId ? [$parentId] : ['root'] + ]; + + $newFile = $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL, $data); + + return $this->put($newFile->id, $content); + } + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function append(string $filename, string $content) + { + $fileContent = $this->get($filename); + + return $this->put($filename, $fileContent . $content); + } + + /** + * @inheritDoc + */ + public function rename(string $oldName, string $newName): bool + { + try { + $data = [ + 'name' => $newName + ]; + + $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $oldName, $data, 'PATCH'); + return true; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function copy(string $source, string $dest = 'root'): bool + { + try { + $data = [ + 'parents' => [$dest] + ]; + + $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $source . '/copy', $data); + return true; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function exists(string $filename): bool + { + return $this->isFile($filename); + } + + /** + * @inheritDoc + */ + public function size(string $filename) + { + try { + $meta = (array)$this->googleDriveApp->getFileInfo($filename); + return $meta['size']; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function lastModified(string $filename) + { + try { + $meta = (array)$this->googleDriveApp->getFileInfo($filename); + return !empty($meta['modifiedTime']) ? strtotime($meta['modifiedTime']) : false; + } catch (Exception $e) { + return false; + } + + } + + /** + * @inheritDoc + */ + public function remove(string $filename): bool + { + try { + $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $filename, [], 'DELETE'); + return true; + } catch (Exception $e) { + return false; + } + + } + + /** + * @inheritDoc + */ + public function isFile(string $filename): bool + { + try { + $meta = (array)$this->googleDriveApp->getFileInfo($filename); + + return $meta['kind'] === GoogleDriveApp::DRIVE_FILE_KIND && $meta['mimeType'] != GoogleDriveApp::FOLDER_MIMETYPE; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function isDirectory(string $dirname): bool + { + try { + $meta = (array)$this->googleDriveApp->getFileInfo($dirname); + + return $meta['kind'] === GoogleDriveApp::DRIVE_FILE_KIND && $meta['mimeType'] === GoogleDriveApp::FOLDER_MIMETYPE; + } catch (Exception $e) { + return false; + } + } + + /** + * @inheritDoc + */ + public function listDirectory(string $dirname) + { + try { + $params = [ + 'q' => "'$dirname' in parents and trashed = false", + 'fields' => '*' + ]; + $response = (array)$this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '?' . http_build_query($params), [], 'GET'); + return $response["files"]; + } catch (Exception $e) { + return false; + } + } +} \ No newline at end of file diff --git a/src/Libraries/Storage/Adapters/GoogleDrive/TokenServiceInterface.php b/src/Libraries/Storage/Adapters/GoogleDrive/TokenServiceInterface.php new file mode 100644 index 0000000..b4fe71c --- /dev/null +++ b/src/Libraries/Storage/Adapters/GoogleDrive/TokenServiceInterface.php @@ -0,0 +1,14 @@ + "sl.BYEQ1_VadTz6nBU36WPBBVwokc3zWVMXGjcOKxV4Tadms8ZlEPM85aHVFa_k1sfjilCWOnl79RUncPZzJ3GhrqhLGIBFFRCH0rKMa_ZtcqkerJn-f5lu10Ki5PSw4fxYM80V4PL_", "token_type" => "bearer", @@ -33,6 +50,9 @@ class DropboxAppTest extends AppTestCase "account_id" => "dbid:AAC9tDKbzTQlyNms0ZcB_iH3wLv7yNn-iyE" ]; + /** + * @var array + */ private $profileDataResponse = [ "account_id" => "dbid:AAH4f99T0taONIb-OurWxbNQ6ywGRopQngc", "disabled" => false, @@ -49,6 +69,9 @@ class DropboxAppTest extends AppTestCase "profile_photo_url" => "https://dl-web.dropbox.com/account_photo/get/69330102&size=128x128" ]; + /** + * @var array + */ private $errorResponse = [ "error" => [ ".tag" => "no_account" @@ -56,6 +79,9 @@ class DropboxAppTest extends AppTestCase "error_summary" => "no_account/..." ]; + /** + * @var string + */ private $fileContentResponse = 'Some plain text!'; public function setUp(): void diff --git a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php index 3eb2fb4..0245744 100644 --- a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php +++ b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxFileSystemAdapterTest.php @@ -9,10 +9,30 @@ class DropboxFileSystemAdapterTest extends AppTestCase { + + /** + * @var DropboxFileSystemAdapter + */ private $fs; + + /** + * @var string + */ private $dirname = 'common'; + + /** + * @var string + */ private $filename = 'sample.txt'; + + /** + * @var string + */ private $content = 'This file was created via dropbox api'; + + /** + * @var array + */ private static $response = []; public function setUp(): void diff --git a/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxTokenServiceTestCase.php b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxTokenServiceTestCase.php new file mode 100644 index 0000000..7bad2e8 --- /dev/null +++ b/tests/unit/Libraries/Storage/Adapters/Dropbox/DropboxTokenServiceTestCase.php @@ -0,0 +1,28 @@ +shouldReceive('getRefreshToken')->andReturnUsing(function () { + $this->currentResponse = (object)$this->tokensGrantResponse; + return 'ref_tok_1234'; + }); + + $tokenServiceMock->shouldReceive('getAccessToken')->andReturn('acc_tok_1234'); + + $tokenServiceMock->shouldReceive('saveTokens')->andReturnUsing(function ($tokens) { + $this->currentResponse = (object)$this->profileDataResponse; + return true; + }); + + return $tokenServiceMock; + } +} \ No newline at end of file diff --git a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php new file mode 100644 index 0000000..63fde36 --- /dev/null +++ b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveAppTest.php @@ -0,0 +1,147 @@ + "sl.BYEQ1_VadTz6nBU36WPBBVwokc3zWVMXGjcOKxV4Tadms8ZlEPM85aHVFa_k1sfjilCWOnl79RUncPZzJ3GhrqhLGIBFFRCH0rKMa_ZtcqkerJn-f5lu10Ki5PSw4fxYM80V4PL_", + "refresh_token" => "-3S067m3M5kAAAAAAAAAAcQF8zVqFUuhK-PFkFqiOfFTgiazWj5NyU-1EGWIh0ZS" + ]; + + /** + * @var array + */ + private $fileMetadataResponse = [ + "id" => "file1", + "kind" => GoogleDriveApp::DRIVE_FILE_KIND, + "name" => "myFile", + "mimeType" => "text/plain" + ]; + + /** + * @var string + */ + private $fileContentResponse = 'Some plain text!'; + + /** + * @var string + */ + private $errorResponse = [ + 'code' => GoogleDriveApp::INVALID_TOKEN_ERROR_CODE, + 'message' => 'Invalid access token', + ]; + + public function setUp(): void + { + parent::setUp(); + + $tokenServiceMock = $this->mockTokenService(); + + $httpClientMock = $this->mockHttpClient(); + + $this->googleDriveApp = new GoogleDriveApp($this->appKey, $this->appSecret, $tokenServiceMock, $httpClientMock); + } + + public function testGoogleDriveGetAuthUrl() + { + $authUrl = $this->googleDriveApp->getAuthUrl($this->redirectUrl); + + $this->assertIsString($authUrl); + + $this->assertStringContainsString('client_id', $authUrl); + + $this->assertStringContainsString('access_type', $authUrl); + } + + public function testGoogleDriveFetchTokens() + { + $this->currentResponse = (object)$this->tokensGrantResponse; + + $response = $this->googleDriveApp->fetchTokens($this->authCode, $this->redirectUrl); + + $this->assertIsObject($response); + + $this->assertTrue(property_exists($response, 'access_token')); + + $this->assertTrue(property_exists($response, 'refresh_token')); + } + + public function testGoogleDriveRpcRequest() + { + $this->currentResponse = (object)$this->fileMetadataResponse; + + $response = $this->googleDriveApp->rpcRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $this->fileMetadataResponse['id']); + + $this->assertIsObject($response); + + $this->assertTrue(property_exists($response, 'id')); + + $this->assertTrue(property_exists($response, 'kind')); + + $this->assertTrue(property_exists($response, 'name')); + + $this->assertTrue(property_exists($response, 'mimeType')); + } + + public function testGoogleDriveGetFileInfo() + { + $this->currentResponse = $this->fileContentResponse; + + $response = $this->googleDriveApp->getFileInfo($this->fileMetadataResponse['id'], true); + + $this->assertIsString($response); + + $this->assertEquals('Some plain text!', $response); + } + + public function testGoogleDriveRequestWithAccessTokenExpired() + { + $this->currentErrors = ["code" => 401]; + + $this->currentResponse = (object)$this->errorResponse; + + $response = $this->googleDriveApp->sendRequest(GoogleDriveApp::FILE_METADATA_URL . '/' . $this->fileMetadataResponse['id']); + + $this->assertIsObject($response); + + $this->assertEquals((object)$this->fileMetadataResponse, $response); + } + +} diff --git a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php new file mode 100644 index 0000000..0c6f905 --- /dev/null +++ b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveFileSystemAdapterTest.php @@ -0,0 +1,220 @@ +makePartial(); + + $googleDrive->shouldReceive('rpcRequest')->andReturnUsing(function ($endpoint, $params) { + if(str_contains($endpoint, '?alt=media')){ + return self::$response[array_key_last(self::$response)]; + } + self::$response = array_merge(self::$response, (array)$params); + return (object)self::$response; + }); + + $this->fs = GoogleDriveFileSystemAdapter::getInstance($googleDrive); + } + + public function tearDown(): void + { + self::$response = []; + } + + public function testGoogleDriveMakeCheckRemoveDirectory() + { + $this->assertFalse($this->fs->isDirectory($this->dirname)); + + self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; + + $this->fs->makeDirectory($this->dirname); + + $this->assertTrue($this->fs->isDirectory($this->dirname)); + + $this->fs->removeDirectory($this->dirname); + + self::$response = []; + + $this->assertFalse($this->fs->isDirectory($this->dirname)); + } + + public function testGoogleDriveCreateGetCheckRemoveFile() + { + $this->assertFalse($this->fs->isFile($this->filename)); + + self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; + self::$response['mimeType'] = 'text/plain'; + + $this->fs->put($this->filename, $this->content); + + $this->assertTrue($this->fs->isFile($this->filename)); + + $this->assertTrue($this->fs->exists($this->filename)); + + $this->assertEquals($this->content, $this->fs->get($this->filename)); + + $this->fs->remove($this->filename); + + self::$response = []; + + $this->assertFalse($this->fs->exists($this->filename)); + } + + public function testGoogleDriveFileAppend() + { + self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; + self::$response['mimeType'] = 'text/plain'; + + $this->fs->put($this->filename, $this->content); + + $this->assertTrue($this->fs->exists($this->filename)); + + $moreContent = 'The sun is shining'; + + $this->fs->append($this->filename, $moreContent); + + $this->assertEquals($this->content . $moreContent, $this->fs->get($this->filename)); + } + + public function testGoogleDriveFileRename() + { + $this->fs->put($this->filename, $this->content); + + $this->assertFalse($this->fs->exists($this->newFilename)); + + self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; + self::$response['mimeType'] = 'text/plain'; + + $this->fs->rename($this->filename, $this->newFilename); + + $this->assertTrue($this->fs->exists($this->newFilename)); + + $this->fs->remove($this->newFilename); + } + + public function testGoogleDriveFileCopy() + { + $this->fs->makeDirectory($this->dirname); + + $this->fs->put($this->filename, $this->content); + + $this->assertFalse($this->fs->exists($this->dirname . '/' . $this->filename)); + + self::$response['kind'] = GoogleDriveApp::DRIVE_FILE_KIND; + self::$response['mimeType'] = 'text/plain'; + + $this->fs->copy($this->filename, $this->dirname . '/' . $this->filename); + + $this->assertTrue($this->fs->exists($this->dirname . '/' . $this->filename)); + + $this->fs->remove($this->dirname . '/' . $this->filename); + + $this->fs->removeDirectory($this->dirname); + } + + public function testGoogleDriveFileSize() + { + $text = 'some bytes'; + + $this->fs->put($this->filename, $text); + + self::$response['size'] = strlen($text); + + $this->assertEquals(10, $this->fs->size($this->filename)); + } + + public function testGoogleDriveFileLastModified() + { + $modified = '2023-02-12T15:50:38Z'; + + $this->fs->put($this->filename, $this->content); + + self::$response['modifiedTime'] = $modified; + + $this->assertIsInt($this->fs->lastModified($this->filename)); + + $this->assertEquals(strtotime($modified), $this->fs->lastModified($this->filename)); + } + + public function testGoogleDriveListDirectory() + { + self::$response['files'] = [ + [ + "kind" => GoogleDriveApp::DRIVE_FILE_KIND, + "mimeType" => 'application/vnd.google-apps.folder', + "name" => "empty", + "id" => "SziOaBdnr3oAAAAAAAAAWQ", + ], + [ + "kind" => GoogleDriveApp::DRIVE_FILE_KIND, + "mimeType" => 'image/png', + "name" => "logo.png", + "id" => "SziOaBdnr3oAAAAAAAAAVQ", + "modifiedTime" => "2023-02-24T15:34:44Z", + "size" => 3455, + ], + [ + "kind" => GoogleDriveApp::DRIVE_FILE_KIND, + "mimeType" => 'image/jpeg', + "name" => "Image 19.jpg", + "id" => "SziOaBdnr3oAAAAAAAAAVw", + "modifiedTime" => "2023-03-01T17:12:58Z", + "size" => 2083432, + ] + ]; + + $entries = $this->fs->listDirectory('test'); + + $this->assertIsArray($entries); + + $this->assertIsArray(current($entries)); + + self::$response = []; + + $this->assertFalse($this->fs->listDirectory('test')); + + } + +} + diff --git a/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveTokenServiceTestCase.php b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveTokenServiceTestCase.php new file mode 100644 index 0000000..8710725 --- /dev/null +++ b/tests/unit/Libraries/Storage/Adapters/GoogleDrive/GoogleDriveTokenServiceTestCase.php @@ -0,0 +1,28 @@ +shouldReceive('getRefreshToken')->andReturnUsing(function () { + $this->currentResponse = (object)$this->tokensGrantResponse; + return 'ref_tok_1234'; + }); + + $tokenServiceMock->shouldReceive('getAccessToken')->andReturn('acc_tok_1234'); + + $tokenServiceMock->shouldReceive('saveTokens')->andReturnUsing(function ($tokens) { + $this->currentResponse = (object)$this->fileMetadataResponse; + return true; + }); + + return $tokenServiceMock; + } +} \ No newline at end of file diff --git a/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php b/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php index 367f07a..00aa3ce 100644 --- a/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php +++ b/tests/unit/Libraries/Storage/Adapters/Local/LocalFileSystemAdapterTest.php @@ -8,9 +8,24 @@ class LocalFileSystemAdapterTest extends AppTestCase { + /** + * @var LocalFileSystemAdapter + */ private $fs; + + /** + * @var string + */ private $dirname; + + /** + * @var string + */ private $filename; + + /** + * @var string + */ private $content = 'Hello world'; public function setUp(): void