diff --git a/.env.dist b/.env.dist
index da221f6..1e61d44 100644
--- a/.env.dist
+++ b/.env.dist
@@ -1,5 +1,6 @@
ALLOW_LIVE_DATA_MANIPULATION_ON_TEST_SERVER=0
TEST_SERVER="https://not-set.example.com"
TEST_SERVER_AUTHORIZATION_TOKEN="not_set"
-TEST_LIB_ID="not_set"
-TEST_LIB_PASSWORD="not_set"
+TEST_LIB_UNENCRYPTED_ID="not_set"
+TEST_LIB_ENCRYPTED_ID="not_set"
+TEST_LIB_ENCRYPTED_PASSWORD="not_set"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4af7763..9c50003 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,14 +19,6 @@ before_script:
- mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
- echo "memory_limit = -1" > /usr/local/etc/php/conf.d/test.ini
-test:php-7.2:
- stage: test
- image: php:7.2
- script:
- - bash ./bin/prepare_tests.sh && bash ./bin/run_tests.sh
- tags:
- - sdo-docker-runner
-
test:php-7.3:
stage: test
image: php:7.3
diff --git a/.travis.yml b/.travis.yml
index f399ae5..3277176 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,7 +4,6 @@ language: php
php:
# using major version aliases
- - 7.2
- 7.3
- 7.4
diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index 42e9f25..0000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,33 +0,0 @@
-pipeline {
- agent {
- docker 'composer'
- }
- triggers {
- pollSCM 'H/5 * * * *'
- }
- stages {
- stage('Checkout') {
- steps {
- checkout scm
- }
- }
- stage('Build') {
- steps {
- sh 'rm -rf ./build/{logs,pdepend} 2> /dev/null'
- sh 'mkdir -p ./build/{logs,pdepend}'
- sh 'chmod +x ./bin/*.sh'
- sh 'COMPOSER_HOME=/tmp/.composer ./bin/prepare_tests.sh'
- }
- }
- stage('Run') {
- steps {
- sh './bin/run_tests.sh'
- }
- }
- }
- post {
- always {
- deleteDir() /* clean up our workspace */
- }
- }
-}
\ No newline at end of file
diff --git a/README.md b/README.md
index 71f7bb3..e80f8e0 100644
--- a/README.md
+++ b/README.md
@@ -20,8 +20,7 @@ Get in touch now: https://sdo.sh/DevOps/#contact
## How to get Started
-To get started with Seafile PHP SDK, you may either set up your own private Seafile server (see [https://www.seafile.com/en/product/private_server/](https://www.seafile.com/en/product/private_server/)) or obtain seacloud.cc account
-[https://seacloud.cc](https://seacloud.cc). Because the SDK is in its infancy it's highly recommended to set up a test server or create a test account.
+To get started with Seafile PHP SDK, you may either set up your own private Seafile server (see [https://www.seafile.com/en/product/private_server/](https://www.seafile.com/en/product/private_server/)) or obtain a cloud account. Because the SDK is in its infancy it's highly recommended to set up a test server or create a test account.
It's not advisable yet to use your real server/account if you already got one.
@@ -80,7 +79,7 @@ First, you need to include the API token (see above):
```php
$client = new Client(
[
- 'base_uri' => 'https://your.seafile-server.com',
+ 'base_uri' => 'https://your-seafile-server.example.com',
'debug' => false,
'headers' => [
'Authorization' => 'Token ' . $token
@@ -157,14 +156,14 @@ $success = $libraryResource->decrypt($libId, ['query' => ['password' => $passwor
$fileToUpload = '/path/to/file/to/be/uploaded.zip';
$dir = '/'; // directory in the library to save the file in
$response = $fileResource->upload($lib, $fileToUpload, $dir);
-$uploadedFileId = json_decode((string)$response->getBody());
+$uploadedFileId = (string)$response->getBody();
```
### Update file
```php
$response = $fileResource->update($lib, $newFilename, '/');
-$updatedFileId = json_decode((string)$response->getBody());
+$updatedFileId = (string)$response->getBody();
```
### Get file details
@@ -329,7 +328,7 @@ $stack->push(
$client = new Client(
[
- 'base_uri' => 'https://your.seafile-server.com',
+ 'base_uri' => 'https://your-seafile-server.example.com',
'debug' => true,
'handler' => $stack,
'headers' => [
@@ -341,11 +340,11 @@ $client = new Client(
## Issues
-- Please let me know of issues.
+- `File::upload()`: Parameter `$newFilename` actually does not set a new file name when uploading a file (thanks to https://github.com/FlorientR)
## Dependencies
-- PHP >=7.0 64 bits
+- PHP >=7.3 64 bits
- Guzzle 6
## Seafile Web API Support Matrix
@@ -353,7 +352,7 @@ $client = new Client(
| Resource | Web API Version | Support grade |
| ---------------------- | --------------- | ------------- |
| Account | v2 | ★★★☆ |
-| Avatar | v2 | ★★★★ |
+| Avatar | v2.1 | ★★★★ |
| Events | v2 | Yet to be done, [contact me](mailto:rene+_gth@sdo.sh) |
| File Share Link | v2.1 | ★★★☆ |
| Group | v2 | ★☆☆☆ |
@@ -372,7 +371,7 @@ Tested with:
- ~~Seafile Server 5.1.3 for generic Linux/Debian Wheezy~~
- ~~Seafile Server 5.1.4 for generic Linux/Ubuntu Xenial~~
- ~~Seafile Server 6.0.3 for generic Linux/Ubuntu Xenial~~
-- Seafile Server 6.3.4 for generic Linux/Ubuntu Xenial
+- Seafile Server 7.1.4 for Ubuntu 20.04 LTS
## Contributing
@@ -401,4 +400,4 @@ There are two types of tests:
## License
-[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2017 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG
+[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2020 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG
diff --git a/bin/run_tests.sh b/bin/run_tests.sh
index bea34cd..42949a5 100755
--- a/bin/run_tests.sh
+++ b/bin/run_tests.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# run tests locally or on Jenkins
+# run tests locally or in CI/CD pipeline
mkdir -p ./build/logs
@@ -13,7 +13,14 @@ if [ ! -f $file ] || [ $size -eq 0 ]; then
fi
if [ -f $file ]; then
- ./vendor/bin/phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=./build/phpcs.xml -v ./src ./test --ignore=./test/bootstrap.php --ignore=./test/ui --standard=$file
+ ./vendor/bin/phpcs \
+ --report=checkstyle \
+ --report-file=./build/logs/checkstyle.xml \
+ --standard=./build/phpcs.xml \
+ -v ./src ./test \
+ --ignore=./test/bootstrap.php \
+ --ignore=./test/ui \
+ --standard=$file
fi
./vendor/bin/phpcpd ./src ./test --exclude=./test/ui
diff --git a/composer.json b/composer.json
index acb33e2..3a12663 100644
--- a/composer.json
+++ b/composer.json
@@ -21,8 +21,8 @@
"encrypted"
],
"require": {
- "php": ">=7.2",
- "guzzlehttp/guzzle": "~6.0",
+ "php": ">=7.3",
+ "guzzlehttp/guzzle": "~6.0|~7.0",
"nabil1337/case-helper": "~0.1",
"ext-json": "*",
"sdo/bitmask": "^1.0"
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 6ac0dce..7de4b5d 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
- stopOnFailure="false"
+ stopOnFailure="true"
timeoutForSmallTests="1"
timeoutForMediumTests="3"
timeoutForLargeTests="9"
@@ -20,8 +20,9 @@
-
-
+
+
+
diff --git a/src/Http/Client.php b/src/Http/Client.php
index 8853d24..8f03397 100644
--- a/src/Http/Client.php
+++ b/src/Http/Client.php
@@ -45,9 +45,9 @@ public function __construct(array $config = [])
* @param array $args Request args
* @return ResponseInterface
*/
- public function get($uri, $args): ResponseInterface
+ public function get($uri, array $options = []): ResponseInterface
{
- return parent::get($uri, $args);
+ return parent::get($uri, $options);
}
/**
@@ -55,9 +55,9 @@ public function get($uri, $args): ResponseInterface
* @param array $args Request args
* @return ResponseInterface
*/
- public function put($uri, $args): ResponseInterface
+ public function put($uri, array $options = []): ResponseInterface
{
- return parent::put($uri, $args);
+ return parent::put($uri, $options);
}
/**
@@ -65,8 +65,8 @@ public function put($uri, $args): ResponseInterface
* @param array $args Request args
* @return ResponseInterface
*/
- public function delete($uri, $args): ResponseInterface
+ public function delete($uri, array $options = []): ResponseInterface
{
- return parent::delete($uri, $args);
+ return parent::delete($uri, $options);
}
}
diff --git a/src/Resource/Account.php b/src/Resource/Account.php
index 902ab0a..1a75487 100644
--- a/src/Resource/Account.php
+++ b/src/Resource/Account.php
@@ -18,6 +18,8 @@
*/
class Account extends Resource
{
+ const API_VERSION = '2';
+
/**
* List accounts
*
@@ -28,7 +30,7 @@ class Account extends Resource
*/
public function getAll(): array
{
- $response = $this->client->request('GET', $this->getApiBaseUrl(). '/accounts/');
+ $response = $this->client->request('GET', $this->getApiBaseUrl() . '/accounts/');
$json = json_decode($response->getBody());
@@ -56,7 +58,7 @@ public function getByEmail(string $emailAddress): AccountType
$response = $this->client->request(
'GET',
// $emailAddress must not be urlencoded
- $this->getApiBaseUrl(). '/accounts/' . $emailAddress . '/'
+ $this->getApiBaseUrl() . '/accounts/' . $emailAddress . '/'
);
$json = json_decode($response->getBody());
@@ -76,7 +78,7 @@ public function getInfo(string $emailAddress): TypeInterface
{
$response = $this->client->request(
'GET',
- $this->getApiBaseUrl(). '/accounts/' . $emailAddress . '/'
+ $this->getApiBaseUrl() . '/accounts/' . $emailAddress . '/'
);
$json = json_decode($response->getBody());
@@ -113,7 +115,7 @@ public function create(AccountType $accountType): bool
$response = $this->client->put(
$uri,
[
- 'headers' => ['Accept' => 'application/json; charset=utf-8'],
+ 'headers' => ['Accept' => 'application/json; charset=utf-8'],
'multipart' => $accountType->toArray(Type::ARRAY_MULTI_PART),
]
);
@@ -151,7 +153,7 @@ public function update(AccountType $accountType): bool
$response = $this->client->put(
$uri,
[
- 'headers' => ['Accept' => 'application/json; charset=utf-8'],
+ 'headers' => ['Accept' => 'application/json; charset=utf-8'],
'multipart' => $accountType->toArray(Type::ARRAY_MULTI_PART),
]
);
@@ -165,7 +167,7 @@ public function update(AccountType $accountType): bool
* Requires admin permissions
*
* @param AccountType $fromAccountType AccountType instance to update from
- * @param AccountType $toAccountType AccountType instance to update to
+ * @param AccountType $toAccountType AccountType instance to update to
*
* @return bool
*/
diff --git a/src/Resource/Avatar.php b/src/Resource/Avatar.php
index e244f04..6ac7150 100644
--- a/src/Resource/Avatar.php
+++ b/src/Resource/Avatar.php
@@ -90,7 +90,7 @@ protected function getAvatar(Type $type, int $size)
}
$response = $this->client->get(
- $this->getApiBaseUrl(). '/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/',
+ $this->getApiBaseUrl() . '/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/',
[]
);
diff --git a/src/Resource/Directory.php b/src/Resource/Directory.php
index 942aac3..a15afa9 100644
--- a/src/Resource/Directory.php
+++ b/src/Resource/Directory.php
@@ -18,11 +18,13 @@
*/
class Directory extends Resource
{
+ const API_VERSION = '2';
+
/**
* Get all items of a directory in a library
*
* @param LibraryType $library Library type
- * @param string $dir Directory path
+ * @param string $dir Directory path
*
* @return DirectoryItem[]
* @throws Exception
@@ -61,9 +63,9 @@ public function getAll(LibraryType $library, string $dir = '/')
/**
* Check if $dirName exists within $parentDir
*
- * @param LibraryType $library Library instance
- * @param string $dirItemName DirectoryItem name
- * @param string $parentDir Parent directory
+ * @param LibraryType $library Library instance
+ * @param string $dirItemName DirectoryItem name
+ * @param string $parentDir Parent directory
*
* @return bool
* @throws Exception
@@ -135,10 +137,10 @@ public function create(LibraryType $library, string $dirName, string $parentDir
'POST',
$uri,
[
- 'headers' => ['Accept' => 'application/json'],
+ 'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
- 'name' => 'operation',
+ 'name' => 'operation',
'contents' => 'mkdir',
],
],
@@ -151,8 +153,8 @@ public function create(LibraryType $library, string $dirName, string $parentDir
/**
* Remove a directory
*
- * @param LibraryType $library Library instance
- * @param string $directoryPath Directory path
+ * @param LibraryType $library Library instance
+ * @param string $directoryPath Directory path
*
* @return bool
*/
@@ -184,9 +186,9 @@ public function remove(LibraryType $library, string $directoryPath)
/**
* Rename a directory
*
- * @param LibraryType $library Library object
- * @param string $directoryPath Directory path
- * @param string $newDirectoryName New directory name
+ * @param LibraryType $library Library object
+ * @param string $directoryPath Directory path
+ * @param string $newDirectoryName New directory name
*
* @return bool
*/
@@ -208,14 +210,14 @@ public function rename(LibraryType $library, string $directoryPath, string $newD
'POST',
$uri,
[
- 'headers' => ['Accept' => 'application/json'],
+ 'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
- 'name' => 'operation',
+ 'name' => 'operation',
'contents' => 'rename',
],
[
- 'name' => 'newname',
+ 'name' => 'newname',
'contents' => $newDirectoryName,
],
],
diff --git a/src/Resource/File.php b/src/Resource/File.php
index 1483eb4..92e1fbe 100644
--- a/src/Resource/File.php
+++ b/src/Resource/File.php
@@ -23,6 +23,8 @@
*/
class File extends Resource
{
+ const API_VERSION = '2';
+
/**
* Mode of operation: copy
*/
@@ -95,7 +97,8 @@ public function downloadFromDir(
string $localFilePath,
string $dir,
int $reuse = 1
- ): ResponseInterface {
+ ): ResponseInterface
+ {
if (is_readable($localFilePath)) {
throw new Exception('File already exists');
}
@@ -149,16 +152,18 @@ public function update(LibraryType $library, string $localFilePath, string $dir
*
* @param LibraryType $library Library instance
* @param bool $newFile Is new file (=upload) or not (=update)
+ * @param string $dir Directory to upload to
*
* @return String Upload link
* @throws GuzzleException
*/
- public function getUploadUrl(LibraryType $library, bool $newFile = true)
+ public function getUploadUrl(LibraryType $library, bool $newFile = true, string $dir = "/"): string
{
$url = $this->getApiBaseUrl()
. '/repos/'
. $library->id
- . '/' . ($newFile ? 'upload' : 'update') . '-link/';
+ . '/' . ($newFile ? 'upload' : 'update') . '-link/'
+ . '?p=' . $dir;
$response = $this->client->request('GET', $url);
$uploadLink = (string)$response->getBody();
@@ -247,7 +252,7 @@ public function upload(
return $this->client->request(
'POST',
- $this->getUploadUrl($library, $newFile),
+ $this->getUploadUrl($library, $newFile, $dir),
[
'headers' => ['Accept' => '*/*'],
'multipart' => $this->getMultiPartParams($localFilePath, $dir, $newFile, $newFilename),
@@ -319,7 +324,7 @@ public function remove(LibraryType $library, string $filePath): bool
*
* @param LibraryType $library Library object
* @param DirectoryItem $dirItem Directory item to rename
- * @param string $newFilename New file name
+ * @param string $newFilename New file name; see "Issues" in the readme
*
* @return bool
* @throws GuzzleException
diff --git a/src/Resource/Group.php b/src/Resource/Group.php
index f32f6f4..8f8416a 100644
--- a/src/Resource/Group.php
+++ b/src/Resource/Group.php
@@ -16,6 +16,8 @@
*/
class Group extends Resource
{
+ const API_VERSION = '2';
+
/**
* List groups
*
diff --git a/src/Resource/Library.php b/src/Resource/Library.php
index 666b6c9..892fd4d 100644
--- a/src/Resource/Library.php
+++ b/src/Resource/Library.php
@@ -17,6 +17,8 @@
*/
class Library extends Resource
{
+ const API_VERSION = '2';
+
/**
* List libraries
*
@@ -25,7 +27,7 @@ class Library extends Resource
*/
public function getAll(): array
{
- $response = $this->client->request('GET', $this->getApiBaseUrl(). '/repos/');
+ $response = $this->client->request('GET', $this->getApiBaseUrl() . '/repos/');
$json = json_decode($response->getBody());
@@ -50,7 +52,7 @@ public function getById($libraryId): LibraryType
{
$response = $this->client->request(
'GET',
- $this->getApiBaseUrl(). '/repos/' . $libraryId . '/'
+ $this->getApiBaseUrl() . '/repos/' . $libraryId . '/'
);
$json = json_decode($response->getBody());
@@ -62,7 +64,7 @@ public function getById($libraryId): LibraryType
* Decrypt library
*
* @param string $libraryId Library ID
- * @param array $options Options
+ * @param array $options Options
*
* @return bool Decryption success
*
@@ -79,7 +81,7 @@ public function decrypt($libraryId, array $options): bool
$response = $this->client->request(
'POST',
- $this->getApiBaseUrl(). '/repos/' . $libraryId . '/',
+ $this->getApiBaseUrl() . '/repos/' . $libraryId . '/',
$options
);
@@ -89,7 +91,7 @@ public function decrypt($libraryId, array $options): bool
/**
* Check if library with certain attribute value exists
*
- * @param string $value Library name
+ * @param string $value Library name
* @param string $attribute Attribute name of library
*
* @return bool
@@ -112,9 +114,9 @@ public function exists($value, $attribute = 'name'): bool
/**
* Create a new library
*
- * @param string $name Library name
+ * @param string $name Library name
* @param string $description Library description
- * @param string $password false means no encryption, any other string is used as password
+ * @param string $password false means no encryption, any other string is used as password
*
* @return bool
* @throws Exception
@@ -127,7 +129,7 @@ public function create($name, $description = "new repo", $password = ''): bool
return false;
}
- // Do not create libraries that already exist
+ // Do not create libraries that already exists
if ($this->exists($name)) {
return false;
}
@@ -137,20 +139,20 @@ public function create($name, $description = "new repo", $password = ''): bool
$this->clipUri($this->getApiBaseUrl())
);
- $multipartData = [
+ $multiPartData = [
[
- 'name' => 'name',
+ 'name' => 'name',
'contents' => $name,
],
[
- 'name' => 'desc',
+ 'name' => 'desc',
'contents' => $description,
],
];
if ($password !== '') {
- $multipartData[] = [
- 'name' => 'passwd',
+ $multiPartData[] = [
+ 'name' => 'passwd',
'contents' => $password,
];
}
@@ -159,8 +161,8 @@ public function create($name, $description = "new repo", $password = ''): bool
'POST',
$uri,
[
- 'headers' => ['Accept' => 'application/json'],
- 'multipart' => $multipartData,
+ 'headers' => ['Accept' => 'application/json'],
+ 'multipart' => $multiPartData,
]
);
@@ -202,8 +204,8 @@ public function remove($libraryId): bool
/**
* Share a library, share type is always "personal"
*
- * @param string $libraryId Library ID
- * @param array $users Comma separated list of user email addresses
+ * @param string $libraryId Library ID
+ * @param array $users Comma separated list of user email addresses
* @param string $permission The permission of the shared library
*
* @return bool
diff --git a/src/Resource/Multi.php b/src/Resource/Multi.php
index d3d5f75..c84f1e3 100644
--- a/src/Resource/Multi.php
+++ b/src/Resource/Multi.php
@@ -16,6 +16,8 @@
*/
class Multi extends Resource
{
+ const API_VERSION = '2';
+
/**
* Mode of operation: copy
*/
@@ -29,10 +31,10 @@ class Multi extends Resource
/**
* Move multiple files or folders
*
- * @param LibraryType $srcLibrary Source library object
- * @param array $srcPaths Array with file/folder paths
- * @param LibraryType $dstLibrary Destination library object
- * @param string $dstDirectoryPath Destination directory Path
+ * @param LibraryType $srcLibrary Source library object
+ * @param array $srcPaths Array with file/folder paths
+ * @param LibraryType $dstLibrary Destination library object
+ * @param string $dstDirectoryPath Destination directory Path
*
* @return bool
* @throws GuzzleException
@@ -42,18 +44,19 @@ public function move(
array $srcPaths,
LibraryType $dstLibrary,
string $dstDirectoryPath
- ): bool {
+ ): bool
+ {
return $this->copy($srcLibrary, $srcPaths, $dstLibrary, $dstDirectoryPath, self::OPERATION_MOVE);
}
/**
* Copy multiple files or folders
*
- * @param LibraryType $srcLibrary Source library object
- * @param array $srcPaths Array with file/folder paths (they must be in the same folder)
- * @param LibraryType $dstLibrary Destination library object
- * @param string $dstDirectoryPath Destination directory Path
- * @param int $operation self::OPERATION_COPY or self::OPERATION_MOVE
+ * @param LibraryType $srcLibrary Source library object
+ * @param array $srcPaths Array with file/folder paths (they must be in the same folder)
+ * @param LibraryType $dstLibrary Destination library object
+ * @param string $dstDirectoryPath Destination directory Path
+ * @param int $operation self::OPERATION_COPY or self::OPERATION_MOVE
*
* @return bool
* @throws GuzzleException
@@ -64,7 +67,8 @@ public function copy(
LibraryType $dstLibrary,
string $dstDirectoryPath,
int $operation = self::OPERATION_COPY
- ): bool {
+ ): bool
+ {
// do not allow empty paths
if (empty($srcPaths) || empty($dstDirectoryPath)) {
return false;
@@ -96,18 +100,18 @@ public function copy(
'POST',
$uri,
[
- 'headers' => ['Accept' => 'application/json'],
+ 'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
- 'name' => 'file_names',
+ 'name' => 'file_names',
'contents' => $dstFileNames,
],
[
- 'name' => 'dst_repo',
+ 'name' => 'dst_repo',
'contents' => $dstLibrary->id,
],
[
- 'name' => 'dst_dir',
+ 'name' => 'dst_dir',
'contents' => $dstDirectoryPath,
],
],
@@ -120,8 +124,8 @@ public function copy(
/**
* check source folders paths and build the file_names string
*
- * @param string $folder Folder path
- * @param array $paths Paths of files
+ * @param string $folder Folder path
+ * @param array $paths Paths of files
* @param string $fileNames Optional file names
*
* @return string
@@ -145,7 +149,7 @@ protected function preparePaths(string $folder, array $paths, string $fileNames
* Delete multiple files or folders
*
* @param LibraryType $library Library object
- * @param array $paths Array with file and folder paths (they must be in the same folder)
+ * @param array $paths Array with file and folder paths (they must be in the same folder)
*
* @return bool
* @throws GuzzleException
@@ -180,10 +184,10 @@ public function delete(LibraryType $library, array $paths): bool
'POST',
$uri,
[
- 'headers' => ['Accept' => 'application/json'],
+ 'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
- 'name' => 'file_names',
+ 'name' => 'file_names',
'contents' => $fileNames,
],
],
diff --git a/src/Resource/Resource.php b/src/Resource/Resource.php
index 558c7fa..64ddc29 100644
--- a/src/Resource/Resource.php
+++ b/src/Resource/Resource.php
@@ -15,7 +15,7 @@
*/
abstract class Resource implements ResourceInterface
{
- const API_VERSION = '2';
+ const API_VERSION = '2.1';
/** Represents 'read' permission (in whatever context) */
const PERMISSION_R = 'r';
@@ -45,7 +45,7 @@ public function __construct(Client $client)
*/
public function getApiBaseUrl(): string
{
- return $this->clipUri($this->client->getConfig('base_uri')) . (static::API_VERSION === '2' ? '/api2' : '/api/v2.1');
+ return $this->clipUri($this->client->getConfig('base_uri')) . (static::API_VERSION === '2' ? '/api2' : '/api/v' . static::API_VERSION);
}
/**
diff --git a/src/Resource/ShareLinks.php b/src/Resource/ShareLinks.php
index 662032e..46d4b95 100644
--- a/src/Resource/ShareLinks.php
+++ b/src/Resource/ShareLinks.php
@@ -3,6 +3,8 @@
namespace Seafile\Client\Resource;
use Exception;
+use GuzzleHttp\Exception\GuzzleException;
+use GuzzleHttp\Psr7\Response;
use Seafile\Client\Type\Library as LibraryType;
use Seafile\Client\Type\SharedLink as SharedLinkType;
use Seafile\Client\Type\SharedLinkPermissions;
@@ -18,8 +20,6 @@
*/
class ShareLinks extends Resource implements ResourceInterface
{
- const API_VERSION = '2.1';
-
/**
* List shared links
*
@@ -79,10 +79,11 @@ public function remove(SharedLinkType $sharedLinkType): bool
* @param LibraryType $library Library instance
* @param string $path Path
* @param SharedLinkPermissions $permissions
- * @param int $expire Expire in such many days
- * @param string $password Optional password string
+ * @param int|null $expire Expire in such many days
+ * @param string|null $password Optional password string
*
* @return SharedLinkType|null
+ * @throws GuzzleException
* @throws Exception
*/
public function create(
diff --git a/src/Resource/StarredFile.php b/src/Resource/StarredFile.php
index 5625aa9..972514f 100644
--- a/src/Resource/StarredFile.php
+++ b/src/Resource/StarredFile.php
@@ -21,6 +21,8 @@
*/
class StarredFile extends Resource
{
+ const API_VERSION = '2';
+
/**
* @var string
*/
@@ -63,7 +65,7 @@ public function getAll(): array
/**
* Create directory within $parentDir
*
- * @param LibraryType $library Library instance
+ * @param LibraryType $library Library instance
* @param DirectoryItem $dirItem DirectoryItem instance to star
*
* @return string URL of starred file list
@@ -79,14 +81,14 @@ public function star(LibraryType $library, DirectoryItem $dirItem): string
'POST',
$this->resourceUri,
[
- 'headers' => ['Accept' => 'application/json'],
+ 'headers' => ['Accept' => 'application/json'],
'multipart' => [
[
- 'name' => 'repo_id',
+ 'name' => 'repo_id',
'contents' => $library->id,
],
[
- 'name' => 'p',
+ 'name' => 'p',
'contents' => $dirItem->path,
],
],
diff --git a/src/Type/DirectoryItem.php b/src/Type/DirectoryItem.php
index d2338e2..456eafe 100644
--- a/src/Type/DirectoryItem.php
+++ b/src/Type/DirectoryItem.php
@@ -3,6 +3,7 @@
namespace Seafile\Client\Type;
use DateTime;
+use Exception;
use stdClass;
/**
@@ -71,7 +72,7 @@ class DirectoryItem extends Type
* @param array $fromArray Create from array
*
* @return DirectoryItem
- * @throws \Exception
+ * @throws Exception
*/
public function fromArray(array $fromArray): DirectoryItem
{
diff --git a/src/Type/SharedLink.php b/src/Type/SharedLink.php
index 2e0476d..c8ae61b 100644
--- a/src/Type/SharedLink.php
+++ b/src/Type/SharedLink.php
@@ -35,7 +35,7 @@ class SharedLink extends Type
/**
* Creation time
*
- * @var \DateTime|null
+ * @var DateTime|null
*/
public $ctime = null;
diff --git a/test/assets/Avatar_get.json b/test/assets/Avatar_get.json
index c8944ce..3018e98 100644
--- a/test/assets/Avatar_get.json
+++ b/test/assets/Avatar_get.json
@@ -1 +1,5 @@
-{"url": "https://seafile.example.com/seafmedia/avatars/groups/default.png", "is_default": true, "mtime": 0}
\ No newline at end of file
+{
+ "url": "https://seafile.example.com/seafmedia/avatars/groups/default.png",
+ "is_default": true,
+ "mtime": 0
+}
\ No newline at end of file
diff --git a/test/bootstrap.php b/test/bootstrap.php
index 6a7ad3e..dd80b64 100644
--- a/test/bootstrap.php
+++ b/test/bootstrap.php
@@ -9,8 +9,9 @@
$_ENV['ALLOW_LIVE_DATA_MANIPULATION_ON_TEST_SERVER'] === '1'
&& $_ENV['TEST_SERVER_AUTHORIZATION_TOKEN'] != 'not_set'
&& $_ENV['TEST_SERVER'] != 'https://not-set.example.com'
- && $_ENV['TEST_LIB_ID'] != 'not_set'
- && $_ENV['TEST_LIB_PASSWORD'] != 'not_set'
+ && $_ENV['TEST_LIB_UNENCRYPTED_ID'] != 'not_set'
+ && $_ENV['TEST_LIB_ENCRYPTED_ID'] != 'not_set'
+ && $_ENV['TEST_LIB_ENCRYPTED_PASSWORD'] != 'not_set'
);
$functionalTestsCredentialsValid = false;
$functionalTestsTestLibCleaned = false;
diff --git a/test/functional/FunctionalTestCase.php b/test/functional/FunctionalTestCase.php
index 04a8da2..bb2dcf4 100644
--- a/test/functional/FunctionalTestCase.php
+++ b/test/functional/FunctionalTestCase.php
@@ -13,6 +13,7 @@
use GuzzleHttp\Middleware;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
+use PHPUnit\Framework\TestCase;
use Seafile\Client\Http\Client;
use Seafile\Client\Resource\Library;
use Seafile\Client\Type\Library as LibraryType;
@@ -26,7 +27,7 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/Schmidt-DevOps/seafile-php-sdk
*/
-class FunctionalTestCase extends \PHPUnit\Framework\TestCase
+class FunctionalTestCase extends TestCase
{
/** @var Client|null */
protected $client = null;
@@ -69,6 +70,7 @@ protected function getLogger(): Logger
/**
* @return Client
+ * @throws Exception
*/
protected function getClient(): Client
{
@@ -130,12 +132,23 @@ protected function getFaker(): Generator
protected function getTestLibraryType(): LibraryType
{
if (is_null($this->testLib)) {
- $libId = $_ENV['TEST_LIB_ID'];
+ $libId = $_ENV['TEST_LIB_ENCRYPTED_ID'];
$libraryResource = new Library($this->client);
$this->testLib = $libraryResource->getById($libId);
- if ($this->testLib->encrypted === true && array_key_exists('TEST_LIB_PASSWORD', $_ENV)) {
- self::assertTrue($libraryResource->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_PASSWORD']]]));
+ if ($this->testLib->encrypted === true && array_key_exists('TEST_LIB_ENCRYPTED_PASSWORD', $_ENV)) {
+ self::assertTrue($libraryResource->decrypt(
+ $libId,
+ [
+ 'query' => ['password' => $_ENV['TEST_LIB_ENCRYPTED_PASSWORD']],
+ 'multipart' => [
+ [
+ 'name' => 'password',
+ 'contents' => $_ENV['TEST_LIB_ENCRYPTED_PASSWORD']
+ ]
+ ]
+ ]
+ ));
}
}
diff --git a/test/functional/Resource/AccountTest.php b/test/functional/Resource/AccountTest.php
index 40e61cd..fa99fd5 100644
--- a/test/functional/Resource/AccountTest.php
+++ b/test/functional/Resource/AccountTest.php
@@ -32,7 +32,7 @@ public function setUp(): void
{
parent::setUp();
- $this->emailAddress = 'a' . (string)random_int(0, 1000) . $this->faker->safeEmail;
+ $this->emailAddress = 'seafile_php_sdk_functional_test_' . (string)random_int(0, 1000) . $this->faker->safeEmail;
$this->accountResource = new Account($this->client);
}
diff --git a/test/functional/Resource/FileTest.php b/test/functional/Resource/FileTest.php
index 53c11f4..548b7da 100644
--- a/test/functional/Resource/FileTest.php
+++ b/test/functional/Resource/FileTest.php
@@ -34,7 +34,6 @@ public function setUp(): void
{
parent::setUp();
- $this->libraryResource = new Library($this->client);
$this->fileResource = new File($this->client);
}
@@ -160,11 +159,12 @@ public function testList()
*/
public function testRename()
{
- $libId = $_ENV['TEST_LIB_ID'];
+ $this->libraryResource = $this->getTestLibraryType();
+ $libId = $_ENV['TEST_LIB_ENCRYPTED_ID'];
$lib = $this->getTestLibraryType();
if ($lib->encrypted === true && isset($cfg->testLibPassword)) {
- $success = $this->libraryResource->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_PASSWORD']]]);
+ $success = $this->libraryResource->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_ENCRYPTED_PASSWORD']]]);
self::assertTrue($success);
}
diff --git a/test/functional/Resource/ShareLinksTest.php b/test/functional/Resource/ShareLinksTest.php
index d742e5f..25404cc 100644
--- a/test/functional/Resource/ShareLinksTest.php
+++ b/test/functional/Resource/ShareLinksTest.php
@@ -58,18 +58,12 @@ public function testShareLinks()
$this->logger->debug(sprintf("Name: %s, ID: %s, is encrypted: %s\n", $lib->name, $lib->id, $lib->encrypted ? 'YES' : 'NO'));
}
- $libId = $_ENV['TEST_LIB_ID'];
+ $libId = $_ENV['TEST_LIB_UNENCRYPTED_ID'];
// get specific library
$this->logger->debug("#################### Getting lib with ID " . $libId);
$lib = $libraryResource->getById($libId);
- if ($lib->encrypted) {
- $lib->password = $_ENV['TEST_LIB_PASSWORD']; // library is encrypted and thus we provide a password
- $success = $libraryResource->decrypt($libId, ['query' => ['password' => $_ENV['TEST_LIB_PASSWORD']]]);
- self::assertTrue($success);
- }
-
// upload a Hello World file and random file name (note: this seems not to work at this time when you are not logged into the Seafile web frontend).
$newFilename = $GLOBALS['BUILD_TMP'] . '/Seafile-PHP-SDK_Test_Upload.txt';
@@ -87,9 +81,13 @@ public function testShareLinks()
$expire = 5;
$permissions = new SharedLinkPermissions(SharedLinkPermissions::CAN_DOWNLOAD);
$p = "/" . basename($newFilename);
- $password = 'qwertz123';
- $shareLinkType = $this->shareLinksResource->create($lib, $p, $permissions, $expire, $password);
+ if ($lib->encrypted) {
+ $shareLinkType = $this->shareLinksResource->create($lib, $p, $permissions, $expire, $lib->password);
+ } else {
+ $shareLinkType = $this->shareLinksResource->create($lib, $p, $permissions, $expire);
+ }
+
self::assertInstanceOf(SharedLink::class, $shareLinkType);
$this->logger->debug("#################### Get all shared links");
diff --git a/test/unit/Resource/AccountTest.php b/test/unit/Resource/AccountTest.php
index de71ef6..2ca19cc 100644
--- a/test/unit/Resource/AccountTest.php
+++ b/test/unit/Resource/AccountTest.php
@@ -2,6 +2,9 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use DateTime;
+use Exception;
+use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
use Seafile\Client\Http\Client as SeafileHttpClient;
@@ -25,8 +28,8 @@ class AccountTest extends UnitTestCase
* Test getAll()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testGetAll()
{
@@ -70,7 +73,7 @@ public function testGetByEmail(string $method = 'getByEmail')
self::assertInstanceOf(AccountType::class, $accountType);
self::assertSame($email, $accountType->email);
- self::assertInstanceOf(\DateTime::class, $accountType->createTime);
+ self::assertInstanceOf(DateTime::class, $accountType->createTime);
self::assertSame('2016-01-08T19:42:50+0000', $accountType->createTime->format(DATE_ISO8601));
}
@@ -88,7 +91,7 @@ public function testGetInfo()
* Test create() with missing attribute values
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testCreateIllegal()
{
@@ -121,7 +124,7 @@ public static function dataProviderCreateUpdate(): array
* @param array $data DataProvider data
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testCreateUpdate(array $data)
{
@@ -137,7 +140,7 @@ public function testCreateUpdate(array $data)
$mockedClient->expects(self::any())
->method('put')
- ->with($baseUri . '/api2/accounts/' . $accountType->{'email'} . '/')// trailing slash is mandatory!
+ ->with($baseUri . '/api' . Account::API_VERSION . '/accounts/' . $accountType->{'email'} . '/')// trailing slash is mandatory!
->willReturn(new Response($data['responseCode']));
$mockedClient->expects(self::any())
@@ -154,7 +157,7 @@ public function testCreateUpdate(array $data)
* Test update() with missing attribute values
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testUpdateIllegal()
{
@@ -183,7 +186,7 @@ public static function dataProviderRemove(): array
* @param array $data DataProvider data
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testRemove(array $data)
{
@@ -197,7 +200,7 @@ public function testRemove(array $data)
$mockedClient->expects(self::any())
->method('delete')
- ->with($baseUri . '/api2/accounts/' . $accountType->email . '/', [])// trailing slash is mandatory!
+ ->with($baseUri . '/api' . Account::API_VERSION . '/accounts/' . $accountType->email . '/', [])// trailing slash is mandatory!
->willReturn(new Response(200));
$mockedClient->expects(self::any())
diff --git a/test/unit/Resource/AvatarTest.php b/test/unit/Resource/AvatarTest.php
index 84973e3..0666652 100644
--- a/test/unit/Resource/AvatarTest.php
+++ b/test/unit/Resource/AvatarTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use DateTime;
+use Exception;
use GuzzleHttp\Psr7\Response;
use Seafile\Client\Http\Client as SeafileHttpClient;
use Seafile\Client\Type\Avatar;
@@ -59,7 +61,7 @@ public function testGetAvatarIllegalSize()
* Test getGroupAvatarByEmail()
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testGetGroupAvatarByEmail()
{
@@ -74,11 +76,11 @@ public function testGetGroupAvatarByEmail()
/**
* Do actual "get avatar" request
*
- * @param string $method Method name
- * @param string $baseUri Base URI
- * @param string $resource Resource string
- * @param string|GroupType $entity Resource entity
- * @param string $size Avatar size in pixels
+ * @param string $method Method name
+ * @param string $baseUri Base URI
+ * @param string $resource Resource string
+ * @param string|GroupType $entity Resource entity
+ * @param string $size Avatar size in pixels
*
* @return void
*/
@@ -91,7 +93,7 @@ protected function doGetAvatar(string $method, string $baseUri, string $resource
$mockedClient->expects(self::any())
->method('get')
- ->with($baseUri . '/api2/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/', [])
+ ->with($baseUri . '/api/v' . AvatarResource::API_VERSION . '/avatars/' . $resource . '/' . $id . '/resized/' . $size . '/', [])
->willReturn(
new Response(
200,
@@ -110,7 +112,7 @@ protected function doGetAvatar(string $method, string $baseUri, string $resource
$avatarType = $avatarResource->{$method}($entity, $size);
self::assertInstanceOf(Avatar::class, $avatarType);
- self::assertInstanceOf(\DateTime::class, $avatarType->mtime);
+ self::assertInstanceOf(DateTime::class, $avatarType->mtime);
self::assertSame('1970-01-01T00:00:00+0000', $avatarType->mtime->format(DATE_ISO8601));
}
@@ -118,7 +120,7 @@ protected function doGetAvatar(string $method, string $baseUri, string $resource
* Test getAvatar() with illegal type instance
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testGetAvatarIllegalType()
{
diff --git a/test/unit/Resource/DirectoryTest.php b/test/unit/Resource/DirectoryTest.php
index 447bb67..92faba9 100644
--- a/test/unit/Resource/DirectoryTest.php
+++ b/test/unit/Resource/DirectoryTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use Exception;
+use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use Seafile\Client\Http\Client as SeafileHttpClient;
use Seafile\Client\Resource\Directory;
@@ -26,7 +28,7 @@ class DirectoryTest extends UnitTestCase
* Test getAll()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testGetAll()
{
@@ -51,7 +53,7 @@ public function testGetAll()
* Test getAll() with directory path
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testGetAllWithDir()
{
@@ -72,7 +74,7 @@ public function testGetAllWithDir()
->method('request')
->with(
self::equalTo('GET'),
- self::equalTo('http://example.com/api2/repos/some-crazy-id/dir/'),
+ self::equalTo('http://example.com/api' . Directory::API_VERSION . '/repos/some-crazy-id/dir/'),
self::equalTo(['query' => ['p' => $rootDir]])
)->willReturn($response);
@@ -87,8 +89,8 @@ public function testGetAllWithDir()
* Test exists()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testExists()
{
@@ -110,7 +112,7 @@ public function testExists()
->method('request')
->with(
self::equalTo('GET'),
- self::equalTo('http://example.com/api2/repos/some-crazy-id/dir/'),
+ self::equalTo('http://example.com/api' . Directory::API_VERSION . '/repos/some-crazy-id/dir/'),
self::equalTo(['query' => ['p' => $rootDir]])
)->willReturn($response);
@@ -142,7 +144,7 @@ public function createNonRecursiveDataProvider()
*
* @dataProvider createNonRecursiveDataProvider
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testCreateNonRecursive(int $expectResponseCode)
{
@@ -169,7 +171,7 @@ public function testCreateNonRecursive(int $expectResponseCode)
* Get directory resource
*
* @param Response $getAllResponse Response on "get all" request
- * @param Response $mkdirResponse Response on actual operation
+ * @param Response $mkdirResponse Response on actual operation
*
* @return Directory
*/
@@ -204,7 +206,7 @@ function ($method) use ($getAllResponse, $mkdirResponse) {
* Test create() non-recursively, directory exists. Must yield boolean false.
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testCreateDirectoryExists()
{
@@ -240,7 +242,7 @@ function () use ($getAllResponse) {
* test create() with empty dirName. Must yield boolean false.
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testCreateEmptyDirName()
{
@@ -256,7 +258,7 @@ public function testCreateEmptyDirName()
* Test create() recursively
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testCreateRecursive()
{
@@ -279,7 +281,7 @@ public function testCreateRecursive()
* Test rename(), with invalid directory name
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testRenameInvalidDirectoryName()
{
@@ -294,7 +296,7 @@ public function testRenameInvalidDirectoryName()
* Test rename()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testRename()
{
@@ -310,16 +312,16 @@ public function testRename()
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/dir/?p=test_dir';
+ $expectUri = 'http://example.com/api' . Directory::API_VERSION . '/repos/some-crazy-id/dir/?p=test_dir';
$expectParams = [
- 'headers' => ['Accept' => "application/json"],
+ 'headers' => ['Accept' => "application/json"],
'multipart' => [
[
- 'name' => "operation",
+ 'name' => "operation",
'contents' => "rename",
],
[
- 'name' => "newname",
+ 'name' => "newname",
'contents' => "test_dir_renamed",
],
],
@@ -359,7 +361,7 @@ function ($method, $uri, $params) use ($getAllResponse, $mkdirResponse, $expectU
* Test remove(), with invalid directory name
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testRemoveInvalidDirectoryName()
{
@@ -374,7 +376,7 @@ public function testRemoveInvalidDirectoryName()
* Test remove()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testRemove()
{
@@ -390,7 +392,7 @@ public function testRemove()
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/dir/?p=test_dir';
+ $expectUri = 'http://example.com/api' . Directory::API_VERSION . '/repos/some-crazy-id/dir/?p=test_dir';
$expectParams = [
'headers' => ['Accept' => "application/json"],
];
diff --git a/test/unit/Resource/FileTest.php b/test/unit/Resource/FileTest.php
index 4778233..3245161 100644
--- a/test/unit/Resource/FileTest.php
+++ b/test/unit/Resource/FileTest.php
@@ -2,10 +2,12 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use DateTime;
use Exception;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
+use ReflectionException;
use Seafile\Client\Http\Client as SeafileHttpClient;
use Seafile\Client\Resource\File;
use Seafile\Client\Tests\Unit\Stubs\FileResourceStub;
@@ -69,13 +71,13 @@ public static function dataProviderTestUrlEncodePath(): array
*
* @return void
* @dataProvider dataProviderTestUrlEncodePath
- * @throws \ReflectionException
+ * @throws ReflectionException
*/
public function testUrlEncodePath(string $path, string $expectEncodedPath)
{
$fileResource = $this->getMockBuilder(File::class)
->disableOriginalConstructor()
- ->setMethods(null)
+ ->addMethods([])
->getMock();
$actualEncodedPath = $this->invokeMethod($fileResource, 'urlencodePath', [$path]);
@@ -101,6 +103,40 @@ public function testGetUploadLink()
self::assertSame('https://some.example.com/some/url', $uploadUrl);
}
+ /**
+ * Test getUploadUrl() with subdirectory. Expect the mocked client's `request` gets called with the parent_dir
+ * parameter "p".
+ *
+ * @return void
+ * @throws GuzzleException
+ * @throws Exception
+ */
+ public function testGetUploadLinkWithSubDirectory()
+ {
+ $libId = "lib_id";
+ $uploadDir = "/Somedir";
+
+ /** @var SeafileHttpClient|MockObject $mockedClient */
+ $mockedClient = $this->getMockedClient(
+ new Response(200, ['Content-Type' => 'application/json'], '"https://some.example.com/some/url"')
+ );
+
+ $mockedClient->expects(self::any())
+ ->method('request')
+ ->with(
+ self::equalTo('GET'),
+ self::equalTo('http://example.com/index.html/api' . File::API_VERSION . '/repos/' . $libId . '/upload-link/?p=' . $uploadDir)
+ );
+
+ $fileResource = new File($mockedClient);
+
+ $lib = new Library(['id' => $libId]);
+
+ $uploadUrl = $fileResource->getUploadUrl($lib, true, $uploadDir);
+
+ self::assertSame('https://some.example.com/some/url', $uploadUrl);
+ }
+
/**
* Download a file, local destination path is already occupied
*
@@ -212,7 +248,7 @@ public function testGetFileDetail()
$response = $fileResource->getFileDetail(new Library(), '/Seafile-PHP-SDK_Test_Upload_jt64pq.txt');
self::assertInstanceOf(DirectoryItem::class, $response);
- self::assertInstanceOf(\DateTime::class, $response->mtime);
+ self::assertInstanceOf(DateTime::class, $response->mtime);
self::assertSame('Seafile-PHP-SDK_Test_Upload_jt64pq.txt', $response->name);
self::assertSame('file', $response->type);
self::assertequals('32', $response->size);
@@ -454,7 +490,7 @@ public function testRemove()
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/file/?p=test_dir';
+ $expectUri = 'http://example.com/api' . File::API_VERSION . '/repos/some-crazy-id/file/?p=test_dir';
$expectParams = [
'headers' => ['Accept' => "application/json"],
];
@@ -511,7 +547,7 @@ public function testRename()
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/file/?p=/test_file';
+ $expectUri = 'http://example.com/api' . File::API_VERSION . '/repos/some-crazy-id/file/?p=/test_file';
$expectParams = [
'headers' => ['Accept' => "application/json"],
'multipart' => [
@@ -593,7 +629,7 @@ public function testCopyMove(array $data)
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/file/?p=' . $srcPath;
+ $expectUri = 'http://example.com/api' . File::API_VERSION . '/repos/some-crazy-id/file/?p=' . $srcPath;
$expectParams = [
'headers' => ['Accept' => 'application/json'],
'multipart' => [
@@ -779,7 +815,7 @@ public function testCreate()
->method('request')
->with(
self::equalTo('POST'),
- 'http://example.com/index.html/api2/repos/123/file/?p=/some_name.txt'
+ 'http://example.com/index.html/api' . File::API_VERSION . '/repos/123/file/?p=/some_name.txt'
)
// Return what was passed to offsetGet as a new instance
->will(self::returnValue(new Response(
diff --git a/test/unit/Resource/GroupTest.php b/test/unit/Resource/GroupTest.php
index c1582d2..02986dc 100644
--- a/test/unit/Resource/GroupTest.php
+++ b/test/unit/Resource/GroupTest.php
@@ -2,6 +2,7 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use Seafile\Client\Resource\Group;
use Seafile\Client\Tests\Unit\UnitTestCase;
@@ -23,7 +24,7 @@ class GroupTest extends UnitTestCase
* Test getAll()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws GuzzleException
*/
public function testGetAll()
{
diff --git a/test/unit/Resource/LibraryTest.php b/test/unit/Resource/LibraryTest.php
index 6ee3bae..12ff84e 100644
--- a/test/unit/Resource/LibraryTest.php
+++ b/test/unit/Resource/LibraryTest.php
@@ -2,6 +2,7 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use Exception;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
@@ -27,7 +28,7 @@ class LibraryTest extends UnitTestCase
* Test getAll()
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testGetAll()
{
@@ -52,7 +53,7 @@ public function testGetAll()
* getById()
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testGetById()
{
@@ -71,7 +72,7 @@ public function testGetById()
* Try to decrypt without query parameters. Must fail of course.
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testDecryptMissingQuery()
{
@@ -84,7 +85,7 @@ public function testDecryptMissingQuery()
* Try to decrypt without password. Must fail of course.
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testDecryptMissingPassword()
{
@@ -97,7 +98,7 @@ public function testDecryptMissingPassword()
* Decryption fails
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testDecryptUnsuccessfully()
{
@@ -121,7 +122,7 @@ public function testDecryptUnsuccessfully()
* Decryption succeeds
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testDecryptSuccessfully()
{
@@ -275,16 +276,16 @@ public function testCreate(array $data)
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/';
+ $expectUri = 'http://example.com/api' . Library::API_VERSION . '/repos/';
$expectParams = [
- 'headers' => ['Accept' => "application/json"],
+ 'headers' => ['Accept' => "application/json"],
'multipart' => [
[
- 'name' => 'name',
+ 'name' => 'name',
'contents' => $name,
],
[
- 'name' => 'desc',
+ 'name' => 'desc',
'contents' => $description,
],
],
@@ -292,7 +293,7 @@ public function testCreate(array $data)
if ($data[2]) {
$expectParams['multipart'][] = [
- 'name' => 'passwd',
+ 'name' => 'passwd',
'contents' => $data[2],
];
}
@@ -333,7 +334,7 @@ function ($method, $uri, $params) use ($getAllResponse, $createResponse, $expect
* Test remove()
*
* @return void
- * @throws \Exception
+ * @throws Exception
* @throws GuzzleException
*/
public function testRemove()
@@ -350,7 +351,7 @@ public function testRemove()
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/';
+ $expectUri = 'http://example.com/api' . Library::API_VERSION . '/repos/some-crazy-id/';
$expectParams = [
'headers' => ['Accept' => "application/json"],
];
diff --git a/test/unit/Resource/MultiTest.php b/test/unit/Resource/MultiTest.php
index 4c3423b..1f6329d 100644
--- a/test/unit/Resource/MultiTest.php
+++ b/test/unit/Resource/MultiTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use Exception;
+use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use Seafile\Client\Http\Client as SeafileHttpClient;
use Seafile\Client\Resource\Multi;
@@ -25,8 +27,8 @@ class MultiTest extends UnitTestCase
* Test delete() with empty paths
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testDeleteEmpty()
{
@@ -44,8 +46,8 @@ public function testDeleteEmpty()
* Test copy() and move() with empty paths
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testCopyMoveEmpty()
{
@@ -71,30 +73,30 @@ public static function dataProviderDelete(): array
return [
[
[
- 'fileNames' => [
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'deletePaths' => [
+ 'deletePaths' => [
'/some_dir/some_file_1',
'/some_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => true,
+ 'assert' => true,
],
],
[
[
- 'fileNames' => [
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'deletePaths' => [
+ 'deletePaths' => [
'/some_dir/some_file_1',
'/some_other_invalid_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => false // because the files are in different folders which is illegal
+ 'assert' => false // because the files are in different folders which is illegal
],
],
];
@@ -108,8 +110,8 @@ public static function dataProviderDelete(): array
* @param array $data DataProvider data
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testDelete(array $data)
{
@@ -128,12 +130,12 @@ public function testDelete(array $data)
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com/');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/fileops/delete/?p=/some_dir';
+ $expectUri = 'http://example.com/api' . Multi::API_VERSION . '/repos/some-crazy-id/fileops/delete/?p=/some_dir';
$expectParams = [
- 'headers' => ['Accept' => "application/json"],
+ 'headers' => ['Accept' => "application/json"],
'multipart' => [
[
- 'name' => 'file_names',
+ 'name' => 'file_names',
'contents' => implode(':', $fileNames),
],
],
@@ -179,62 +181,62 @@ public static function dataProviderCopyMove(): array
return [
[
[
- 'operation' => 'copy',
- 'fileNames' => [
+ 'operation' => 'copy',
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'filePaths' => [
+ 'filePaths' => [
'/some_dir/some_file_1',
'/some_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => true,
+ 'assert' => true,
],
],
[
[
- 'operation' => 'copy',
- 'fileNames' => [
+ 'operation' => 'copy',
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'filePaths' => [
+ 'filePaths' => [
'/some_dir/some_file_1',
'/some_other_invalid_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => false // because the files are in different folders which is illegal
+ 'assert' => false // because the files are in different folders which is illegal
],
],
[
[
- 'operation' => 'move',
- 'fileNames' => [
+ 'operation' => 'move',
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'filePaths' => [
+ 'filePaths' => [
'/some_dir/some_file_1',
'/some_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => true,
+ 'assert' => true,
],
],
[
[
- 'operation' => 'move',
- 'fileNames' => [
+ 'operation' => 'move',
+ 'fileNames' => [
'some_file_1',
'some_file_2',
],
- 'filePaths' => [
+ 'filePaths' => [
'/some_dir/some_file_1',
'/some_other_invalid_dir/some_file_2',
],
'responseCode' => 200,
- 'assert' => false // because the files are in different folders which is illegal
+ 'assert' => false // because the files are in different folders which is illegal
],
],
];
@@ -248,8 +250,8 @@ public static function dataProviderCopyMove(): array
* @param array $data DataProvider data
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testCopyMove(array $data)
{
@@ -275,20 +277,20 @@ public function testCopyMove(array $data)
$mockedClient = $this->getMockBuilder(SeafileHttpClient::class)->getMock();
$mockedClient->method('getConfig')->willReturn('http://example.com');
- $expectUri = 'http://example.com/api2/repos/some-crazy-id/fileops/' . $data ['operation'] . '/?p=/some_dir';
+ $expectUri = 'http://example.com/api' . Multi::API_VERSION . '/repos/some-crazy-id/fileops/' . $data ['operation'] . '/?p=/some_dir';
$expectParams = [
- 'headers' => ['Accept' => "application/json"],
+ 'headers' => ['Accept' => "application/json"],
'multipart' => [
[
- 'name' => 'file_names',
+ 'name' => 'file_names',
'contents' => implode(':', $fileNames),
],
[
- 'name' => 'dst_repo',
+ 'name' => 'dst_repo',
'contents' => $dstLib->id,
],
[
- 'name' => 'dst_dir',
+ 'name' => 'dst_dir',
'contents' => $destDir,
],
],
diff --git a/test/unit/Resource/StarredFileTest.php b/test/unit/Resource/StarredFileTest.php
index e0eb0fe..d7a7ac4 100644
--- a/test/unit/Resource/StarredFileTest.php
+++ b/test/unit/Resource/StarredFileTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Resource;
+use Exception;
+use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
use Seafile\Client\Http\Client as SeafileHttpClient;
@@ -26,8 +28,8 @@ class StarredFileTest extends UnitTestCase
* Test getAll()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testGetAll()
{
@@ -52,8 +54,8 @@ public function testGetAll()
* Test star() with wrong DirItem type
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testStarWrongType()
{
@@ -69,8 +71,8 @@ public function testStarWrongType()
* Test star()
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testStar()
{
@@ -86,7 +88,7 @@ public function testStar()
$starResponse = new Response(
201,
[
- 'Accept' => 'application/json',
+ 'Accept' => 'application/json',
'Location' => $responseUrl,
]
);
@@ -121,7 +123,7 @@ function ($method, $uri, $params) use ($starResponse, $lib, $dirItem) {
if ($hasParams
&& $hasContents
&& $method === 'POST'
- && $uri === 'https://example.com/test/api2/starredfiles/'
+ && $uri === 'https://example.com/test/api' . StarredFile::API_VERSION . '/starredfiles/'
) {
return $starResponse;
}
@@ -140,9 +142,9 @@ function ($method, $uri, $params) use ($starResponse, $lib, $dirItem) {
/**
* Test star() with error response
*
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
* @return void
+ * @throws Exception
+ * @throws GuzzleException
*/
public function testStarErrorStatusCode()
{
@@ -158,7 +160,7 @@ public function testStarErrorStatusCode()
$starResponse = new Response(
500,
[
- 'Accept' => 'application/json',
+ 'Accept' => 'application/json',
'Location' => $responseUrl,
]
);
@@ -188,8 +190,8 @@ public function testStarErrorStatusCode()
* Test star() with missing location
*
* @return void
- * @throws \Exception
- * @throws \GuzzleHttp\Exception\GuzzleException
+ * @throws Exception
+ * @throws GuzzleException
*/
public function testStarErrorMissingLocation()
{
@@ -232,13 +234,13 @@ public static function dataProviderUnstar(): array
[
[
'responseCode' => 200,
- 'result' => true,
+ 'result' => true,
],
],
[
[
'responseCode' => 500,
- 'result' => false,
+ 'result' => false,
],
],
];
@@ -250,8 +252,8 @@ public static function dataProviderUnstar(): array
* @param array $data Data provider array
*
* @return void
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
* @dataProvider dataProviderUnstar
*/
public function testUnstar(array $data)
diff --git a/test/unit/Stubs/FileResourceStub.php b/test/unit/Stubs/FileResourceStub.php
index df61f3a..c26f2d9 100644
--- a/test/unit/Stubs/FileResourceStub.php
+++ b/test/unit/Stubs/FileResourceStub.php
@@ -20,19 +20,19 @@ class FileResourceStub extends File
/**
* Get download URL of a file
*
- * @param LibraryType $library Library instance
- * @param DirectoryItem $item Item instance
- * @param string $dir Dir string
- * @param int $reuse Reuse more than once per hour
+ * @param LibraryType $library Library instance
+ * @param DirectoryItem $item Item instance
+ * @param string $dir Dir string
+ * @param int $reuse Reuse more than once per hour
*
* @return string
*/
public function getDownloadUrl(LibraryType $library, DirectoryItem $item, string $dir = '/', int $reuse = 1)
{
$library = null;
- $item = null;
- $dir = null;
- $reuse = null;
+ $item = null;
+ $dir = null;
+ $reuse = null;
return 'http://download.example.com/';
}
@@ -40,11 +40,12 @@ public function getDownloadUrl(LibraryType $library, DirectoryItem $item, string
* Get upload URL
*
* @param LibraryType $library Library instance
- * @param bool $newFile Is new file (=upload) or not (=update)
+ * @param bool $newFile Is new file (=upload) or not (=update)
+ * @param string $dir Directory to upload to
*
* @return String Upload link
*/
- public function getUploadUrl(LibraryType $library, bool $newFile = true)
+ public function getUploadUrl(LibraryType $library, bool $newFile = true, string $dir = "/"): string
{
$library = null;
$newFile = null;
diff --git a/test/unit/Type/DirectoryItemUnitTest.php b/test/unit/Type/DirectoryItemUnitTest.php
index afcd226..c0b0b09 100644
--- a/test/unit/Type/DirectoryItemUnitTest.php
+++ b/test/unit/Type/DirectoryItemUnitTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Type;
+use Exception;
+use GuzzleHttp\Exception\GuzzleException;
use Seafile\Client\Tests\Unit\UnitTestCase;
use Seafile\Client\Type\DirectoryItem;
@@ -28,13 +30,13 @@ public function dataFromArray()
// [[expect response code, expected result, password]]
[
[
- 'dir' => true,
+ 'dir' => true,
'type' => 'dir',
],
],
[
[
- 'dir' => false,
+ 'dir' => false,
'type' => 'file',
],
],
@@ -48,8 +50,8 @@ public function dataFromArray()
*
* @return void
* @dataProvider dataFromArray
- * @throws \GuzzleHttp\Exception\GuzzleException
- * @throws \Exception
+ * @throws GuzzleException
+ * @throws Exception
*/
public function testFromArray(array $data)
{
diff --git a/test/unit/Type/TypeUnitTest.php b/test/unit/Type/TypeUnitTest.php
index e449944..f1a726c 100644
--- a/test/unit/Type/TypeUnitTest.php
+++ b/test/unit/Type/TypeUnitTest.php
@@ -2,6 +2,8 @@
namespace Seafile\Client\Tests\Unit\Type;
+use DateTime;
+use Exception;
use Seafile\Client\Tests\Unit\UnitTestCase;
use Seafile\Client\Type\Account;
use Seafile\Client\Type\Type;
@@ -25,12 +27,12 @@ class TypeUnitTest extends UnitTestCase
* Test fromArray()
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testFromArray()
{
$dirItem = new DirectoryItem([
- 'id' => 1,
+ 'id' => 1,
'size' => 2,
'name' => 'my name',
'type' => 'my type',
@@ -46,29 +48,29 @@ public function testFromArray()
* Test fromArray() with a non-existing property
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testFromArrayPropertyMissing()
{
$dirItem = new DirectoryItem([
- 'id' => 1,
- 'size' => 2,
- 'name' => 'my name',
- 'type' => 'my type',
+ 'id' => 1,
+ 'size' => 2,
+ 'name' => 'my name',
+ 'type' => 'my type',
'does_not_exist' => '123',
]);
self::assertEquals(
[
- 'id' => 1,
- 'size' => 2,
- 'name' => 'my name',
- 'type' => 'my type',
+ 'id' => 1,
+ 'size' => 2,
+ 'name' => 'my name',
+ 'type' => 'my type',
'mtime' => null,
- 'dir' => '/',
- 'org' => null,
- 'path' => null,
- 'repo' => null,
+ 'dir' => '/',
+ 'org' => null,
+ 'path' => null,
+ 'repo' => null,
],
(array)$dirItem
);
@@ -78,7 +80,7 @@ public function testFromArrayPropertyMissing()
* Test fromArray() with create_time property
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testFromArrayCreateTime()
{
@@ -86,14 +88,14 @@ public function testFromArrayCreateTime()
'create_time' => '1452202279000000',
]);
- self::assertSame('2016-01-07T21:31:19+0000', $accountType->createTime->format(\DateTime::ISO8601));
+ self::assertSame('2016-01-07T21:31:19+0000', $accountType->createTime->format(DateTime::ISO8601));
}
/**
* Test fromJson() with create_time property
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testFromJsonCreateTime()
{
@@ -103,14 +105,14 @@ public function testFromJsonCreateTime()
'create_time' => '1452202279000000',
])));
- self::assertSame('2016-01-07T21:31:19+0000', $accountType->createTime->format(\DateTime::ISO8601));
+ self::assertSame('2016-01-07T21:31:19+0000', $accountType->createTime->format(DateTime::ISO8601));
}
/**
* Test toJson()
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testJson()
{
@@ -152,7 +154,7 @@ public static function dataProviderTestToArrayAssoc(): array
*
* @return void
* @dataProvider dataProviderTestToArrayAssoc
- * @throws \Exception
+ * @throws Exception
*/
public function testToArrayAssoc(array $data)
{
@@ -192,7 +194,7 @@ public static function dataProviderTestToArrayMultiPart(): array
*
* @return void
* @dataProvider dataProviderTestToArrayMultiPart
- * @throws \Exception
+ * @throws Exception
*/
public function testToArrayMultiPart(array $data)
{
@@ -207,7 +209,7 @@ public function testToArrayMultiPart(array $data)
* Must yield AccountType instance
*
* @return void
- * @throws \Exception
+ * @throws Exception
*/
public function testFromArrayCreator()
{
diff --git a/test/unit/UnitTestCase.php b/test/unit/UnitTestCase.php
index 0b853f7..35dd5a2 100644
--- a/test/unit/UnitTestCase.php
+++ b/test/unit/UnitTestCase.php
@@ -4,6 +4,8 @@
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\MockObject\MockObject;
+use PHPUnit\Framework\TestCase;
+use ReflectionClass;
use ReflectionException;
use Seafile\Client\Http\Client;
@@ -16,21 +18,21 @@
* @license https://opensource.org/licenses/MIT MIT
* @link https://github.com/Schmidt-DevOps/seafile-php-sdk
*/
-class UnitTestCase extends \PHPUnit\Framework\TestCase
+class UnitTestCase extends TestCase
{
/**
* Call protected/private method of a class.
*
- * @param object $object Instantiated object that we will run method on.
+ * @param object $object Instantiated object that we will run method on.
* @param string $methodName Method name to call
- * @param array $parameters Array of parameters to pass into method.
+ * @param array $parameters Array of parameters to pass into method.
*
* @return mixed Method return.
* @throws ReflectionException
*/
public function invokeMethod(&$object, string $methodName, array $parameters = [])
{
- $reflection = new \ReflectionClass(get_class($object));
+ $reflection = new ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);