From ee5defdf735360bc14ff7c36342b65e5f4f400bc Mon Sep 17 00:00:00 2001 From: nabim777 Date: Fri, 3 Jan 2025 09:54:14 +0545 Subject: [PATCH] review addresses Signed-off-by: nabim777 --- .../{TusClientWrapper.php => TusClient.php} | 55 +++---------------- tests/acceptance/bootstrap/TUSContext.php | 4 +- .../apiSpacesShares/shareUploadTUS.feature | 2 + 3 files changed, 13 insertions(+), 48 deletions(-) rename tests/acceptance/TestHelpers/{TusClientWrapper.php => TusClient.php} (65%) diff --git a/tests/acceptance/TestHelpers/TusClientWrapper.php b/tests/acceptance/TestHelpers/TusClient.php similarity index 65% rename from tests/acceptance/TestHelpers/TusClientWrapper.php rename to tests/acceptance/TestHelpers/TusClient.php index 21e95994a28..8b3149fa940 100644 --- a/tests/acceptance/TestHelpers/TusClientWrapper.php +++ b/tests/acceptance/TestHelpers/TusClient.php @@ -23,54 +23,17 @@ namespace TestHelpers; use Carbon\Carbon; +use GuzzleHttp\Exception\GuzzleException; use TusPhp\Exception\FileException; -use GuzzleHttp\Exception\ClientException; use Psr\Http\Message\ResponseInterface; -use GuzzleHttp\Exception\GuzzleException; use Symfony\Component\HttpFoundation\Response as HttpResponse; -use ReflectionException; use TusPhp\Tus\Client; /** - * A helper class where TUS is wrapped and done API requests + * A TUS client based on TusPhp\Tus\Client */ -class TusClientWrapper extends Client { - public $client; - - /** - * Constructor for the TusClientWrapper. - * - * @param string $baseUri - * @param array $options - * - * @throws ReflectionException - */ - public function __construct(string $baseUri, array $options = []) { - parent::__construct($baseUri, $options); - $this->client = new Client($baseUri, $options); - } - - /** - * @param string $key - * - * @return self - */ - public function setKey(string $key): self { - $this->client->setKey($key); - return $this; - } - - /** - * @param string $file - * @param string|null $name - * - * @return self - */ - public function file(string $file, string $name = null): self { - $this->client->file($file, $name); - return $this; - } +class TusClient extends Client { /** * @param string $key @@ -82,15 +45,15 @@ public function file(string $file, string $name = null): self { public function createUploadWithResponse(string $key, int $bytes = -1): ResponseInterface { $bytes = $bytes < 0 ? $this->fileSize : $bytes; $headers = $this->headers + [ - 'Upload-Length' => $this->client->fileSize, + 'Upload-Length' => $this->fileSize, 'Upload-Key' => $key, - 'Upload-Checksum' => $this->client->getUploadChecksumHeader(), - 'Upload-Metadata' => $this->client->getUploadMetadataHeader(), + 'Upload-Checksum' => $this->getUploadChecksumHeader(), + 'Upload-Metadata' => $this->getUploadMetadataHeader(), ]; $data = ''; if ($bytes > 0) { - $data = $this->client->getData(0, $bytes); + $data = $this->getData(0, $bytes); $headers += [ 'Content-Type' => self::HEADER_CONTENT_TYPE, @@ -103,7 +66,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response } try { - $response = $this->client->getClient()->post( + $response = $this->getClient()->post( $this->apiPath, [ 'body' => $data, @@ -123,7 +86,7 @@ public function createUploadWithResponse(string $key, int $bytes = -1): Response $uploadLocation = current($response->getHeader('location')); $this->getCache()->set( - $this->client->getKey(), + $this->getKey(), [ 'location' => $uploadLocation, 'expires_at' => Carbon::now()->addSeconds($this->getCache()->getTtl())->format($this->getCache()::RFC_7231), diff --git a/tests/acceptance/bootstrap/TUSContext.php b/tests/acceptance/bootstrap/TUSContext.php index 148b0649b84..0c0a3e0abdb 100644 --- a/tests/acceptance/bootstrap/TUSContext.php +++ b/tests/acceptance/bootstrap/TUSContext.php @@ -32,7 +32,7 @@ use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; use TestHelpers\BehatHelper; -use TestHelpers\TusClientWrapper; +use TestHelpers\TusClient; require_once 'bootstrap.php'; @@ -371,7 +371,7 @@ public function publicUploadFileUsingTus( $sourceFile = $this->featureContext->acceptanceTestsDirLocation() . $source; $url = WebdavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $token, "public-files"); - $tusWrapper = new TusClientWrapper( + $tusWrapper = new TusClient( $this->featureContext->getBaseUrl(), [ 'verify' => false, diff --git a/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature b/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature index eeb790f5a45..08a8a8f0ac5 100644 --- a/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature +++ b/tests/acceptance/features/apiSpacesShares/shareUploadTUS.feature @@ -413,6 +413,7 @@ Feature: upload resources on share using TUS protocol | permissionsRole | createOnly | | password | %public% | When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API + Then the HTTP status code should be "201" And for user "Alice" folder "uploadFolder" of the space "Personal" should contain these files: | textfile.txt | And for user "Alice" folder "uploadFolder" of the space "Personal" should not contain these files: @@ -431,6 +432,7 @@ Feature: upload resources on share using TUS protocol | permissionsRole | createOnly | | password | %public% | When the public uploads file "filesForUpload/zerobyte.txt" to "textfile.txt" via TUS inside last link shared folder with password "%public%" using the WebDAV API + Then the HTTP status code should be "201" And for user "Alice" folder "uploadFolder" of the space "Project" should contain these files: | textfile.txt | And for user "Alice" folder "uploadFolder" of the space "Project" should not contain these files: