diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7dc7bb4 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,36 @@ +name: Unit tests +on: push +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ['8.2'] + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, dom, fileinfo # Add your extensions here. + coverage: xdebug + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Prepare tests + run: composer run-script tests_prepare + +# - name: Run tests +# run: composer run-script tests_run diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9c50003..fc441b9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,11 @@ variables: before_script: - apt-get update -yqq - - apt-get install git -yqq + - apt-get install git iputils-ping wget -yqq + - ping -c 1 1.1.1.1 || true + - ping -c 1 example.com || true + - ping -c 1 github.com || true + - ping -c 1 dl-cdn.alpinelinux.org || true - curl -sS https://getcomposer.org/installer | php - mv composer.phar /usr/local/bin/composer - curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar @@ -19,17 +23,17 @@ 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.3: +test:php-8.0: stage: test - image: php:7.3 + image: php:8.0 script: - bash ./bin/prepare_tests.sh && bash ./bin/run_tests.sh tags: - sdo-docker-runner -test:php-7.4: +test:php-8.1: stage: test - image: php:7.4 + image: php:8.1 script: - bash ./bin/prepare_tests.sh && bash ./bin/run_tests.sh tags: diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3277176..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: php - -# list any PHP version you want to test against -php: - # using major version aliases - - - 7.3 - - 7.4 - -install: - - sh ./bin/prepare_tests.sh - -# omitting "script:" will default to phpunit -# use the $DB env variable to determine the phpunit.xml to use -script: phpunit --configuration phpunit.xml.dist --coverage-text test - -notifications: - email: - on_success: change - on_failure: change \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 05cc17c..1c7ff5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [2.0.0] +### [3.0.0] - 2021-MM-DD + +- Supports PHP ~v8.0 only. + +## [2.0.1] - 2020-10-06 This version will not be backwards compatible with Version 1.x. diff --git a/README.md b/README.md index e80f8e0..3f86d5e 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,9 @@ This is a PHP package for accessing [Seafile Web API](https://www.seafile.com/). No marketing skills whatsoever, but low rates, 20+ years of experience, and "german work attitude" -- whatever you associate with that. -Get in touch now: https://sdo.sh/DevOps/#contact +Get in touch now: https://sdo.sh/#contact -[![Build Status](https://travis-ci.org/Schmidt-DevOps/Seafile-PHP-SDK.svg?branch=develop)](https://travis-ci.org/Schmidt-DevOps/Seafile-PHP-SDK) -[![Test Coverage](https://codeclimate.com/github/rene-s/Seafile-PHP-SDK/badges/coverage.svg)](https://codeclimate.com/github/rene-s/Seafile-PHP-SDK/coverage) +[![Unit tests](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK/actions/workflows/tests.yml/badge.svg)](https://github.com/Schmidt-DevOps/Seafile-PHP-SDK/actions/workflows/tests.yml) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ## What is Seafile? @@ -344,24 +343,24 @@ $client = new Client( ## Dependencies -- PHP >=7.3 64 bits -- Guzzle 6 +- PHP >=8.0 64 bits +- Guzzle 7.2 ## Seafile Web API Support Matrix -| Resource | Web API Version | Support grade | -| ---------------------- | --------------- | ------------- | -| Account | v2 | ★★★☆ | -| Avatar | v2.1 | ★★★★ | +| Resource | Web API Version | Support grade | +|------------------------|-----------------|-------------------------------------------------------| +| Account | v2 | ★★★☆ | +| Avatar | v2.1 | ★★★★ | | Events | v2 | Yet to be done, [contact me](mailto:rene+_gth@sdo.sh) | -| File Share Link | v2.1 | ★★★☆ | -| Group | v2 | ★☆☆☆ | -| Library/Directory | v2 | ★★☆☆ | -| Library/File | v2 | ★★☆☆ | -| Library/Library | v2 | ★★☆☆ | -| Library/Multiple Files | v2 | ★★★★ | +| File Share Link | v2.1 | ★★★☆ | +| Group | v2 | ★☆☆☆ | +| Library/Directory | v2 | ★★☆☆ | +| Library/File | v2 | ★★☆☆ | +| Library/Library | v2 | ★★☆☆ | +| Library/Multiple Files | v2 | ★★★★ | | Organization | v2 | Yet to be done, [contact me](mailto:rene+_gth@sdo.sh) | -| Starred Files | v2 | ★★★★ | +| Starred Files | v2 | ★★★★ | ## Seafile server compatibility @@ -371,7 +370,11 @@ 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 7.1.4 for Ubuntu 20.04 LTS +- Seafile Server 7.x+ for Ubuntu 20.04 LTS + +## Support + +I'd be happy to implement new features for you at a competitive hourly rate. Get in touch now: https://sdo.sh/#contact ## Contributing @@ -388,7 +391,7 @@ Please note that this package still is in its infancy. Only a part of the API ha There are two types of tests: 1. Unit tests that test a code unit without external dependencies and no data manipulation. Please always provide at least unit tests when contributing. -1. Functional tests that run against a live server instance (=may have external dependencies) and also alter data. Disabled and thus skipped by default. Please refer to `/phpunit/php` in `phpunit.xml.dist` for information on how to enable functional tests. +2. Functional tests that run against a live server instance (=may have external dependencies) and also alter data. Disabled and thus skipped by default. Please refer to `/phpunit/php` in `phpunit.xml.dist` for information on how to enable functional tests. ## Links @@ -400,4 +403,4 @@ There are two types of tests: ## License -[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2020 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG +[MIT](https://raw.githubusercontent.com/rene-s/seafile-php-sdk/master/LICENSE) © 2015-2023 Rene Schmidt DevOps UG (haftungsbeschränkt) & Co. KG diff --git a/bin/run_tests.sh b/bin/run_tests.sh index 42949a5..58583e8 100755 --- a/bin/run_tests.sh +++ b/bin/run_tests.sh @@ -9,7 +9,6 @@ size=`stat --printf="%s" $file 2>/dev/null` if [ ! -f $file ] || [ $size -eq 0 ]; then wget $url -O $file - fi if [ -f $file ]; then diff --git a/composer.json b/composer.json index 3a12663..857b59d 100644 --- a/composer.json +++ b/composer.json @@ -21,20 +21,19 @@ "encrypted" ], "require": { - "php": ">=7.3", - "guzzlehttp/guzzle": "~6.0|~7.0", - "nabil1337/case-helper": "~0.1", + "php": ">=8.2", + "guzzlehttp/guzzle": "~7.7", + "marcusball/case-helper": "~0.2", "ext-json": "*", - "sdo/bitmask": "^1.0" + "sdo/bitmask": "~1.0" }, "require-dev": { - "monolog/monolog": "~1.17", - "phpunit/phpunit": "~8.0", - "phpunit/php-token-stream": "~3.0", - "sebastian/phpcpd": "~4.0", - "squizlabs/php_codesniffer": "~3.2", - "phpunit/php-timer": "~2.0", - "fzaninotto/faker": "^1.9" + "monolog/monolog": " ~2.9", + "phpunit/phpunit": "~9.6", + "sebastian/phpcpd": "~6.0", + "squizlabs/php_codesniffer": "~3.7", + "phpunit/php-timer": "~5.0", + "fzaninotto/faker": "~1.5" }, "type": "library", "autoload": { @@ -47,5 +46,9 @@ "Seafile\\Client\\Tests\\Functional\\": "test/functional", "Seafile\\Client\\Tests\\Unit\\": "test/unit" } + }, + "scripts": { + "tests_prepare": "./bin/prepare_tests.sh", + "tests_run": "./bin/run_tests.sh" } } diff --git a/src/Http/Client.php b/src/Http/Client.php index 8f03397..d2db6bc 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -2,6 +2,7 @@ namespace Seafile\Client\Http; +use GuzzleHttp\Exception\GuzzleException; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\UriInterface; @@ -42,8 +43,9 @@ public function __construct(array $config = []) /** * @param string|UriInterface $uri URI for request - * @param array $args Request args + * @param array $options * @return ResponseInterface + * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { @@ -52,8 +54,9 @@ public function get($uri, array $options = []): ResponseInterface /** * @param string|UriInterface $uri URI for request - * @param array $args Request args + * @param array $options * @return ResponseInterface + * @throws GuzzleException */ public function put($uri, array $options = []): ResponseInterface { @@ -62,8 +65,9 @@ public function put($uri, array $options = []): ResponseInterface /** * @param string|UriInterface $uri URI for request - * @param array $args Request args + * @param array $options * @return ResponseInterface + * @throws GuzzleException */ public function delete($uri, array $options = []): ResponseInterface { diff --git a/src/Resource/File.php b/src/Resource/File.php index 92e1fbe..50b793f 100644 --- a/src/Resource/File.php +++ b/src/Resource/File.php @@ -92,11 +92,11 @@ protected function urlEncodePath(string $path) * @throws GuzzleException */ public function downloadFromDir( - LibraryType $library, + LibraryType $library, DirectoryItem $item, - string $localFilePath, - string $dir, - int $reuse = 1 + string $localFilePath, + string $dir, + int $reuse = 1 ): ResponseInterface { if (is_readable($localFilePath)) { @@ -184,8 +184,8 @@ public function getUploadUrl(LibraryType $library, bool $newFile = true, string public function getMultiPartParams( string $localFilePath, string $dir, - bool $newFile = true, - $newFilename = false + bool $newFile = true, + $newFilename = false ): array { if ($newFilename === false) { @@ -240,10 +240,10 @@ public function getMultiPartParams( */ public function upload( LibraryType $library, - string $localFilePath, - string $dir = '/', - $newFilename = false, - bool $newFile = true + string $localFilePath, + string $dir = '/', + $newFilename = false, + bool $newFile = true ): ResponseInterface { if (!is_readable($localFilePath)) { @@ -389,10 +389,10 @@ public function rename(LibraryType $library, DirectoryItem $dirItem, string $new */ public function copy( LibraryType $srcLibrary, - string $srcFilePath, + string $srcFilePath, LibraryType $dstLibrary, - string $dstDirectoryPath, - int $operation = self::OPERATION_COPY + string $dstDirectoryPath, + int $operation = self::OPERATION_COPY ): bool { // do not allow empty paths @@ -453,9 +453,9 @@ public function copy( */ public function move( LibraryType $srcLibrary, - string $srcFilePath, + string $srcFilePath, LibraryType $dstLibrary, - string $dstDirectoryPath + string $dstDirectoryPath ): bool { return $this->copy($srcLibrary, $srcFilePath, $dstLibrary, $dstDirectoryPath, self::OPERATION_MOVE); @@ -472,8 +472,8 @@ public function move( * @throws GuzzleException */ public function getFileRevisionDownloadUrl( - LibraryType $library, - DirectoryItem $dirItem, + LibraryType $library, + DirectoryItem $dirItem, FileHistoryItem $fileHistoryItem ) { @@ -501,10 +501,10 @@ public function getFileRevisionDownloadUrl( * @throws GuzzleException */ public function downloadRevision( - LibraryType $library, - DirectoryItem $dirItem, + LibraryType $library, + DirectoryItem $dirItem, FileHistoryItem $fileHistoryItem, - string $localFilePath + string $localFilePath ): ResponseInterface { $downloadUrl = $this->getFileRevisionDownloadUrl($library, $dirItem, $fileHistoryItem); diff --git a/src/Resource/Multi.php b/src/Resource/Multi.php index c84f1e3..ab7884b 100644 --- a/src/Resource/Multi.php +++ b/src/Resource/Multi.php @@ -41,9 +41,9 @@ class Multi extends Resource */ public function move( LibraryType $srcLibrary, - array $srcPaths, + array $srcPaths, LibraryType $dstLibrary, - string $dstDirectoryPath + string $dstDirectoryPath ): bool { return $this->copy($srcLibrary, $srcPaths, $dstLibrary, $dstDirectoryPath, self::OPERATION_MOVE); @@ -63,10 +63,10 @@ public function move( */ public function copy( LibraryType $srcLibrary, - array $srcPaths, + array $srcPaths, LibraryType $dstLibrary, - string $dstDirectoryPath, - int $operation = self::OPERATION_COPY + string $dstDirectoryPath, + int $operation = self::OPERATION_COPY ): bool { // do not allow empty paths diff --git a/src/Resource/ShareLinks.php b/src/Resource/ShareLinks.php index 46d4b95..acafb66 100644 --- a/src/Resource/ShareLinks.php +++ b/src/Resource/ShareLinks.php @@ -87,11 +87,11 @@ public function remove(SharedLinkType $sharedLinkType): bool * @throws Exception */ public function create( - LibraryType $library, - string $path, + LibraryType $library, + string $path, SharedLinkPermissions $permissions, - int $expire = null, - string $password = null + int $expire = null, + string $password = null ): ?SharedLinkType { $uri = sprintf(