From dc349f6c13c87cde6de15c0ca1f3856283f6af1f Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 5 Jul 2020 21:58:32 +0200 Subject: [PATCH 01/69] add PhpStan, Improve PHP Docs, add strict return types --- composer.json | 4 +- composer.lock | 94 ++++++++++++++---------------- phpstan.neon | 4 ++ src/Api.php | 22 ++++--- src/BaseClient.php | 23 ++++---- src/ClientInterface.php | 12 ++-- src/CreditNote/Client.php | 8 +-- src/Event/Client.php | 11 ++-- src/File/Client.php | 10 ++-- src/Invoice/Client.php | 6 +- src/OrderConfirmation/Client.php | 2 +- src/PaginationClient.php | 2 +- src/Profile/Client.php | 15 +++-- src/Quotation/Client.php | 6 +- src/Traits/CacheResponseTrait.php | 6 +- src/Traits/DocumentClientTrait.php | 2 +- src/Voucher/Client.php | 6 +- src/Voucherlist/Client.php | 21 +++++-- tests/TestClient.php | 26 ++++----- 19 files changed, 152 insertions(+), 128 deletions(-) create mode 100644 phpstan.neon diff --git a/composer.json b/composer.json index 2c7ca40..1c03003 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ "psr/cache": "^1.0" }, "require-dev": { - "fzaninotto/faker": "^1.9.1", "phpunit/phpunit": "^8.5", - "symfony/cache": "^5.1" + "symfony/cache": "^5.1", + "phpstan/phpstan": "^0.12.32" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 375bf0e..87ab6fe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "617ba7b53bbdfd5459e80f59a43f57b7", + "content-hash": "5fa51936673596bfb1ae59b58795c97a", "packages": [ { "name": "guzzlehttp/guzzle", @@ -577,56 +577,6 @@ ], "time": "2020-05-29T17:27:14+00:00" }, - { - "name": "fzaninotto/faker", - "version": "v1.9.1", - "source": { - "type": "git", - "url": "https://github.com/fzaninotto/Faker.git", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "ext-intl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7", - "squizlabs/php_codesniffer": "^2.9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "time": "2019-12-12T13:22:17+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.10.1", @@ -987,6 +937,48 @@ ], "time": "2020-03-05T15:02:03+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.32", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "d03863f504c8432b3de4d1881f73f6acb8c0e67c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d03863f504c8432b3de4d1881f73f6acb8c0e67c", + "reference": "d03863f504c8432b3de4d1881f73f6acb8c0e67c", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "time": "2020-07-01T11:57:52+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "7.0.10", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..3ff6fa8 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 7 + paths: + - src \ No newline at end of file diff --git a/src/Api.php b/src/Api.php index 4ca884d..053f14e 100644 --- a/src/Api.php +++ b/src/Api.php @@ -17,6 +17,7 @@ use Clicksports\LexOffice\Exceptions\CacheException; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; +use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -57,9 +58,9 @@ class Api protected Client $client; /** - * @var Request|null $request + * @var RequestInterface $request */ - public ?Request $request = null; + public RequestInterface $request; /** * LexOffice constructor. @@ -77,12 +78,12 @@ public function __construct(string $apiKey, Client $client = null) } /** - * @param $method - * @param $resource - * @param array $headers + * @param string $method + * @param string $resource + * @param string[] $headers * @return $this */ - public function newRequest($method, $resource, $headers = []): self + public function newRequest(string $method, string $resource, $headers = []): self { $this->setRequest( new Request($method, $this->createApiUrl($resource), $headers) @@ -133,9 +134,16 @@ public function getResponse() } // when no cacheInterface is set or the cache is invalid - if (!isset($response) || !$response) { + if (!isset($response)) { try { $response = $this->client->send($this->request); + } catch (RequestException $exception) { + $response = $exception->getResponse(); + throw new LexOfficeApiException( + $exception->getMessage(), + $response ? $response->getStatusCode() : $exception->getCode(), + $exception + ); } catch (GuzzleException $exception) { throw new LexOfficeApiException( $exception->getMessage(), diff --git a/src/BaseClient.php b/src/BaseClient.php index 22152f0..7fe2020 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -3,6 +3,7 @@ namespace Clicksports\LexOffice; +use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\MultipartStream; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -22,12 +23,12 @@ public function __construct(Api $lexOffice) } /** - * @param array $data + * @param array[] $data * @return ResponseInterface * @throws Exceptions\CacheException * @throws Exceptions\LexOfficeApiException */ - public function create(array $data) + public function create(array $data): ResponseInterface { $api = $this->api->newRequest('POST', $this->resource); @@ -38,13 +39,13 @@ public function create(array $data) /** * @param string $id - * @param array $data - * @return void - * @throws Exception + * @param array[] $data + * @return ResponseInterface + * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { - throw new Exceptions\BadMethodCallException('method update is defined for ' . $this->resource); + throw new BadMethodCallException('method update is defined for ' . $this->resource); } /** @@ -53,7 +54,7 @@ public function update(string $id, array $data) * @throws Exceptions\CacheException * @throws Exceptions\LexOfficeApiException */ - public function get(string $id) + public function get(string $id): ResponseInterface { return $this->api->newRequest('GET', $this->resource . '/' . $id) ->getResponse(); @@ -63,7 +64,7 @@ public function get(string $id) * @param ResponseInterface $response * @return object */ - public function getAsJson(ResponseInterface $response) + public function getAsJson(ResponseInterface $response): object { $body = $response->getBody()->__toString(); @@ -71,7 +72,7 @@ public function getAsJson(ResponseInterface $response) } /** - * @param array $content + * @param array[] $content * @return StreamInterface */ public function createStream(array $content): StreamInterface @@ -80,7 +81,7 @@ public function createStream(array $content): StreamInterface } /** - * @param array $content + * @param string[]|bool[]|resource[] $content * @return MultipartStream */ public function createMultipartStream(array $content): MultipartStream diff --git a/src/ClientInterface.php b/src/ClientInterface.php index f207cd4..1338ea8 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -13,24 +13,24 @@ interface ClientInterface public function __construct(Api $lexOffice); /** - * @param array $data + * @param array[] $data * @return ResponseInterface * @throws Exceptions\CacheException * @throws Exceptions\LexOfficeApiException */ - public function create(array $data); + public function create(array $data) : ResponseInterface; /** * @param string $id - * @param array $data + * @param array[] $data * @return ResponseInterface */ - public function update(string $id, array $data); + public function update(string $id, array $data): ResponseInterface; /** * @return ResponseInterface */ - public function getAll(); + public function getAll() : ResponseInterface; /** * @param string $id @@ -38,5 +38,5 @@ public function getAll(); * @throws Exceptions\CacheException * @throws Exceptions\LexOfficeApiException */ - public function get(string $id); + public function get(string $id): ResponseInterface; } diff --git a/src/CreditNote/Client.php b/src/CreditNote/Client.php index 859e07c..1b4f2a9 100644 --- a/src/CreditNote/Client.php +++ b/src/CreditNote/Client.php @@ -3,10 +3,8 @@ namespace Clicksports\LexOffice\CreditNote; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\File\Client as FileClient; use Clicksports\LexOffice\Traits\DocumentClientTrait; use Clicksports\LexOffice\Voucherlist\Client as VoucherlistClient; use Psr\Http\Message\ResponseInterface; @@ -18,13 +16,13 @@ class Client extends BaseClient protected string $resource = 'credit-notes'; /** - * @param array $data + * @param array[] $data * @param bool $finalized * @return ResponseInterface * @throws CacheException * @throws LexOfficeApiException */ - public function create(array $data, $finalized = false) + public function create(array $data, $finalized = false): ResponseInterface { $oldResource = $this->resource; @@ -40,7 +38,7 @@ public function create(array $data, $finalized = false) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/Event/Client.php b/src/Event/Client.php index 77e1a14..aa9b021 100644 --- a/src/Event/Client.php +++ b/src/Event/Client.php @@ -13,17 +13,18 @@ class Client extends BaseClient { protected string $resource = 'event-subscriptions'; - public function get(string $id) + public function get(string $id): ResponseInterface { throw new BadMethodCallException('method get() is not supported'); } /** * @param string $id - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update() is not implemented yet'); } @@ -33,7 +34,7 @@ public function update(string $id, array $data) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { return $this->api->newRequest('GET', 'event-subscriptions') ->getResponse(); @@ -45,7 +46,7 @@ public function getAll() * @throws CacheException * @throws LexOfficeApiException */ - public function delete(string $id) + public function delete(string $id): ResponseInterface { return $this->api->newRequest('DELETE', 'event-subscriptions/' . $id) ->getResponse(); diff --git a/src/File/Client.php b/src/File/Client.php index 1cddc9e..e72d3e3 100644 --- a/src/File/Client.php +++ b/src/File/Client.php @@ -14,6 +14,7 @@ class Client extends BaseClient protected string $resource = 'files'; + /** @var string[] */ protected array $supportedExtension = ['png', 'jpg', 'pdf']; /** @@ -23,7 +24,7 @@ class Client extends BaseClient * @throws LexOfficeApiException * @throws CacheException */ - public function upload(string $filepath, string $type) + public function upload(string $filepath, string $type): ResponseInterface { $regex = '/.(' . implode('|', $this->supportedExtension) . ')/'; $matchResult = preg_match($regex, $filepath, $matches); @@ -53,10 +54,11 @@ public function upload(string $filepath, string $type) } /** - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } @@ -64,7 +66,7 @@ public function create(array $data) /** * @throws BadMethodCallException */ - public function getAll() + public function getAll(): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } diff --git a/src/Invoice/Client.php b/src/Invoice/Client.php index 62c1244..3a269af 100644 --- a/src/Invoice/Client.php +++ b/src/Invoice/Client.php @@ -16,13 +16,13 @@ class Client extends BaseClient protected string $resource = 'invoices'; /** - * @param array $data + * @param array[] $data * @param bool $finalized * @return ResponseInterface * @throws CacheException * @throws LexOfficeApiException */ - public function create(array $data, $finalized = false) + public function create(array $data, $finalized = false): ResponseInterface { $oldResource = $this->resource; @@ -39,7 +39,7 @@ public function create(array $data, $finalized = false) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/OrderConfirmation/Client.php b/src/OrderConfirmation/Client.php index 00ab2f0..2886cba 100644 --- a/src/OrderConfirmation/Client.php +++ b/src/OrderConfirmation/Client.php @@ -20,7 +20,7 @@ class Client extends BaseClient * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 20b4d0c..78437d5 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -39,7 +39,7 @@ public function getPage(int $page): ResponseInterface * @throws Exceptions\CacheException * @throws Exceptions\LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $response = $this->getPage(0); $result = $this->getAsJson($response); diff --git a/src/Profile/Client.php b/src/Profile/Client.php index 1ea3e20..decb423 100644 --- a/src/Profile/Client.php +++ b/src/Profile/Client.php @@ -19,24 +19,26 @@ class Client extends BaseClient * @throws CacheException * @throws LexOfficeApiException */ - public function get(string $id = null) + public function get(string $id = null): ResponseInterface { return $this->api->newRequest('GET', $this->resource) ->getResponse(); } + /** * @throws BadMethodCallException */ - public function getAll() + public function getAll(): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } /** - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } @@ -44,10 +46,11 @@ public function create(array $data) /** * @param string $id - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } diff --git a/src/Quotation/Client.php b/src/Quotation/Client.php index 29bb3af..551484a 100644 --- a/src/Quotation/Client.php +++ b/src/Quotation/Client.php @@ -16,13 +16,13 @@ class Client extends BaseClient protected string $resource = 'quotations'; /** - * @param array $data + * @param array[] $data * @param bool $finalized * @return ResponseInterface * @throws CacheException * @throws LexOfficeApiException */ - public function create(array $data, $finalized = false) + public function create(array $data, $finalized = false): ResponseInterface { $oldResource = $this->resource; @@ -38,7 +38,7 @@ public function create(array $data, $finalized = false) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/Traits/CacheResponseTrait.php b/src/Traits/CacheResponseTrait.php index 3365138..26f4444 100644 --- a/src/Traits/CacheResponseTrait.php +++ b/src/Traits/CacheResponseTrait.php @@ -48,11 +48,15 @@ public function getCacheResponse(RequestInterface $request): ?Response { $cacheName = $this->getCacheName($request); + if (!$this->cacheInterface) { + throw new CacheException('response could not be cached, cacheInterface is not defined'); + } + try { if ($request->getMethod() == 'GET') { $cache = $this->cacheInterface->getItem($cacheName); - if ($cache && $cache->isHit()) { + if ($cache->isHit()) { $cache = \GuzzleHttp\json_decode($cache->get()); return new Response( diff --git a/src/Traits/DocumentClientTrait.php b/src/Traits/DocumentClientTrait.php index 9bc60c7..dc2c1f9 100644 --- a/src/Traits/DocumentClientTrait.php +++ b/src/Traits/DocumentClientTrait.php @@ -16,7 +16,7 @@ trait DocumentClientTrait * @throws CacheException * @throws LexOfficeApiException */ - public function document(string $id, bool $asContent = false) + public function document(string $id, bool $asContent = false): ResponseInterface { $response = $this->api->newRequest('GET', $this->resource . '/' . $id . '/document') ->getResponse(); diff --git a/src/Voucher/Client.php b/src/Voucher/Client.php index e151f07..0c9cca9 100644 --- a/src/Voucher/Client.php +++ b/src/Voucher/Client.php @@ -14,12 +14,12 @@ class Client extends BaseClient /** * @param string $id - * @param array $data + * @param array[] $data * @return ResponseInterface * @throws CacheException * @throws LexOfficeApiException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { $api = $this->api->newRequest('PUT', $this->resource . '/' . $id); @@ -33,7 +33,7 @@ public function update(string $id, array $data) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/Voucherlist/Client.php b/src/Voucherlist/Client.php index 80a2042..e20b4a7 100644 --- a/src/Voucherlist/Client.php +++ b/src/Voucherlist/Client.php @@ -4,6 +4,7 @@ use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\PaginationClient; +use Psr\Http\Message\ResponseInterface; class Client extends PaginationClient { @@ -12,10 +13,15 @@ class Client extends PaginationClient public string $sortColumn = 'voucherNumber'; public string $sortDirection = 'DESC'; + /** @var string[] */ public array $types = []; + /** @var string[] */ public array $statuses = []; + /** + * @return $this + */ public function setToEverything() { $this->types = [ @@ -39,6 +45,8 @@ public function setToEverything() 'accepted', 'rejected' ]; + + return $this; } /** @@ -54,29 +62,32 @@ public function generateUrl(int $page): string } /** - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is not supported for ' . $this->resource); } /** * @param string $id - * @param array $data + * @param array[] $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is not supported for ' . $this->resource); } /** * @param string $id + * @return ResponseInterface * @throws BadMethodCallException */ - public function get(string $id) + public function get(string $id): ResponseInterface { throw new BadMethodCallException('method get is not supported for ' . $this->resource); } diff --git a/tests/TestClient.php b/tests/TestClient.php index 4784004..f249615 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -18,7 +18,7 @@ class TestClient extends TestCase { /** * @param Response $response - * @param array $methodExcept + * @param string[] $methodExcept * @return Api|MockObject */ public function createApiMockObject(Response $response, $methodExcept = []) @@ -27,8 +27,8 @@ public function createApiMockObject(Response $response, $methodExcept = []) } /** - * @param array $responses - * @param array $methodExcept + * @param Response[] $responses + * @param string[] $methodExcept * @return MockObject|Api */ public function createApiMultiMockObject(array $responses, $methodExcept = []) @@ -55,7 +55,7 @@ public function createApiMultiMockObject(array $responses, $methodExcept = []) /** * @param string $className * @param Response $response - * @param array $methodExcept + * @param string[] $methodExcept * @return MockObject|ClientInterface */ public function createClientMockObject(string $className, Response $response, array $methodExcept = []) @@ -64,10 +64,10 @@ public function createClientMockObject(string $className, Response $response, ar } /** - * @param string $className + * @param string $className * @param Response[] $responses - * @param array $methodExcept - * @return MockObject + * @param string[] $methodExcept + * @return MockObject|ClientInterface */ public function createClientMultiMockObject(string $className, array $responses, array $methodExcept = []) { @@ -85,8 +85,8 @@ public function createClientMultiMockObject(string $className, array $responses, } /** - * @param array $responses - * @param array $methodExcept + * @param Response[] $responses + * @param string[] $methodExcept * @return MockObject|PaginationClient * @throws ReflectionException */ @@ -111,16 +111,16 @@ public function createPaginationClientMockObject(array $responses, array $method /** * Sets a protected property on a given object via reflection * - * @param $object - instance in which protected value is being modified - * @param $property - property on instance being modified - * @param $value - new value of the property being modified + * @param object $object - instance in which protected value is being modified + * @param string $property - property on instance being modified + * @param mixed $value - new value of the property being modified * * @return void * * @throws ReflectionException * @link https://stackoverflow.com/a/37667018/7387397 */ - public function setProtectedProperty($object, $property, $value) + public function setProtectedProperty(object $object, string $property, $value) { $reflection = new ReflectionClass($object); $reflection_property = $reflection->getProperty($property); From 6e4fac148b55df1d10b611afe24665ed088df671 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 5 Jul 2020 21:58:56 +0200 Subject: [PATCH 02/69] implement throwable in own exceptions --- src/Exceptions/BadMethodCallException.php | 2 +- src/Exceptions/CacheException.php | 2 +- src/Exceptions/LexOfficeApiException.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/BadMethodCallException.php b/src/Exceptions/BadMethodCallException.php index b9b0e77..6faab4a 100644 --- a/src/Exceptions/BadMethodCallException.php +++ b/src/Exceptions/BadMethodCallException.php @@ -2,7 +2,7 @@ namespace Clicksports\LexOffice\Exceptions; -class BadMethodCallException extends \BadMethodCallException +class BadMethodCallException extends \BadMethodCallException implements \Throwable { } \ No newline at end of file diff --git a/src/Exceptions/CacheException.php b/src/Exceptions/CacheException.php index 8347b36..0852681 100644 --- a/src/Exceptions/CacheException.php +++ b/src/Exceptions/CacheException.php @@ -3,7 +3,7 @@ namespace Clicksports\LexOffice\Exceptions; -class CacheException extends \Exception implements \Psr\Cache\CacheException +class CacheException extends \Exception implements \Psr\Cache\CacheException, \Throwable { } \ No newline at end of file diff --git a/src/Exceptions/LexOfficeApiException.php b/src/Exceptions/LexOfficeApiException.php index 6e86d52..cbeda90 100644 --- a/src/Exceptions/LexOfficeApiException.php +++ b/src/Exceptions/LexOfficeApiException.php @@ -2,7 +2,7 @@ namespace Clicksports\LexOffice\Exceptions; -class LexOfficeApiException extends \Exception +class LexOfficeApiException extends \Exception implements \Throwable { } \ No newline at end of file From ee9d98f92ba5255299c9b6310410e48895d88991 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 5 Jul 2020 22:11:19 +0200 Subject: [PATCH 03/69] phpstan doc for Pagination and DocumentClientTrait --- src/PaginationClient.php | 3 +++ src/Traits/DocumentClientTrait.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 78437d5..11ed299 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -3,6 +3,7 @@ namespace Clicksports\LexOffice; use Psr\Http\Message\ResponseInterface; +use stdClass; use function GuzzleHttp\Psr7\stream_for; abstract class PaginationClient extends BaseClient @@ -42,6 +43,7 @@ public function getPage(int $page): ResponseInterface public function getAll(): ResponseInterface { $response = $this->getPage(0); + /** @var stdClass{totalPages:int, content:\stdClass[]} $result */ $result = $this->getAsJson($response); if ($result->totalPages == 1) { @@ -51,6 +53,7 @@ public function getAll(): ResponseInterface // update content to get all contacts for ($i = 1; $i < $result->totalPages; $i++) { $responsePage = $this->getPage($i); + /** @var stdClass{totalPages:int, content:\stdClass[]} $resultPage */ $resultPage = $this->getAsJson($responsePage); foreach ($resultPage->content as $entity) { diff --git a/src/Traits/DocumentClientTrait.php b/src/Traits/DocumentClientTrait.php index dc2c1f9..a081938 100644 --- a/src/Traits/DocumentClientTrait.php +++ b/src/Traits/DocumentClientTrait.php @@ -6,6 +6,7 @@ use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Clicksports\LexOffice\File\Client as FileClient; use Psr\Http\Message\ResponseInterface; +use stdClass; trait DocumentClientTrait { @@ -25,6 +26,7 @@ public function document(string $id, bool $asContent = false): ResponseInterface return $response; } + /** @var stdClass{documentField: string} $content */ $content = $this->getAsJson($response); $fileClient = new FileClient($this->api); From 3c49f790aafcabc39d3bc9235c8107890be2f26d Mon Sep 17 00:00:00 2001 From: Alexander S Date: Mon, 6 Jul 2020 09:55:52 +0200 Subject: [PATCH 04/69] add github action shepherd --- .github/workflows/shepherd.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/shepherd.yml diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml new file mode 100644 index 0000000..2d7318e --- /dev/null +++ b/.github/workflows/shepherd.yml @@ -0,0 +1,16 @@ +name: Run Shepherd + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run Psalm + run: ./vendor/bin/phpstan --threads=2 --output-format=github --shepherd \ No newline at end of file From dc24539a1a6b45e5a982863910acc5c0623a488e Mon Sep 17 00:00:00 2001 From: Alexander S Date: Mon, 6 Jul 2020 20:47:25 +0200 Subject: [PATCH 05/69] update shepherd action --- .github/workflows/shepherd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 2d7318e..48e8021 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan --threads=2 --output-format=github --shepherd \ No newline at end of file + run: ./vendor/bin/phpstan --output-format=github --shepherd \ No newline at end of file From f3cdb87b9dd0dad8e493aed5d58648f8cb2cd1e4 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Mon, 6 Jul 2020 20:49:43 +0200 Subject: [PATCH 06/69] update shepherd action --- .github/workflows/shepherd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 48e8021..430ad10 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan --output-format=github --shepherd \ No newline at end of file + run: ./vendor/bin/phpstan --show-info=false --shepherd --diff --output-format=checkstyle | cs2pr \ No newline at end of file From 75da9683e18f3329ddf2cd35f1c1cff4ae95afcc Mon Sep 17 00:00:00 2001 From: Alexander S Date: Mon, 6 Jul 2020 20:53:41 +0200 Subject: [PATCH 07/69] update shepherd action --- .github/workflows/shepherd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 430ad10..2739eeb 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan --show-info=false --shepherd --diff --output-format=checkstyle | cs2pr \ No newline at end of file + run: ./vendor/bin/phpstan --shepherd --diff --output-format=checkstyle | cs2pr \ No newline at end of file From 4ffd8d2ff4cc8f35e63b1f22f651819b9fc22167 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Mon, 6 Jul 2020 21:31:40 +0200 Subject: [PATCH 08/69] update shepherd action --- .github/workflows/shepherd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 2739eeb..53d541d 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan --shepherd --diff --output-format=checkstyle | cs2pr \ No newline at end of file + run: ./vendor/bin/phpstan analyse --ansi --error-format symplify" \ No newline at end of file From 4c02a37ddc165e88182732701ff8cc78c540a526 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 22 Nov 2020 21:11:34 +0100 Subject: [PATCH 09/69] update composer.lock after merge --- composer.lock | 117 ++++++++++++++++++++++++++------------------------ 1 file changed, 61 insertions(+), 56 deletions(-) diff --git a/composer.lock b/composer.lock index 8b491bc..ae1be98 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fd59de2e621b131220df7beb1733eaf3", + "content-hash": "f60264785f87f2e7d2db90c6bb039309", "packages": [ { "name": "guzzlehttp/guzzle", @@ -507,61 +507,6 @@ ], "time": "2020-11-10T18:47:58+00:00" }, - { - "name": "fzaninotto/faker", - "version": "v1.9.1", - "source": { - "type": "git", - "url": "https://github.com/fzaninotto/Faker.git", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f", - "reference": "fc10d778e4b84d5bd315dad194661e091d307c6f", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "ext-intl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7", - "squizlabs/php_codesniffer": "^2.9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "support": { - "issues": "https://github.com/fzaninotto/Faker/issues", - "source": "https://github.com/fzaninotto/Faker/tree/v1.9.1" - }, - "abandoned": true, - "time": "2019-12-12T13:22:17+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.10.2", @@ -1012,6 +957,66 @@ }, "time": "2020-09-29T09:10:42+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.57", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", + "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.57" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2020-11-21T12:53:28+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.3", From 9d182ef5a69bccbb43d306c9d2296cd22c8db6b2 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 22 Nov 2020 21:12:10 +0100 Subject: [PATCH 10/69] add `declare(strict_types=1);` to every file --- src/Api.php | 2 +- src/BaseClient.php | 2 +- src/ClientInterface.php | 2 +- src/Contact/Client.php | 2 +- src/CreditNote/Client.php | 2 +- src/Event/Client.php | 2 +- src/Exceptions/BadMethodCallException.php | 2 +- src/Exceptions/CacheException.php | 2 +- src/Exceptions/LexOfficeApiException.php | 2 +- src/File/Client.php | 2 +- src/Invoice/Client.php | 2 +- src/OrderConfirmation/Client.php | 2 +- src/PaginationClient.php | 2 +- src/Profile/Client.php | 2 +- src/Quotation/Client.php | 2 +- src/Traits/CacheResponseTrait.php | 2 +- src/Traits/DocumentClientTrait.php | 2 +- src/Voucher/Client.php | 2 +- src/Voucherlist/Client.php | 2 +- tests/ApiTest.php | 2 +- tests/CacheResponseTraitTest.php | 2 +- tests/Contact/ClientTest.php | 2 +- tests/CreditNote/ClientTest.php | 2 +- tests/Event/ClientTest.php | 2 +- tests/File/ClientTest.php | 2 +- tests/Invoice/ClientTest.php | 2 +- tests/OrderConfirmation/ClientTest.php | 2 +- tests/PaginationClientTest.php | 2 +- tests/Profile/ClientTest.php | 2 +- tests/Quotation/ClientTest.php | 2 +- tests/TestClient.php | 2 +- tests/Voucher/ClientTest.php | 2 +- tests/Voucherlist/ClientTest.php | 2 +- 33 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Api.php b/src/Api.php index cdf694f..35af4d4 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1,4 +1,4 @@ - Date: Sun, 22 Nov 2020 21:58:35 +0100 Subject: [PATCH 11/69] rename Client Files, use new namespace `Clicksports\LexOffice\Clients` --- src/Api.php | 60 +++++++++---------- .../Client.php => Clients/Contact.php} | 4 +- .../Client.php => Clients/CreditNote.php} | 7 +-- src/{Event/Client.php => Clients/Event.php} | 4 +- src/{File/Client.php => Clients/File.php} | 4 +- .../Client.php => Clients/Invoice.php} | 7 +-- .../OrderConfirmation.php} | 7 +-- .../Client.php => Clients/Profile.php} | 4 +- .../Client.php => Clients/Quotation.php} | 7 +-- .../Client.php => Clients/Voucher.php} | 7 +-- .../Client.php => Clients/VoucherList.php} | 4 +- src/Traits/DocumentClientTrait.php | 4 +- tests/ApiTest.php | 30 ++++++---- .../ContactTest.php} | 8 +-- .../CreditNoteTest.php} | 14 ++--- .../ClientTest.php => Clients/EventTest.php} | 16 ++--- .../ClientTest.php => Clients/FileTest.php} | 24 ++++---- .../InvoiceTest.php} | 18 +++--- .../OrderConfirmationTest.php} | 18 +++--- .../ProfileTest.php} | 14 ++--- .../QuotationTest.php} | 18 +++--- .../VoucherListTest.php} | 14 ++--- .../VoucherTest.php} | 14 ++--- tests/{ => Traits}/CacheResponseTraitTest.php | 3 +- tests/{ => Traits}/PaginationClientTest.php | 3 +- 25 files changed, 160 insertions(+), 153 deletions(-) rename src/{Contact/Client.php => Clients/Contact.php} (85%) rename src/{CreditNote/Client.php => Clients/CreditNote.php} (85%) rename src/{Event/Client.php => Clients/Event.php} (95%) rename src/{File/Client.php => Clients/File.php} (96%) rename src/{Invoice/Client.php => Clients/Invoice.php} (85%) rename src/{OrderConfirmation/Client.php => Clients/OrderConfirmation.php} (76%) rename src/{Profile/Client.php => Clients/Profile.php} (95%) rename src/{Quotation/Client.php => Clients/Quotation.php} (85%) rename src/{Voucher/Client.php => Clients/Voucher.php} (86%) rename src/{Voucherlist/Client.php => Clients/VoucherList.php} (96%) rename tests/{Contact/ClientTest.php => Clients/ContactTest.php} (73%) rename tests/{CreditNote/ClientTest.php => Clients/CreditNoteTest.php} (85%) rename tests/{Event/ClientTest.php => Clients/EventTest.php} (86%) rename tests/{File/ClientTest.php => Clients/FileTest.php} (83%) rename tests/{Invoice/ClientTest.php => Clients/InvoiceTest.php} (88%) rename tests/{OrderConfirmation/ClientTest.php => Clients/OrderConfirmationTest.php} (85%) rename tests/{Profile/ClientTest.php => Clients/ProfileTest.php} (83%) rename tests/{Quotation/ClientTest.php => Clients/QuotationTest.php} (87%) rename tests/{Voucherlist/ClientTest.php => Clients/VoucherListTest.php} (84%) rename tests/{Voucher/ClientTest.php => Clients/VoucherTest.php} (85%) rename tests/{ => Traits}/CacheResponseTraitTest.php (97%) rename tests/{ => Traits}/PaginationClientTest.php (94%) diff --git a/src/Api.php b/src/Api.php index 35af4d4..a12290e 100644 --- a/src/Api.php +++ b/src/Api.php @@ -2,17 +2,17 @@ namespace Clicksports\LexOffice; -use Clicksports\LexOffice\Contact\Client as ContactClient; -use Clicksports\LexOffice\CreditNote\Client as CreditNoteClient; -use Clicksports\LexOffice\Event\Client as EventClient; -use Clicksports\LexOffice\File\Client as FileClient; -use Clicksports\LexOffice\Invoice\Client as InvoiceClient; -use Clicksports\LexOffice\OrderConfirmation\Client as OrderConfirmationClient; -use Clicksports\LexOffice\Profile\Client as ProfileClient; -use Clicksports\LexOffice\Quotation\Client as QuotationClient; +use Clicksports\LexOffice\Clients\Contact; +use Clicksports\LexOffice\Clients\CreditNote; +use Clicksports\LexOffice\Clients\Event; +use Clicksports\LexOffice\Clients\File; +use Clicksports\LexOffice\Clients\Invoice; +use Clicksports\LexOffice\Clients\OrderConfirmation; +use Clicksports\LexOffice\Clients\Profile; +use Clicksports\LexOffice\Clients\Quotation; +use Clicksports\LexOffice\Clients\Voucher; +use Clicksports\LexOffice\Clients\VoucherList; use Clicksports\LexOffice\Traits\CacheResponseTrait; -use Clicksports\LexOffice\Voucher\Client as VoucherClient; -use Clicksports\LexOffice\Voucherlist\Client as VoucherlistClient; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Clicksports\LexOffice\Exceptions\CacheException; use GuzzleHttp\Client; @@ -162,82 +162,82 @@ public function getResponse() } /** - * @return ContactClient + * @return Contact */ public function contact() { - return new ContactClient($this); + return new Contact($this); } /** - * @return EventClient + * @return Event */ public function event() { - return new EventClient($this); + return new Event($this); } /** - * @return InvoiceClient + * @return Invoice */ public function invoice() { - return new InvoiceClient($this); + return new Invoice($this); } /** - * @return OrderConfirmationClient + * @return OrderConfirmation */ public function orderConfirmation() { - return new OrderConfirmationClient($this); + return new OrderConfirmation($this); } /** - * @return CreditNoteClient + * @return CreditNote */ public function creditNote() { - return new CreditNoteClient($this); + return new CreditNote($this); } /** - * @return QuotationClient + * @return Quotation */ public function quotation() { - return new QuotationClient($this); + return new Quotation($this); } /** - * @return VoucherClient + * @return Voucher */ public function voucher() { - return new VoucherClient($this); + return new Voucher($this); } /** - * @return VoucherlistClient + * @return VoucherList */ public function voucherlist() { - return new VoucherlistClient($this); + return new VoucherList($this); } /** - * @return ProfileClient + * @return Profile */ public function profile() { - return new ProfileClient($this); + return new Profile($this); } /** - * @return FileClient + * @return File */ public function file() { - return new FileClient($this); + return new File($this); } } diff --git a/src/Contact/Client.php b/src/Clients/Contact.php similarity index 85% rename from src/Contact/Client.php rename to src/Clients/Contact.php index 7fa7d4b..5ab69f6 100644 --- a/src/Contact/Client.php +++ b/src/Clients/Contact.php @@ -1,10 +1,10 @@ api); + $client = new VoucherList($this->api); $client->setToEverything(); $client->types = ['creditnote']; diff --git a/src/Event/Client.php b/src/Clients/Event.php similarity index 95% rename from src/Event/Client.php rename to src/Clients/Event.php index e6a78ce..56c322b 100644 --- a/src/Event/Client.php +++ b/src/Clients/Event.php @@ -1,7 +1,7 @@ api); + $client = new VoucherList($this->api); $client->setToEverything(); $client->types = ['invoice']; diff --git a/src/OrderConfirmation/Client.php b/src/Clients/OrderConfirmation.php similarity index 76% rename from src/OrderConfirmation/Client.php rename to src/Clients/OrderConfirmation.php index dcd1465..4fbbee9 100644 --- a/src/OrderConfirmation/Client.php +++ b/src/Clients/OrderConfirmation.php @@ -1,15 +1,14 @@ api); + $client = new VoucherList($this->api); $client->setToEverything(); $client->types = ['orderconfirmation']; diff --git a/src/Profile/Client.php b/src/Clients/Profile.php similarity index 95% rename from src/Profile/Client.php rename to src/Clients/Profile.php index 9615791..38aaba1 100644 --- a/src/Profile/Client.php +++ b/src/Clients/Profile.php @@ -1,7 +1,7 @@ api); + $client = new VoucherList($this->api); $client->setToEverything(); $client->types = ['quotation']; diff --git a/src/Voucher/Client.php b/src/Clients/Voucher.php similarity index 86% rename from src/Voucher/Client.php rename to src/Clients/Voucher.php index 4e44fc0..7e4759c 100644 --- a/src/Voucher/Client.php +++ b/src/Clients/Voucher.php @@ -1,14 +1,13 @@ api); + $client = new VoucherList($this->api); /** * @link https://developers.lexoffice.io/docs/#vouchers-endpoint-purpose diff --git a/src/Voucherlist/Client.php b/src/Clients/VoucherList.php similarity index 96% rename from src/Voucherlist/Client.php rename to src/Clients/VoucherList.php index 6a02272..27c523a 100644 --- a/src/Voucherlist/Client.php +++ b/src/Clients/VoucherList.php @@ -1,12 +1,12 @@ getAsJson($response); - $fileClient = new FileClient($this->api); + $fileClient = new File($this->api); return $fileClient->get($content->documentFileId); } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index a2faebe..43cf31f 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -2,6 +2,16 @@ namespace Clicksports\LexOffice\Tests; +use Clicksports\LexOffice\Clients\Contact; +use Clicksports\LexOffice\Clients\CreditNote; +use Clicksports\LexOffice\Clients\Event; +use Clicksports\LexOffice\Clients\File; +use Clicksports\LexOffice\Clients\Invoice; +use Clicksports\LexOffice\Clients\OrderConfirmation; +use Clicksports\LexOffice\Clients\Profile; +use Clicksports\LexOffice\Clients\Quotation; +use Clicksports\LexOffice\Clients\Voucher; +use Clicksports\LexOffice\Clients\VoucherList; use GuzzleHttp\Psr7\Response; class ApiTest extends TestClient @@ -22,16 +32,16 @@ public function testClients() ['contact', 'event', 'invoice', 'orderConfirmation', 'quotation', 'voucher', 'voucherlist', 'profile', 'creditNote', 'file'] ); - $this->assertInstanceOf(\Clicksports\LexOffice\Contact\Client::class, $stub->contact()); - $this->assertInstanceOf(\Clicksports\LexOffice\Event\Client::class, $stub->event()); - $this->assertInstanceOf(\Clicksports\LexOffice\Invoice\Client::class, $stub->invoice()); - $this->assertInstanceOf(\Clicksports\LexOffice\OrderConfirmation\Client::class, $stub->orderConfirmation()); - $this->assertInstanceOf(\Clicksports\LexOffice\Quotation\Client::class, $stub->quotation()); - $this->assertInstanceOf(\Clicksports\LexOffice\Voucher\Client::class, $stub->voucher()); - $this->assertInstanceOf(\Clicksports\LexOffice\Voucherlist\Client::class, $stub->voucherlist()); - $this->assertInstanceOf(\Clicksports\LexOffice\Profile\Client::class, $stub->profile()); - $this->assertInstanceOf(\Clicksports\LexOffice\CreditNote\Client::class, $stub->creditNote()); - $this->assertInstanceOf(\Clicksports\LexOffice\File\Client::class, $stub->file()); + $this->assertInstanceOf(Contact::class, $stub->contact()); + $this->assertInstanceOf(Event::class, $stub->event()); + $this->assertInstanceOf(Invoice::class, $stub->invoice()); + $this->assertInstanceOf(OrderConfirmation::class, $stub->orderConfirmation()); + $this->assertInstanceOf(Quotation::class, $stub->quotation()); + $this->assertInstanceOf(Voucher::class, $stub->voucher()); + $this->assertInstanceOf(VoucherList::class, $stub->voucherlist()); + $this->assertInstanceOf(Profile::class, $stub->profile()); + $this->assertInstanceOf(CreditNote::class, $stub->creditNote()); + $this->assertInstanceOf(File::class, $stub->file()); } public function testGetResponse() diff --git a/tests/Contact/ClientTest.php b/tests/Clients/ContactTest.php similarity index 73% rename from tests/Contact/ClientTest.php rename to tests/Clients/ContactTest.php index dcc6ea2..e0da99c 100644 --- a/tests/Contact/ClientTest.php +++ b/tests/Clients/ContactTest.php @@ -1,17 +1,17 @@ createClientMockObject( - Client::class, + Contact::class, new Response(200, [], 'body'), ['generateUrl'] ); diff --git a/tests/CreditNote/ClientTest.php b/tests/Clients/CreditNoteTest.php similarity index 85% rename from tests/CreditNote/ClientTest.php rename to tests/Clients/CreditNoteTest.php index 9e8f8c4..153c662 100644 --- a/tests/CreditNote/ClientTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -1,17 +1,17 @@ createClientMockObject( - Client::class, + CreditNote::class, new Response(200, [], 'body'), ['create'] ); @@ -26,7 +26,7 @@ public function testCreate() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + CreditNote::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -39,7 +39,7 @@ public function testGetAll() public function testDocument() { $stub = $this->createClientMockObject( - Client::class, + CreditNote::class, new Response(200, [], '{"documentFileId": "fake-id"}'), ['document'] ); @@ -52,7 +52,7 @@ public function testDocument() ); $stub = $this->createClientMultiMockObject( - Client::class, + CreditNote::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') diff --git a/tests/Event/ClientTest.php b/tests/Clients/EventTest.php similarity index 86% rename from tests/Event/ClientTest.php rename to tests/Clients/EventTest.php index f804610..57e91f1 100644 --- a/tests/Event/ClientTest.php +++ b/tests/Clients/EventTest.php @@ -1,19 +1,19 @@ createClientMockObject( - Client::class, + Event::class, new Response(200, [], 'body'), ['create'] ); @@ -30,7 +30,7 @@ public function testGet() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Event::class, new Response(200, [], 'body'), ['get'] ); @@ -41,7 +41,7 @@ public function testGet() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + Event::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -56,7 +56,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Event::class, new Response(200, [], '{}'), ['update'] ); @@ -67,7 +67,7 @@ public function testUpdate() public function testDelete() { $stub = $this->createClientMockObject( - Client::class, + Event::class, new Response(200, [], 'body'), ['delete'] ); diff --git a/tests/File/ClientTest.php b/tests/Clients/FileTest.php similarity index 83% rename from tests/File/ClientTest.php rename to tests/Clients/FileTest.php index adccda0..01d75fc 100644 --- a/tests/File/ClientTest.php +++ b/tests/Clients/FileTest.php @@ -1,22 +1,22 @@ expectException(LexOfficeApiException::class); $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['upload'] ); @@ -29,7 +29,7 @@ public function testUploadNotFound() $this->expectException(LexOfficeApiException::class); $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['upload'] ); @@ -42,14 +42,14 @@ public function testUploadToBig() $this->expectException(LexOfficeApiException::class); $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['upload'] ); - $file = __DIR__ . '/somefile.jpg'; + $file = __DIR__ . '/../cache/somefile.jpg'; $fp = fopen($file, 'w+'); // - fseek($fp, Client::MAX_FILE_SIZE + 1,SEEK_CUR); + fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); fclose($fp); @@ -61,12 +61,12 @@ public function testUploadToBig() public function testUpload() { $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['upload'] ); - $file = __DIR__ . '/somefile2.jpg'; + $file = __DIR__ . '/../cache/somefile2.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); @@ -84,7 +84,7 @@ public function testCreate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['create'] ); @@ -97,7 +97,7 @@ public function testGetAll() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + File::class, new Response(200, [], '{}'), ['getAll'] ); diff --git a/tests/Invoice/ClientTest.php b/tests/Clients/InvoiceTest.php similarity index 88% rename from tests/Invoice/ClientTest.php rename to tests/Clients/InvoiceTest.php index 7ddfde9..05892f0 100644 --- a/tests/Invoice/ClientTest.php +++ b/tests/Clients/InvoiceTest.php @@ -1,19 +1,19 @@ createClientMockObject( - Client::class, + Invoice::class, new Response(200, [], 'body'), ['create'] ); @@ -28,7 +28,7 @@ public function testCreate() public function testGet() { $stub = $this->createClientMockObject( - Client::class, + Invoice::class, new Response(200, [], 'body'), ['get'] ); @@ -41,7 +41,7 @@ public function testGet() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + Invoice::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -56,7 +56,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Invoice::class, new Response(200, [], '{}'), ['update'] ); @@ -67,7 +67,7 @@ public function testUpdate() public function testDocument() { $stub = $this->createClientMockObject( - Client::class, + Invoice::class, new Response(200, [], '{"documentFileId": "fake-id"}'), ['document'] ); @@ -80,7 +80,7 @@ public function testDocument() ); $stub = $this->createClientMultiMockObject( - Client::class, + Invoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') diff --git a/tests/OrderConfirmation/ClientTest.php b/tests/Clients/OrderConfirmationTest.php similarity index 85% rename from tests/OrderConfirmation/ClientTest.php rename to tests/Clients/OrderConfirmationTest.php index fdcf8e1..952841d 100644 --- a/tests/OrderConfirmation/ClientTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -1,19 +1,19 @@ createClientMockObject( - Client::class, + OrderConfirmation::class, new Response(200, [], 'body'), ['create'] ); @@ -28,7 +28,7 @@ public function testCreate() public function testGet() { $stub = $this->createClientMockObject( - Client::class, + OrderConfirmation::class, new Response(200, [], 'body'), ['get'] ); @@ -41,7 +41,7 @@ public function testGet() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + OrderConfirmation::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -56,7 +56,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + OrderConfirmation::class, new Response(200, [], '{}'), ['update'] ); @@ -67,7 +67,7 @@ public function testUpdate() public function testDocument() { $stub = $this->createClientMockObject( - Client::class, + OrderConfirmation::class, new Response(200, [], '{"documentFileId": "fake-id"}'), ['document'] ); @@ -80,7 +80,7 @@ public function testDocument() ); $stub = $this->createClientMultiMockObject( - Client::class, + OrderConfirmation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') diff --git a/tests/Profile/ClientTest.php b/tests/Clients/ProfileTest.php similarity index 83% rename from tests/Profile/ClientTest.php rename to tests/Clients/ProfileTest.php index d3b38a1..512302b 100644 --- a/tests/Profile/ClientTest.php +++ b/tests/Clients/ProfileTest.php @@ -1,13 +1,13 @@ expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Profile::class, new Response(200, [], '{}'), ['getAll'] ); @@ -26,7 +26,7 @@ public function testGetAll() public function testGet() { $stub = $this->createClientMockObject( - Client::class, + Profile::class, new Response(200, [], '{}'), ['get'] ); @@ -42,7 +42,7 @@ public function testCreate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Profile::class, new Response(200, [], '{}'), ['create'] ); @@ -55,7 +55,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Profile::class, new Response(200, [], '{}'), ['update'] ); diff --git a/tests/Quotation/ClientTest.php b/tests/Clients/QuotationTest.php similarity index 87% rename from tests/Quotation/ClientTest.php rename to tests/Clients/QuotationTest.php index 8d62b1f..811c40c 100644 --- a/tests/Quotation/ClientTest.php +++ b/tests/Clients/QuotationTest.php @@ -1,19 +1,19 @@ createClientMockObject( - Client::class, + Quotation::class, new Response(200, [], 'body'), ['create'] ); @@ -28,7 +28,7 @@ public function testCreate() public function testGet() { $stub = $this->createClientMockObject( - Client::class, + Quotation::class, new Response(200, [], 'body'), ['get'] ); @@ -41,7 +41,7 @@ public function testGet() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + Quotation::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -56,7 +56,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + Quotation::class, new Response(200, [], '{}'), ['update'] ); @@ -67,7 +67,7 @@ public function testUpdate() public function testDocument() { $stub = $this->createClientMockObject( - Client::class, + Quotation::class, new Response(200, [], '{"documentFileId": "fake-id"}'), ['document'] ); @@ -80,7 +80,7 @@ public function testDocument() ); $stub = $this->createClientMultiMockObject( - Client::class, + Quotation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') diff --git a/tests/Voucherlist/ClientTest.php b/tests/Clients/VoucherListTest.php similarity index 84% rename from tests/Voucherlist/ClientTest.php rename to tests/Clients/VoucherListTest.php index 6884f7a..9c35278 100644 --- a/tests/Voucherlist/ClientTest.php +++ b/tests/Clients/VoucherListTest.php @@ -1,19 +1,19 @@ createClientMockObject( - Client::class, + VoucherList::class, new Response(200, [], 'body'), ['generateUrl'] ); @@ -32,7 +32,7 @@ public function testCreate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + VoucherList::class, new Response(200, [], 'body'), ['create'] ); @@ -45,7 +45,7 @@ public function testGet() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + VoucherList::class, new Response(200, [], 'body'), ['get'] ); @@ -58,7 +58,7 @@ public function testUpdate() $this->expectException(BadMethodCallException::class); $stub = $this->createClientMockObject( - Client::class, + VoucherList::class, new Response(200, [], '{}'), ['update'] ); diff --git a/tests/Voucher/ClientTest.php b/tests/Clients/VoucherTest.php similarity index 85% rename from tests/Voucher/ClientTest.php rename to tests/Clients/VoucherTest.php index 5c0de2b..1f834d6 100644 --- a/tests/Voucher/ClientTest.php +++ b/tests/Clients/VoucherTest.php @@ -1,18 +1,18 @@ createClientMockObject( - Client::class, + Voucher::class, new Response(200, [], 'body'), ['create'] ); @@ -27,7 +27,7 @@ public function testCreate() public function testGet() { $stub = $this->createClientMockObject( - Client::class, + Voucher::class, new Response(200, [], 'body'), ['get'] ); @@ -40,7 +40,7 @@ public function testGet() public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + Voucher::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -53,7 +53,7 @@ public function testGetAll() public function testUpdate() { $stub = $this->createClientMockObject( - Client::class, + Voucher::class, new Response(200, [], '{}'), ['update'] ); diff --git a/tests/CacheResponseTraitTest.php b/tests/Traits/CacheResponseTraitTest.php similarity index 97% rename from tests/CacheResponseTraitTest.php rename to tests/Traits/CacheResponseTraitTest.php index 255c8a7..e825f47 100644 --- a/tests/CacheResponseTraitTest.php +++ b/tests/Traits/CacheResponseTraitTest.php @@ -1,10 +1,11 @@ Date: Sun, 7 Feb 2021 21:27:57 +0100 Subject: [PATCH 12/69] split Create/Get/Update/Delete into Traits. remove BadMethodCallException --- src/BaseClient.php | 39 ----------------- src/ClientInterface.php | 30 ------------- src/Clients/Contact.php | 5 +++ src/Clients/CreditNote.php | 24 +++-------- src/Clients/Event.php | 34 +++------------ src/Clients/File.php | 22 ++-------- src/Clients/Invoice.php | 25 +++-------- src/Clients/OrderConfirmation.php | 6 ++- src/Clients/Profile.php | 34 +-------------- src/Clients/Quotation.php | 24 +++-------- src/Clients/Traits/CreateFinalizeTrait.php | 22 ++++++++++ src/Clients/Traits/CreateTrait.php | 21 +++++++++ src/Clients/Traits/DeleteTrait.php | 18 ++++++++ .../Traits/DocumentClientTrait.php | 6 +-- src/Clients/Traits/GetTrait.php | 18 ++++++++ src/Clients/Traits/UpdateTrait.php | 22 ++++++++++ src/Clients/Voucher.php | 23 +++------- src/Clients/VoucherList.php | 33 -------------- src/Exceptions/BadMethodCallException.php | 8 ---- tests/Clients/EventTest.php | 27 ------------ tests/Clients/FileTest.php | 27 ------------ tests/Clients/InvoiceTest.php | 14 ------ tests/Clients/OrderConfirmationTest.php | 14 ------ tests/Clients/ProfileTest.php | 43 +------------------ tests/Clients/QuotationTest.php | 14 ------ tests/Clients/VoucherListTest.php | 40 ----------------- 26 files changed, 144 insertions(+), 449 deletions(-) create mode 100644 src/Clients/Traits/CreateFinalizeTrait.php create mode 100644 src/Clients/Traits/CreateTrait.php create mode 100644 src/Clients/Traits/DeleteTrait.php rename src/{ => Clients}/Traits/DocumentClientTrait.php (77%) create mode 100644 src/Clients/Traits/GetTrait.php create mode 100644 src/Clients/Traits/UpdateTrait.php delete mode 100644 src/Exceptions/BadMethodCallException.php diff --git a/src/BaseClient.php b/src/BaseClient.php index 47baabc..8b9a5c4 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\MultipartStream; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamInterface; @@ -21,44 +20,6 @@ public function __construct(Api $lexOffice) $this->api = $lexOffice; } - /** - * @param array[] $data - * @return ResponseInterface - * @throws Exceptions\CacheException - * @throws Exceptions\LexOfficeApiException - */ - public function create(array $data): ResponseInterface - { - $api = $this->api->newRequest('POST', $this->resource); - - $api->request = $api->request->withBody($this->createStream($data)); - - return $api->getResponse(); - } - - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function update(string $id, array $data): ResponseInterface - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @param string $id - * @return ResponseInterface - * @throws Exceptions\CacheException - * @throws Exceptions\LexOfficeApiException - */ - public function get(string $id): ResponseInterface - { - return $this->api->newRequest('GET', $this->resource . '/' . $id) - ->getResponse(); - } - /** * @param ResponseInterface $response * @return object diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 74e0488..3213443 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -2,8 +2,6 @@ namespace Clicksports\LexOffice; -use Psr\Http\Message\ResponseInterface; - interface ClientInterface { /** @@ -11,32 +9,4 @@ interface ClientInterface * @param Api $lexOffice */ public function __construct(Api $lexOffice); - - /** - * @param array[] $data - * @return ResponseInterface - * @throws Exceptions\CacheException - * @throws Exceptions\LexOfficeApiException - */ - public function create(array $data) : ResponseInterface; - - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - */ - public function update(string $id, array $data): ResponseInterface; - - /** - * @return ResponseInterface - */ - public function getAll() : ResponseInterface; - - /** - * @param string $id - * @return ResponseInterface - * @throws Exceptions\CacheException - * @throws Exceptions\LexOfficeApiException - */ - public function get(string $id): ResponseInterface; } diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index 5ab69f6..00c4015 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -2,10 +2,15 @@ namespace Clicksports\LexOffice\Clients; +use Clicksports\LexOffice\Clients\Traits\CreateTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\PaginationClient; class Contact extends PaginationClient { + use CreateTrait; + use GetTrait; + protected string $resource = 'contacts'; public string $sortDirection = 'ASC'; diff --git a/src/Clients/CreditNote.php b/src/Clients/CreditNote.php index 531e346..20e6f16 100644 --- a/src/Clients/CreditNote.php +++ b/src/Clients/CreditNote.php @@ -3,35 +3,21 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; +use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; +use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; use Psr\Http\Message\ResponseInterface; class CreditNote extends BaseClient { + use GetTrait; + use CreateFinalizeTrait; use DocumentClientTrait; protected string $resource = 'credit-notes'; - /** - * @param array[] $data - * @param bool $finalized - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function create(array $data, $finalized = false): ResponseInterface - { - $oldResource = $this->resource; - - $this->resource .= $finalized ? '?finalize=true' : ''; - $response = parent::create($data); - $this->resource = $oldResource; - - return $response; - } - /** * @return ResponseInterface * @throws CacheException diff --git a/src/Clients/Event.php b/src/Clients/Event.php index 56c322b..f5c7840 100644 --- a/src/Clients/Event.php +++ b/src/Clients/Event.php @@ -4,30 +4,18 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; +use Clicksports\LexOffice\Clients\Traits\CreateTrait; +use Clicksports\LexOffice\Clients\Traits\DeleteTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Event extends BaseClient { - protected string $resource = 'event-subscriptions'; + use DeleteTrait; + use CreateTrait; - public function get(string $id): ResponseInterface - { - throw new BadMethodCallException('method get() is not supported'); - } - - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function update(string $id, array $data): ResponseInterface - { - throw new BadMethodCallException('method update() is not implemented yet'); - } + protected string $resource = 'event-subscriptions'; /** * @return ResponseInterface @@ -39,16 +27,4 @@ public function getAll(): ResponseInterface return $this->api->newRequest('GET', 'event-subscriptions') ->getResponse(); } - - /** - * @param string $id - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function delete(string $id): ResponseInterface - { - return $this->api->newRequest('DELETE', 'event-subscriptions/' . $id) - ->getResponse(); - } } diff --git a/src/Clients/File.php b/src/Clients/File.php index afc31ca..15eeaf3 100644 --- a/src/Clients/File.php +++ b/src/Clients/File.php @@ -3,13 +3,15 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class File extends BaseClient { + use GetTrait; + const MAX_FILE_SIZE = 5 * 1024 * 1024; protected string $resource = 'files'; @@ -54,22 +56,4 @@ public function upload(string $filepath, string $type): ResponseInterface return $api->getResponse(); } - - /** - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function create(array $data): ResponseInterface - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @throws BadMethodCallException - */ - public function getAll(): ResponseInterface - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } } diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index 08461e7..0d1720b 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -3,36 +3,21 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; +use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; +use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; use Psr\Http\Message\ResponseInterface; class Invoice extends BaseClient { + use GetTrait; use DocumentClientTrait; + use CreateFinalizeTrait; protected string $resource = 'invoices'; - /** - * @param array[] $data - * @param bool $finalized - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function create(array $data, $finalized = false): ResponseInterface - { - $oldResource = $this->resource; - - $this->resource .= $finalized ? '?finalize=true' : ''; - $response = parent::create($data); - $this->resource = $oldResource; - - return $response; - } - - /** * @return ResponseInterface * @throws CacheException diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 4fbbee9..6aa0676 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -3,13 +3,17 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; +use Clicksports\LexOffice\Clients\Traits\CreateTrait; +use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; use Psr\Http\Message\ResponseInterface; class OrderConfirmation extends BaseClient { + use GetTrait; + use CreateTrait; use DocumentClientTrait; protected string $resource = 'order-confirmations'; diff --git a/src/Clients/Profile.php b/src/Clients/Profile.php index 38aaba1..1d2c60c 100644 --- a/src/Clients/Profile.php +++ b/src/Clients/Profile.php @@ -4,7 +4,6 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -14,44 +13,13 @@ class Profile extends BaseClient protected string $resource = 'profile'; /** - * @param string|null $id (unused) * @return ResponseInterface * @throws CacheException * @throws LexOfficeApiException */ - public function get(string $id = null): ResponseInterface + public function get(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) ->getResponse(); } - - /** - * @throws BadMethodCallException - */ - public function getAll(): ResponseInterface - { - throw new BadMethodCallException('method create is defined for ' . $this->resource); - } - - /** - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function create(array $data): ResponseInterface - { - throw new BadMethodCallException('method create is defined for ' . $this->resource); - } - - - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function update(string $id, array $data): ResponseInterface - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } } diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 2437dcb..9938b27 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -3,35 +3,21 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; +use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; +use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; use Psr\Http\Message\ResponseInterface; class Quotation extends BaseClient { + use GetTrait; use DocumentClientTrait; + use CreateFinalizeTrait; protected string $resource = 'quotations'; - /** - * @param array[] $data - * @param bool $finalized - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function create(array $data, $finalized = false): ResponseInterface - { - $oldResource = $this->resource; - - $this->resource .= $finalized ? '?finalize=true' : ''; - $response = parent::create($data); - $this->resource = $oldResource; - - return $response; - } - /** * @return ResponseInterface * @throws CacheException diff --git a/src/Clients/Traits/CreateFinalizeTrait.php b/src/Clients/Traits/CreateFinalizeTrait.php new file mode 100644 index 0000000..c8b00c3 --- /dev/null +++ b/src/Clients/Traits/CreateFinalizeTrait.php @@ -0,0 +1,22 @@ +api->newRequest('POST', $this->resource . ($finalized ? '?finalize=true' : '')); + + $api->request = $api->request->withBody($this->createStream($data)); + + return $api->getResponse(); + } +} \ No newline at end of file diff --git a/src/Clients/Traits/CreateTrait.php b/src/Clients/Traits/CreateTrait.php new file mode 100644 index 0000000..af1ec88 --- /dev/null +++ b/src/Clients/Traits/CreateTrait.php @@ -0,0 +1,21 @@ +api->newRequest('POST', $this->resource); + + $api->request = $api->request->withBody($this->createStream($data)); + + return $api->getResponse(); + } +} \ No newline at end of file diff --git a/src/Clients/Traits/DeleteTrait.php b/src/Clients/Traits/DeleteTrait.php new file mode 100644 index 0000000..35e5af0 --- /dev/null +++ b/src/Clients/Traits/DeleteTrait.php @@ -0,0 +1,18 @@ +api->newRequest('DELETE', 'event-subscriptions/' . $id) + ->getResponse(); + } +} \ No newline at end of file diff --git a/src/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php similarity index 77% rename from src/Traits/DocumentClientTrait.php rename to src/Clients/Traits/DocumentClientTrait.php index 1091b36..54dbfe5 100644 --- a/src/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -1,10 +1,8 @@ api->newRequest('GET', $this->resource . '/' . $id) + ->getResponse(); + } +} \ No newline at end of file diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php new file mode 100644 index 0000000..0709ba2 --- /dev/null +++ b/src/Clients/Traits/UpdateTrait.php @@ -0,0 +1,22 @@ +api->newRequest('PUT', $this->resource . '/' . $id); + + $api->request = $api->request->withBody($this->createStream($data)); + + return $api->getResponse(); + } +} \ No newline at end of file diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index 7e4759c..7a1bf53 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -3,29 +3,20 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; +use Clicksports\LexOffice\Clients\Traits\CreateTrait; +use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\UpdateTrait; use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Voucher extends BaseClient { - protected string $resource = 'vouchers'; + use CreateTrait; + use GetTrait; + use UpdateTrait; - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function update(string $id, array $data): ResponseInterface - { - $api = $this->api->newRequest('PUT', $this->resource . '/' . $id); - - $api->request = $api->request->withBody($this->createStream($data)); - - return $api->getResponse(); - } + protected string $resource = 'vouchers'; /** * @return ResponseInterface diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index 27c523a..1014626 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -2,9 +2,7 @@ namespace Clicksports\LexOffice\Clients; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\PaginationClient; -use Psr\Http\Message\ResponseInterface; class VoucherList extends PaginationClient { @@ -60,35 +58,4 @@ public function generateUrl(int $page): string '&voucherType=' . implode(',', $this->types) . '&voucherStatus=' . implode(',', $this->statuses); } - - /** - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function create(array $data): ResponseInterface - { - throw new BadMethodCallException('method create is not supported for ' . $this->resource); - } - - /** - * @param string $id - * @param array[] $data - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function update(string $id, array $data): ResponseInterface - { - throw new BadMethodCallException('method update is not supported for ' . $this->resource); - } - - /** - * @param string $id - * @return ResponseInterface - * @throws BadMethodCallException - */ - public function get(string $id): ResponseInterface - { - throw new BadMethodCallException('method get is not supported for ' . $this->resource); - } } diff --git a/src/Exceptions/BadMethodCallException.php b/src/Exceptions/BadMethodCallException.php deleted file mode 100644 index a3d681e..0000000 --- a/src/Exceptions/BadMethodCallException.php +++ /dev/null @@ -1,8 +0,0 @@ -assertEquals('body', $response->getBody()->__toString()); } - public function testGet() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Event::class, - new Response(200, [], 'body'), - ['get'] - ); - - $stub->get('resource-id'); - } - public function testGetAll() { $stub = $this->createClientMockObject( @@ -51,19 +37,6 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Event::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } - public function testDelete() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index 01d75fc..561cfba 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -3,7 +3,6 @@ namespace CliockSports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\File; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; @@ -78,30 +77,4 @@ public function testUpload() $this->assertInstanceOf(ResponseInterface::class, $response); } - - public function testCreate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}'), - ['create'] - ); - - $stub->create([]); - } - - public function testGetAll() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}'), - ['getAll'] - ); - - $stub->getAll(); - } } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 05892f0..856ea92 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\Invoice; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -51,19 +50,6 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Invoice::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } - public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 952841d..e184fdc 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\OrderConfirmation; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -51,19 +50,6 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - OrderConfirmation::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } - public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 512302b..4f6f989 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -3,29 +3,14 @@ namespace Clicksports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\Profile; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; class ProfileTest extends TestClient { - - public function testGetAll() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Profile::class, - new Response(200, [], '{}'), - ['getAll'] - ); - - $stub->getAll(); - } - public function testGet() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMockObject( Profile::class, new Response(200, [], '{}'), ['get'] @@ -36,30 +21,4 @@ public function testGet() $stub->get()->getBody()->__toString() ); } - - public function testCreate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Profile::class, - new Response(200, [], '{}'), - ['create'] - ); - - $stub->create([]); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Profile::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('id', []); - } } diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 811c40c..2f7212f 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\Quotation; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -51,19 +50,6 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Quotation::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } - public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 9c35278..2dc7ab0 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice\Tests\Clients; use Clicksports\LexOffice\Clients\VoucherList; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -26,43 +25,4 @@ public function testGenerateUrl() $stub->generateUrl(0) ); } - - public function testCreate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - VoucherList::class, - new Response(200, [], 'body'), - ['create'] - ); - - $stub->create([]); - } - - public function testGet() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - VoucherList::class, - new Response(200, [], 'body'), - ['get'] - ); - - $stub->get('resource-id'); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - VoucherList::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } } From 96c650e159dc242cee0abdd9b210552819f24dd6 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 28 Feb 2021 16:44:46 +0100 Subject: [PATCH 13/69] refactor new clients --- .gitignore | 2 +- src/Api.php | 24 +++---- src/Clients/Country.php | 26 ++++++++ src/Clients/DownPaymentInvoice.php | 34 ++++++++++ src/Clients/Payment.php | 15 +++++ src/Clients/PaymentCondition.php | 26 ++++++++ src/Country/Client.php | 54 ---------------- src/DownPaymentInvoice/Client.php | 53 --------------- src/Payment/Client.php | 43 ------------- src/PaymentCondition/Client.php | 54 ---------------- tests/ApiTest.php | 12 ++-- tests/Clients/CountryTest.php | 24 +++++++ .../DownPaymentInvoiceTest.php} | 39 ++++------- tests/Clients/PaymentConditionTest.php | 24 +++++++ tests/Clients/PaymentTest.php | 24 +++++++ tests/Country/ClientTest.php | 64 ------------------- tests/Payment/ClientTest.php | 64 ------------------- tests/PaymentCondition/ClientTest.php | 63 ------------------ 18 files changed, 206 insertions(+), 439 deletions(-) create mode 100644 src/Clients/Country.php create mode 100644 src/Clients/DownPaymentInvoice.php create mode 100644 src/Clients/Payment.php create mode 100644 src/Clients/PaymentCondition.php delete mode 100644 src/Country/Client.php delete mode 100644 src/DownPaymentInvoice/Client.php delete mode 100644 src/Payment/Client.php delete mode 100644 src/PaymentCondition/Client.php create mode 100644 tests/Clients/CountryTest.php rename tests/{DownPaymentInvoices/ClientTest.php => Clients/DownPaymentInvoiceTest.php} (65%) create mode 100644 tests/Clients/PaymentConditionTest.php create mode 100644 tests/Clients/PaymentTest.php delete mode 100644 tests/Country/ClientTest.php delete mode 100644 tests/Payment/ClientTest.php delete mode 100644 tests/PaymentCondition/ClientTest.php diff --git a/.gitignore b/.gitignore index c06b02b..1448903 100644 --- a/.gitignore +++ b/.gitignore @@ -102,7 +102,7 @@ crashlytics.properties crashlytics-build.properties fabric.properties -# Editor-based Rest Client +# Editor-based Rest Country .idea/httpRequests # Android studio 3.1+ serialized cache file diff --git a/src/Api.php b/src/Api.php index 3dbc02e..e3b8473 100644 --- a/src/Api.php +++ b/src/Api.php @@ -3,15 +3,15 @@ namespace Clicksports\LexOffice; use Clicksports\LexOffice\Clients\Contact; -use Clicksports\LexOffice\Country\Client as CountryClient; +use Clicksports\LexOffice\Clients\Country; use Clicksports\LexOffice\Clients\CreditNote; -use Clicksports\LexOffice\DownPaymentInvoice\Client as DownPaymentInvoiceClient; +use Clicksports\LexOffice\Clients\DownPaymentInvoice; use Clicksports\LexOffice\Clients\Event; use Clicksports\LexOffice\Clients\File; use Clicksports\LexOffice\Clients\Invoice; use Clicksports\LexOffice\Clients\OrderConfirmation; -use Clicksports\LexOffice\Payment\Client as PaymentClient; -use Clicksports\LexOffice\PaymentCondition\Client as PaymentConditionClient; +use Clicksports\LexOffice\Clients\Payment; +use Clicksports\LexOffice\Clients\PaymentCondition; use Clicksports\LexOffice\Clients\Profile; use Clicksports\LexOffice\Clients\Quotation; use Clicksports\LexOffice\Clients\Voucher; @@ -174,11 +174,11 @@ public function contact() } /** - * @return CountryClient + * @return Country */ public function country() { - return new CountryClient($this); + return new Country($this); } /** @@ -198,11 +198,11 @@ public function invoice() } /** - * @return DownPaymentInvoiceClient + * @return DownPaymentInvoice */ public function downPaymentInvoice() { - return new DownPaymentInvoiceClient($this); + return new DownPaymentInvoice($this); } /** @@ -214,19 +214,19 @@ public function orderConfirmation() } /** - * @return PaymentClient + * @return Payment */ public function payment() { - return new PaymentClient($this); + return new Payment($this); } /** - * @return PaymentConditionClient + * @return PaymentCondition */ public function paymentCondition() { - return new PaymentConditionClient($this); + return new PaymentCondition($this); } /** diff --git a/src/Clients/Country.php b/src/Clients/Country.php new file mode 100644 index 0000000..1773046 --- /dev/null +++ b/src/Clients/Country.php @@ -0,0 +1,26 @@ +api->newRequest('GET', $this->resource) + ->getResponse(); + } +} diff --git a/src/Clients/DownPaymentInvoice.php b/src/Clients/DownPaymentInvoice.php new file mode 100644 index 0000000..84c34b4 --- /dev/null +++ b/src/Clients/DownPaymentInvoice.php @@ -0,0 +1,34 @@ +api); + + $client->setToEverything(); + $client->types = ['downpaymentinvoice']; + + return $client->getAll(); + } +} diff --git a/src/Clients/Payment.php b/src/Clients/Payment.php new file mode 100644 index 0000000..d6b2003 --- /dev/null +++ b/src/Clients/Payment.php @@ -0,0 +1,15 @@ +api->newRequest('GET', $this->resource) + ->getResponse(); + } +} diff --git a/src/Country/Client.php b/src/Country/Client.php deleted file mode 100644 index 38a825f..0000000 --- a/src/Country/Client.php +++ /dev/null @@ -1,54 +0,0 @@ -resource); - } - - /** - * @param string $id - * @throws BadMethodCallException - */ - public function get(string $id) - { - throw new BadMethodCallException('method get is defined for ' . $this->resource); - } - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function getAll() - { - return $this->api->newRequest('GET', $this->resource) - ->getResponse(); - } -} diff --git a/src/DownPaymentInvoice/Client.php b/src/DownPaymentInvoice/Client.php deleted file mode 100644 index 2f088fb..0000000 --- a/src/DownPaymentInvoice/Client.php +++ /dev/null @@ -1,53 +0,0 @@ -resource); - } - - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function getAll() - { - $client = new VoucherlistClient($this->api); - - $client->setToEverything(); - $client->types = ['downpaymentinvoice']; - - return $client->getAll(); - } -} diff --git a/src/Payment/Client.php b/src/Payment/Client.php deleted file mode 100644 index 9f2143a..0000000 --- a/src/Payment/Client.php +++ /dev/null @@ -1,43 +0,0 @@ -resource); - } - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @throws BadMethodCallException - */ - public function getAll() - { - throw new BadMethodCallException('method getAll is defined for ' . $this->resource); - } -} diff --git a/src/PaymentCondition/Client.php b/src/PaymentCondition/Client.php deleted file mode 100644 index b70b35c..0000000 --- a/src/PaymentCondition/Client.php +++ /dev/null @@ -1,54 +0,0 @@ -resource); - } - - /** - * @param string $id - * @throws BadMethodCallException - */ - public function get(string $id) - { - throw new BadMethodCallException('method get is defined for ' . $this->resource); - } - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function getAll() - { - return $this->api->newRequest('GET', $this->resource) - ->getResponse(); - } -} diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 5508649..8b4e681 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -3,11 +3,15 @@ namespace Clicksports\LexOffice\Tests; use Clicksports\LexOffice\Clients\Contact; +use Clicksports\LexOffice\Clients\Country; use Clicksports\LexOffice\Clients\CreditNote; +use Clicksports\LexOffice\Clients\DownPaymentInvoice; use Clicksports\LexOffice\Clients\Event; use Clicksports\LexOffice\Clients\File; use Clicksports\LexOffice\Clients\Invoice; use Clicksports\LexOffice\Clients\OrderConfirmation; +use Clicksports\LexOffice\Clients\Payment; +use Clicksports\LexOffice\Clients\PaymentCondition; use Clicksports\LexOffice\Clients\Profile; use Clicksports\LexOffice\Clients\Quotation; use Clicksports\LexOffice\Clients\Voucher; @@ -44,19 +48,19 @@ public function testClients() 'file' ]); - $this->assertInstanceOf(\Clicksports\LexOffice\Country\Client::class, $stub->country()); + $this->assertInstanceOf(Country::class, $stub->country()); $this->assertInstanceOf(Contact::class, $stub->contact()); $this->assertInstanceOf(Event::class, $stub->event()); $this->assertInstanceOf(Invoice::class, $stub->invoice()); - $this->assertInstanceOf(\Clicksports\LexOffice\DownPaymentInvoice\Client::class, $stub->downPaymentInvoice()); + $this->assertInstanceOf(DownPaymentInvoice::class, $stub->downPaymentInvoice()); $this->assertInstanceOf(OrderConfirmation::class, $stub->orderConfirmation()); $this->assertInstanceOf(Quotation::class, $stub->quotation()); $this->assertInstanceOf(Voucher::class, $stub->voucher()); $this->assertInstanceOf(VoucherList::class, $stub->voucherlist()); $this->assertInstanceOf(Profile::class, $stub->profile()); $this->assertInstanceOf(CreditNote::class, $stub->creditNote()); - $this->assertInstanceOf(\Clicksports\LexOffice\Payment\Client::class, $stub->payment()); - $this->assertInstanceOf(\Clicksports\LexOffice\PaymentCondition\Client::class, $stub->paymentCondition()); + $this->assertInstanceOf(Payment::class, $stub->payment()); + $this->assertInstanceOf(PaymentCondition::class, $stub->paymentCondition()); $this->assertInstanceOf(File::class, $stub->file()); } diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php new file mode 100644 index 0000000..f0d3e69 --- /dev/null +++ b/tests/Clients/CountryTest.php @@ -0,0 +1,24 @@ +createClientMockObject( + Country::class, + new Response(200, [], '{"content": [], "totalPages": 1}'), + ['getAll'] + ); + + $response = $stub->getAll(); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } +} diff --git a/tests/DownPaymentInvoices/ClientTest.php b/tests/Clients/DownPaymentInvoiceTest.php similarity index 65% rename from tests/DownPaymentInvoices/ClientTest.php rename to tests/Clients/DownPaymentInvoiceTest.php index 4d06ff3..3460ef7 100644 --- a/tests/DownPaymentInvoices/ClientTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -1,46 +1,31 @@ expectException(BadMethodCallException::class); - $stub = $this->createClientMockObject( - Client::class, + DownPaymentInvoice::class, new Response(200, [], 'body'), - ['create'] + ['get'] ); - $stub->create([ - 'version' => 0 - ]); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['update'] - ); + $response = $stub->get('resource-id'); - $stub->update('resource-id', []); + $this->assertEquals('body', $response->getBody()->__toString()); } public function testGetAll() { $stub = $this->createClientMockObject( - Client::class, + DownPaymentInvoice::class, new Response(200, [], '{"content": [], "totalPages": 1}'), ['getAll'] ); @@ -53,7 +38,7 @@ public function testGetAll() public function testDocument() { $stub = $this->createClientMockObject( - Client::class, + DownPaymentInvoice::class, new Response(200, [], '{"documentFileId": "fake-id"}'), ['document'] ); @@ -66,7 +51,7 @@ public function testDocument() ); $stub = $this->createClientMultiMockObject( - Client::class, + DownPaymentInvoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') diff --git a/tests/Clients/PaymentConditionTest.php b/tests/Clients/PaymentConditionTest.php new file mode 100644 index 0000000..d550803 --- /dev/null +++ b/tests/Clients/PaymentConditionTest.php @@ -0,0 +1,24 @@ +createClientMockObject( + PaymentCondition::class, + new Response(200, [], '{"content": [], "totalPages": 1}'), + ['getAll'] + ); + + $response = $stub->getAll(); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } +} diff --git a/tests/Clients/PaymentTest.php b/tests/Clients/PaymentTest.php new file mode 100644 index 0000000..3e5c500 --- /dev/null +++ b/tests/Clients/PaymentTest.php @@ -0,0 +1,24 @@ +createClientMockObject( + Payment::class, + new Response(200, [], 'body'), + ['get'] + ); + + $response = $stub->get('resource-id'); + + $this->assertEquals('body', $response->getBody()->__toString()); + } +} diff --git a/tests/Country/ClientTest.php b/tests/Country/ClientTest.php deleted file mode 100644 index 3c064a9..0000000 --- a/tests/Country/ClientTest.php +++ /dev/null @@ -1,64 +0,0 @@ -expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['create'] - ); - - $stub->create([]); - } - - public function testGet() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['get'] - ); - - $stub->get('resource-id'); - } - - public function testGetAll() - { - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] - ); - - $response = $stub->getAll(); - - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } -} diff --git a/tests/Payment/ClientTest.php b/tests/Payment/ClientTest.php deleted file mode 100644 index cd95e62..0000000 --- a/tests/Payment/ClientTest.php +++ /dev/null @@ -1,64 +0,0 @@ -expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['create'] - ); - - $stub->create([]); - } - - public function testGet() - { - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['get'] - ); - - $response = $stub->get('resource-id'); - - $this->assertEquals('body', $response->getBody()->__toString()); - } - - public function testGetAll() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['getAll'] - ); - - $stub->getAll(); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } -} diff --git a/tests/PaymentCondition/ClientTest.php b/tests/PaymentCondition/ClientTest.php deleted file mode 100644 index 7ad522d..0000000 --- a/tests/PaymentCondition/ClientTest.php +++ /dev/null @@ -1,63 +0,0 @@ -expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['create'] - ); - - $stub->create([]); - } - - public function testGet() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['get'] - ); - - $stub->get('resource-id'); - } - - public function testGetAll() - { - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] - ); - - $response = $stub->getAll(); - - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } -} From a735d03959e78030edaec746975bff76388e8e87 Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 28 Feb 2021 16:52:27 +0100 Subject: [PATCH 14/69] add declare strict types --- src/Clients/Country.php | 3 +-- src/Clients/DownPaymentInvoice.php | 4 ++-- src/Clients/Payment.php | 2 +- src/Clients/PaymentCondition.php | 5 ++--- tests/Clients/CountryTest.php | 2 +- tests/Clients/DownPaymentInvoiceTest.php | 2 +- tests/Clients/PaymentConditionTest.php | 2 +- tests/Clients/PaymentTest.php | 2 +- 8 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Clients/Country.php b/src/Clients/Country.php index 1773046..cbd3124 100644 --- a/src/Clients/Country.php +++ b/src/Clients/Country.php @@ -1,5 +1,4 @@ -api); diff --git a/src/Clients/Payment.php b/src/Clients/Payment.php index d6b2003..0e2efd3 100644 --- a/src/Clients/Payment.php +++ b/src/Clients/Payment.php @@ -1,4 +1,4 @@ -api->newRequest('GET', $this->resource) ->getResponse(); diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php index f0d3e69..b25a770 100644 --- a/tests/Clients/CountryTest.php +++ b/tests/Clients/CountryTest.php @@ -1,4 +1,4 @@ - Date: Sun, 28 Feb 2021 17:17:22 +0100 Subject: [PATCH 15/69] fix phpstan --- .github/workflows/shepherd.yml | 2 +- composer.lock | 168 +++++++++++++++++---------------- src/Utils.php | 10 +- 3 files changed, 92 insertions(+), 88 deletions(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 53d541d..29f4aef 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan analyse --ansi --error-format symplify" \ No newline at end of file + run: ./vendor/bin/phpstan analyse --ansi --error-format github" \ No newline at end of file diff --git a/composer.lock b/composer.lock index ae1be98..09ebc9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f60264785f87f2e7d2db90c6bb039309", + "content-hash": "57d668bda7ef12147e6730f6598b6b3f", "packages": [ { "name": "guzzlehttp/guzzle", @@ -567,16 +567,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.2", + "version": "v4.10.4", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de" + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", "shasum": "" }, "require": { @@ -617,9 +617,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" }, - "time": "2020-09-26T10:30:38+00:00" + "time": "2020-12-20T10:01:03+00:00" }, { "name": "phar-io/manifest", @@ -683,16 +683,16 @@ }, { "name": "phar-io/version", - "version": "3.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0" + "reference": "bae7c545bef187884426f042434e561ab1ddb182" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/c6bb6825def89e0a32220f88337f8ceaf1975fa0", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0", + "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", + "reference": "bae7c545bef187884426f042434e561ab1ddb182", "shasum": "" }, "require": { @@ -728,9 +728,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/master" + "source": "https://github.com/phar-io/version/tree/3.1.0" }, - "time": "2020-06-27T14:39:04+00:00" + "time": "2021-02-23T14:00:09+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -892,16 +892,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.1", + "version": "1.12.2", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d" + "reference": "245710e971a030f42e08f4912863805570f23d39" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8ce87516be71aae9b956f81906aaf0338e0d8a2d", - "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", + "reference": "245710e971a030f42e08f4912863805570f23d39", "shasum": "" }, "require": { @@ -913,7 +913,7 @@ }, "require-dev": { "phpspec/phpspec": "^6.0", - "phpunit/phpunit": "^8.0 || ^9.0 <9.3" + "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { @@ -953,22 +953,22 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.1" + "source": "https://github.com/phpspec/prophecy/tree/1.12.2" }, - "time": "2020-09-29T09:10:42+00:00" + "time": "2020-12-19T10:15:11+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.57", + "version": "0.12.79", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b" + "reference": "dd7769915648b704b9bd12925994457f1c2c8442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", - "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dd7769915648b704b9bd12925994457f1c2c8442", + "reference": "dd7769915648b704b9bd12925994457f1c2c8442", "shasum": "" }, "require": { @@ -999,7 +999,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.57" + "source": "https://github.com/phpstan/phpstan/tree/0.12.79" }, "funding": [ { @@ -1015,20 +1015,20 @@ "type": "tidelift" } ], - "time": "2020-11-21T12:53:28+00:00" + "time": "2021-02-25T16:44:57+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.3", + "version": "9.2.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41" + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6b20e2055f7c29b56cb3870b3de7cc463d7add41", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", "shasum": "" }, "require": { @@ -1042,7 +1042,7 @@ "sebastian/code-unit-reverse-lookup": "^2.0.2", "sebastian/complexity": "^2.0", "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0", + "sebastian/lines-of-code": "^1.0.3", "sebastian/version": "^3.0.1", "theseer/tokenizer": "^1.2.0" }, @@ -1084,7 +1084,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.3" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" }, "funding": [ { @@ -1092,7 +1092,7 @@ "type": "github" } ], - "time": "2020-10-30T10:46:41+00:00" + "time": "2020-11-28T06:44:49+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1337,16 +1337,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.4.3", + "version": "9.5.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab" + "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab", - "reference": "9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", + "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", "shasum": "" }, "require": { @@ -1362,7 +1362,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2", + "phpunit/php-code-coverage": "^9.2.3", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1393,7 +1393,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.4-dev" + "dev-master": "9.5-dev" } }, "autoload": { @@ -1424,7 +1424,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.4.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.2" }, "funding": [ { @@ -1436,7 +1436,7 @@ "type": "github" } ], - "time": "2020-11-10T12:53:30+00:00" + "time": "2021-02-02T14:45:58+00:00" }, { "name": "psr/container", @@ -2111,16 +2111,16 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "acf76492a65401babcf5283296fa510782783a7a" + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/acf76492a65401babcf5283296fa510782783a7a", - "reference": "acf76492a65401babcf5283296fa510782783a7a", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", "shasum": "" }, "require": { @@ -2156,7 +2156,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.2" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" }, "funding": [ { @@ -2164,7 +2164,7 @@ "type": "github" } ], - "time": "2020-10-26T17:03:56+00:00" + "time": "2020-11-28T06:42:11+00:00" }, { "name": "sebastian/object-enumerator", @@ -2507,29 +2507,29 @@ }, { "name": "symfony/cache", - "version": "v5.1.8", + "version": "v5.2.3", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "d7bc33e9f9028f49f87057e7944c076d9593f046" + "reference": "d6aed6c1bbf6f59e521f46437475a0ff4878d388" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/d7bc33e9f9028f49f87057e7944c076d9593f046", - "reference": "d7bc33e9f9028f49f87057e7944c076d9593f046", + "url": "https://api.github.com/repos/symfony/cache/zipball/d6aed6c1bbf6f59e521f46437475a0ff4878d388", + "reference": "d6aed6c1bbf6f59e521f46437475a0ff4878d388", "shasum": "" }, "require": { "php": ">=7.2.5", "psr/cache": "~1.0", - "psr/log": "~1.0", + "psr/log": "^1.1", "symfony/cache-contracts": "^1.1.7|^2", "symfony/polyfill-php80": "^1.15", "symfony/service-contracts": "^1.1|^2", "symfony/var-exporter": "^4.4|^5.0" }, "conflict": { - "doctrine/dbal": "<2.5", + "doctrine/dbal": "<2.10", "symfony/dependency-injection": "<4.4", "symfony/http-kernel": "<4.4", "symfony/var-dumper": "<4.4" @@ -2542,12 +2542,14 @@ "require-dev": { "cache/integration-tests": "dev-master", "doctrine/cache": "^1.6", - "doctrine/dbal": "^2.5|^3.0", + "doctrine/dbal": "^2.10|^3.0", "predis/predis": "^1.1", "psr/simple-cache": "^1.0", "symfony/config": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/messenger": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0" }, "type": "library", @@ -2573,14 +2575,14 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Cache component with PSR-6, PSR-16, and tags", + "description": "Provides an extended PSR-6, PSR-16 (and tags) implementation", "homepage": "https://symfony.com", "keywords": [ "caching", "psr6" ], "support": { - "source": "https://github.com/symfony/cache/tree/v5.1.8" + "source": "https://github.com/symfony/cache/tree/v5.2.3" }, "funding": [ { @@ -2596,7 +2598,7 @@ "type": "tidelift" } ], - "time": "2020-10-25T23:21:56+00:00" + "time": "2021-01-27T11:24:50+00:00" }, { "name": "symfony/cache-contracts", @@ -2679,16 +2681,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.20.0", + "version": "v1.22.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41" + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f4ba089a5b6366e453971d3aad5fe8e897b37f41", - "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", "shasum": "" }, "require": { @@ -2700,7 +2702,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.20-dev" + "dev-main": "1.22-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2738,7 +2740,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.20.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" }, "funding": [ { @@ -2754,20 +2756,20 @@ "type": "tidelift" } ], - "time": "2020-10-23T14:02:19+00:00" + "time": "2021-01-07T16:49:33+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.20.0", + "version": "v1.22.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de" + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/e70aa8b064c5b72d3df2abd5ab1e90464ad009de", - "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91", + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91", "shasum": "" }, "require": { @@ -2776,7 +2778,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.20-dev" + "dev-main": "1.22-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2821,7 +2823,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.20.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1" }, "funding": [ { @@ -2837,7 +2839,7 @@ "type": "tidelift" } ], - "time": "2020-10-23T14:02:19+00:00" + "time": "2021-01-07T16:49:33+00:00" }, { "name": "symfony/service-contracts", @@ -2920,16 +2922,16 @@ }, { "name": "symfony/var-exporter", - "version": "v5.1.8", + "version": "v5.2.3", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "b4048bfc6248413592462c029381bdb2f7b6525f" + "reference": "5aed4875ab514c8cb9b6ff4772baa25fa4c10307" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/b4048bfc6248413592462c029381bdb2f7b6525f", - "reference": "b4048bfc6248413592462c029381bdb2f7b6525f", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/5aed4875ab514c8cb9b6ff4772baa25fa4c10307", + "reference": "5aed4875ab514c8cb9b6ff4772baa25fa4c10307", "shasum": "" }, "require": { @@ -2962,7 +2964,7 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code", + "description": "Allows exporting any serializable PHP data structure to plain PHP code", "homepage": "https://symfony.com", "keywords": [ "clone", @@ -2973,7 +2975,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v5.1.8" + "source": "https://github.com/symfony/var-exporter/tree/v5.2.3" }, "funding": [ { @@ -2989,7 +2991,7 @@ "type": "tidelift" } ], - "time": "2020-10-24T12:01:57+00:00" + "time": "2021-01-27T10:01:46+00:00" }, { "name": "theseer/tokenizer", @@ -3046,12 +3048,12 @@ "version": "1.9.1", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, @@ -3089,8 +3091,8 @@ "validate" ], "support": { - "issues": "https://github.com/webmozart/assert/issues", - "source": "https://github.com/webmozart/assert/tree/master" + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.9.1" }, "time": "2020-07-08T17:02:28+00:00" } @@ -3101,7 +3103,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.4", + "php": "^7.4 | ^8", "ext-json": "*", "ext-curl": "*" }, diff --git a/src/Utils.php b/src/Utils.php index def7c55..4af7063 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -5,30 +5,32 @@ use GuzzleHttp\Psr7\Stream; +use InvalidArgumentException; class Utils { /** * @param string $resource - * @param array $options + * @param array{size?: int, metadata?: array, mode?: bool, seekable?: bool} $options * @return Stream */ public static function streamFor($resource = '', array $options = []): Stream { if (is_scalar($resource)) { $stream = fopen('php://temp', 'r+'); - if ($resource !== '') { + if ($resource !== '' && $stream) { fwrite($stream, $resource); fseek($stream, 0); + + return new Stream($stream, $options); } - return new Stream($stream, $options); } throw new InvalidArgumentException('Invalid resource type: ' . gettype($resource)); } /** - * @param $value + * @param mixed $value * @param int $options * @param int $depth * @return string From c2478d149dc4918a67722ab3ff605b803e52ad6b Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 28 Feb 2021 17:27:47 +0100 Subject: [PATCH 16/69] fix phpstan + merge --- .github/workflows/shepherd.yml | 2 +- composer.lock | 168 +++++++++++++++--------------- src/Country/Client.php | 11 +- src/DownPaymentInvoice/Client.php | 8 +- src/Payment/Client.php | 12 +-- src/PaymentCondition/Client.php | 11 +- 6 files changed, 110 insertions(+), 102 deletions(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 53d541d..336bd62 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -13,4 +13,4 @@ jobs: run: composer install --prefer-dist --no-progress --no-suggest - name: Run Psalm - run: ./vendor/bin/phpstan analyse --ansi --error-format symplify" \ No newline at end of file + run: ./vendor/bin/phpstan analyse --ansi --error-format github \ No newline at end of file diff --git a/composer.lock b/composer.lock index ae1be98..09ebc9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f60264785f87f2e7d2db90c6bb039309", + "content-hash": "57d668bda7ef12147e6730f6598b6b3f", "packages": [ { "name": "guzzlehttp/guzzle", @@ -567,16 +567,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.2", + "version": "v4.10.4", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de" + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", - "reference": "658f1be311a230e0907f5dfe0213742aff0596de", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", "shasum": "" }, "require": { @@ -617,9 +617,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.2" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" }, - "time": "2020-09-26T10:30:38+00:00" + "time": "2020-12-20T10:01:03+00:00" }, { "name": "phar-io/manifest", @@ -683,16 +683,16 @@ }, { "name": "phar-io/version", - "version": "3.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/phar-io/version.git", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0" + "reference": "bae7c545bef187884426f042434e561ab1ddb182" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/c6bb6825def89e0a32220f88337f8ceaf1975fa0", - "reference": "c6bb6825def89e0a32220f88337f8ceaf1975fa0", + "url": "https://api.github.com/repos/phar-io/version/zipball/bae7c545bef187884426f042434e561ab1ddb182", + "reference": "bae7c545bef187884426f042434e561ab1ddb182", "shasum": "" }, "require": { @@ -728,9 +728,9 @@ "description": "Library for handling version information and constraints", "support": { "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/master" + "source": "https://github.com/phar-io/version/tree/3.1.0" }, - "time": "2020-06-27T14:39:04+00:00" + "time": "2021-02-23T14:00:09+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -892,16 +892,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.12.1", + "version": "1.12.2", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d" + "reference": "245710e971a030f42e08f4912863805570f23d39" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8ce87516be71aae9b956f81906aaf0338e0d8a2d", - "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", + "reference": "245710e971a030f42e08f4912863805570f23d39", "shasum": "" }, "require": { @@ -913,7 +913,7 @@ }, "require-dev": { "phpspec/phpspec": "^6.0", - "phpunit/phpunit": "^8.0 || ^9.0 <9.3" + "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { @@ -953,22 +953,22 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/1.12.1" + "source": "https://github.com/phpspec/prophecy/tree/1.12.2" }, - "time": "2020-09-29T09:10:42+00:00" + "time": "2020-12-19T10:15:11+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.57", + "version": "0.12.79", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b" + "reference": "dd7769915648b704b9bd12925994457f1c2c8442" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", - "reference": "f9909d1d0c44b4cbaf72babcf80e8f14d6fdd55b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dd7769915648b704b9bd12925994457f1c2c8442", + "reference": "dd7769915648b704b9bd12925994457f1c2c8442", "shasum": "" }, "require": { @@ -999,7 +999,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.57" + "source": "https://github.com/phpstan/phpstan/tree/0.12.79" }, "funding": [ { @@ -1015,20 +1015,20 @@ "type": "tidelift" } ], - "time": "2020-11-21T12:53:28+00:00" + "time": "2021-02-25T16:44:57+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.3", + "version": "9.2.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41" + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6b20e2055f7c29b56cb3870b3de7cc463d7add41", - "reference": "6b20e2055f7c29b56cb3870b3de7cc463d7add41", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", + "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", "shasum": "" }, "require": { @@ -1042,7 +1042,7 @@ "sebastian/code-unit-reverse-lookup": "^2.0.2", "sebastian/complexity": "^2.0", "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0", + "sebastian/lines-of-code": "^1.0.3", "sebastian/version": "^3.0.1", "theseer/tokenizer": "^1.2.0" }, @@ -1084,7 +1084,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.3" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.5" }, "funding": [ { @@ -1092,7 +1092,7 @@ "type": "github" } ], - "time": "2020-10-30T10:46:41+00:00" + "time": "2020-11-28T06:44:49+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1337,16 +1337,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.4.3", + "version": "9.5.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab" + "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab", - "reference": "9fa359ff5ddaa5eb2be2bedb08a6a5787a5807ab", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", + "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", "shasum": "" }, "require": { @@ -1362,7 +1362,7 @@ "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2", + "phpunit/php-code-coverage": "^9.2.3", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1393,7 +1393,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.4-dev" + "dev-master": "9.5-dev" } }, "autoload": { @@ -1424,7 +1424,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.4.3" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.2" }, "funding": [ { @@ -1436,7 +1436,7 @@ "type": "github" } ], - "time": "2020-11-10T12:53:30+00:00" + "time": "2021-02-02T14:45:58+00:00" }, { "name": "psr/container", @@ -2111,16 +2111,16 @@ }, { "name": "sebastian/lines-of-code", - "version": "1.0.2", + "version": "1.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "acf76492a65401babcf5283296fa510782783a7a" + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/acf76492a65401babcf5283296fa510782783a7a", - "reference": "acf76492a65401babcf5283296fa510782783a7a", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", "shasum": "" }, "require": { @@ -2156,7 +2156,7 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.2" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" }, "funding": [ { @@ -2164,7 +2164,7 @@ "type": "github" } ], - "time": "2020-10-26T17:03:56+00:00" + "time": "2020-11-28T06:42:11+00:00" }, { "name": "sebastian/object-enumerator", @@ -2507,29 +2507,29 @@ }, { "name": "symfony/cache", - "version": "v5.1.8", + "version": "v5.2.3", "source": { "type": "git", "url": "https://github.com/symfony/cache.git", - "reference": "d7bc33e9f9028f49f87057e7944c076d9593f046" + "reference": "d6aed6c1bbf6f59e521f46437475a0ff4878d388" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/d7bc33e9f9028f49f87057e7944c076d9593f046", - "reference": "d7bc33e9f9028f49f87057e7944c076d9593f046", + "url": "https://api.github.com/repos/symfony/cache/zipball/d6aed6c1bbf6f59e521f46437475a0ff4878d388", + "reference": "d6aed6c1bbf6f59e521f46437475a0ff4878d388", "shasum": "" }, "require": { "php": ">=7.2.5", "psr/cache": "~1.0", - "psr/log": "~1.0", + "psr/log": "^1.1", "symfony/cache-contracts": "^1.1.7|^2", "symfony/polyfill-php80": "^1.15", "symfony/service-contracts": "^1.1|^2", "symfony/var-exporter": "^4.4|^5.0" }, "conflict": { - "doctrine/dbal": "<2.5", + "doctrine/dbal": "<2.10", "symfony/dependency-injection": "<4.4", "symfony/http-kernel": "<4.4", "symfony/var-dumper": "<4.4" @@ -2542,12 +2542,14 @@ "require-dev": { "cache/integration-tests": "dev-master", "doctrine/cache": "^1.6", - "doctrine/dbal": "^2.5|^3.0", + "doctrine/dbal": "^2.10|^3.0", "predis/predis": "^1.1", "psr/simple-cache": "^1.0", "symfony/config": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0", "symfony/filesystem": "^4.4|^5.0", + "symfony/http-kernel": "^4.4|^5.0", + "symfony/messenger": "^4.4|^5.0", "symfony/var-dumper": "^4.4|^5.0" }, "type": "library", @@ -2573,14 +2575,14 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "Symfony Cache component with PSR-6, PSR-16, and tags", + "description": "Provides an extended PSR-6, PSR-16 (and tags) implementation", "homepage": "https://symfony.com", "keywords": [ "caching", "psr6" ], "support": { - "source": "https://github.com/symfony/cache/tree/v5.1.8" + "source": "https://github.com/symfony/cache/tree/v5.2.3" }, "funding": [ { @@ -2596,7 +2598,7 @@ "type": "tidelift" } ], - "time": "2020-10-25T23:21:56+00:00" + "time": "2021-01-27T11:24:50+00:00" }, { "name": "symfony/cache-contracts", @@ -2679,16 +2681,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.20.0", + "version": "v1.22.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41" + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/f4ba089a5b6366e453971d3aad5fe8e897b37f41", - "reference": "f4ba089a5b6366e453971d3aad5fe8e897b37f41", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", "shasum": "" }, "require": { @@ -2700,7 +2702,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.20-dev" + "dev-main": "1.22-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2738,7 +2740,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.20.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" }, "funding": [ { @@ -2754,20 +2756,20 @@ "type": "tidelift" } ], - "time": "2020-10-23T14:02:19+00:00" + "time": "2021-01-07T16:49:33+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.20.0", + "version": "v1.22.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de" + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/e70aa8b064c5b72d3df2abd5ab1e90464ad009de", - "reference": "e70aa8b064c5b72d3df2abd5ab1e90464ad009de", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dc3063ba22c2a1fd2f45ed856374d79114998f91", + "reference": "dc3063ba22c2a1fd2f45ed856374d79114998f91", "shasum": "" }, "require": { @@ -2776,7 +2778,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.20-dev" + "dev-main": "1.22-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2821,7 +2823,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.20.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.22.1" }, "funding": [ { @@ -2837,7 +2839,7 @@ "type": "tidelift" } ], - "time": "2020-10-23T14:02:19+00:00" + "time": "2021-01-07T16:49:33+00:00" }, { "name": "symfony/service-contracts", @@ -2920,16 +2922,16 @@ }, { "name": "symfony/var-exporter", - "version": "v5.1.8", + "version": "v5.2.3", "source": { "type": "git", "url": "https://github.com/symfony/var-exporter.git", - "reference": "b4048bfc6248413592462c029381bdb2f7b6525f" + "reference": "5aed4875ab514c8cb9b6ff4772baa25fa4c10307" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/b4048bfc6248413592462c029381bdb2f7b6525f", - "reference": "b4048bfc6248413592462c029381bdb2f7b6525f", + "url": "https://api.github.com/repos/symfony/var-exporter/zipball/5aed4875ab514c8cb9b6ff4772baa25fa4c10307", + "reference": "5aed4875ab514c8cb9b6ff4772baa25fa4c10307", "shasum": "" }, "require": { @@ -2962,7 +2964,7 @@ "homepage": "https://symfony.com/contributors" } ], - "description": "A blend of var_export() + serialize() to turn any serializable data structure to plain PHP code", + "description": "Allows exporting any serializable PHP data structure to plain PHP code", "homepage": "https://symfony.com", "keywords": [ "clone", @@ -2973,7 +2975,7 @@ "serialize" ], "support": { - "source": "https://github.com/symfony/var-exporter/tree/v5.1.8" + "source": "https://github.com/symfony/var-exporter/tree/v5.2.3" }, "funding": [ { @@ -2989,7 +2991,7 @@ "type": "tidelift" } ], - "time": "2020-10-24T12:01:57+00:00" + "time": "2021-01-27T10:01:46+00:00" }, { "name": "theseer/tokenizer", @@ -3046,12 +3048,12 @@ "version": "1.9.1", "source": { "type": "git", - "url": "https://github.com/webmozart/assert.git", + "url": "https://github.com/webmozarts/assert.git", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/bafc69caeb4d49c39fd0779086c03a3738cbb389", "reference": "bafc69caeb4d49c39fd0779086c03a3738cbb389", "shasum": "" }, @@ -3089,8 +3091,8 @@ "validate" ], "support": { - "issues": "https://github.com/webmozart/assert/issues", - "source": "https://github.com/webmozart/assert/tree/master" + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.9.1" }, "time": "2020-07-08T17:02:28+00:00" } @@ -3101,7 +3103,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^7.4", + "php": "^7.4 | ^8", "ext-json": "*", "ext-curl": "*" }, diff --git a/src/Country/Client.php b/src/Country/Client.php index 38a825f..edf95a1 100644 --- a/src/Country/Client.php +++ b/src/Country/Client.php @@ -15,18 +15,20 @@ class Client extends BaseClient /*** * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } /** * @param string $id + * @return ResponseInterface * @throws BadMethodCallException */ - public function get(string $id) + public function get(string $id): ResponseInterface { throw new BadMethodCallException('method get is defined for ' . $this->resource); } @@ -34,9 +36,10 @@ public function get(string $id) /** * @param string $id * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } @@ -46,7 +49,7 @@ public function update(string $id, array $data) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) ->getResponse(); diff --git a/src/DownPaymentInvoice/Client.php b/src/DownPaymentInvoice/Client.php index 2f088fb..9cdc3b1 100644 --- a/src/DownPaymentInvoice/Client.php +++ b/src/DownPaymentInvoice/Client.php @@ -18,9 +18,10 @@ class Client extends BaseClient /** * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } @@ -29,9 +30,10 @@ public function create(array $data) /** * @param string $id * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } @@ -41,7 +43,7 @@ public function update(string $id, array $data) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { $client = new VoucherlistClient($this->api); diff --git a/src/Payment/Client.php b/src/Payment/Client.php index 9f2143a..b9d38db 100644 --- a/src/Payment/Client.php +++ b/src/Payment/Client.php @@ -4,10 +4,6 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Exceptions\CacheException; -use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Voucherlist\Client as VoucherlistClient; use Psr\Http\Message\ResponseInterface; class Client extends BaseClient @@ -16,9 +12,10 @@ class Client extends BaseClient /*** * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } @@ -26,9 +23,10 @@ public function create(array $data) /** * @param string $id * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } @@ -36,7 +34,7 @@ public function update(string $id, array $data) /** * @throws BadMethodCallException */ - public function getAll() + public function getAll(): ResponseInterface { throw new BadMethodCallException('method getAll is defined for ' . $this->resource); } diff --git a/src/PaymentCondition/Client.php b/src/PaymentCondition/Client.php index b70b35c..630ab45 100644 --- a/src/PaymentCondition/Client.php +++ b/src/PaymentCondition/Client.php @@ -15,18 +15,20 @@ class Client extends BaseClient /*** * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function create(array $data) + public function create(array $data): ResponseInterface { throw new BadMethodCallException('method create is defined for ' . $this->resource); } /** * @param string $id + * @return ResponseInterface * @throws BadMethodCallException */ - public function get(string $id) + public function get(string $id): ResponseInterface { throw new BadMethodCallException('method get is defined for ' . $this->resource); } @@ -34,9 +36,10 @@ public function get(string $id) /** * @param string $id * @param array $data + * @return ResponseInterface * @throws BadMethodCallException */ - public function update(string $id, array $data) + public function update(string $id, array $data): ResponseInterface { throw new BadMethodCallException('method update is defined for ' . $this->resource); } @@ -46,7 +49,7 @@ public function update(string $id, array $data) * @throws CacheException * @throws LexOfficeApiException */ - public function getAll() + public function getAll(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) ->getResponse(); From 988f848ca2f6a2165ea1302983caa081413d93ce Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 28 Feb 2021 18:10:44 +0100 Subject: [PATCH 17/69] fix delete Trait + composer scripts --- composer.json | 4 ++++ src/Clients/Traits/DeleteTrait.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 54a01fd..b0e88dd 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,10 @@ "name": "clicksports/lex-office-api", "type": "library", "description": "Simple API Integration for Lex-Office", + "scripts": { + "test": "phpunit", + "lint": "phpstan analyse --ansi --error-format raw" + }, "keywords": [ "lex-office", "lexoffice", diff --git a/src/Clients/Traits/DeleteTrait.php b/src/Clients/Traits/DeleteTrait.php index 35e5af0..ab112c5 100644 --- a/src/Clients/Traits/DeleteTrait.php +++ b/src/Clients/Traits/DeleteTrait.php @@ -12,7 +12,7 @@ trait DeleteTrait */ public function delete(string $id): ResponseInterface { - return $this->api->newRequest('DELETE', 'event-subscriptions/' . $id) + return $this->api->newRequest('DELETE', $this->resource . '/' . $id) ->getResponse(); } } \ No newline at end of file From e8c6c347c92f850382b0e6e1ccd2be5514418b2e Mon Sep 17 00:00:00 2001 From: Alexander S Date: Sun, 28 Feb 2021 18:45:08 +0100 Subject: [PATCH 18/69] fix test cache dir missing --- tests/Clients/FileTest.php | 6 ++++-- tests/TestClient.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index 561cfba..fd77ec7 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -46,7 +46,8 @@ public function testUploadToBig() ['upload'] ); - $file = __DIR__ . '/../cache/somefile.jpg'; + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); @@ -65,7 +66,8 @@ public function testUpload() ['upload'] ); - $file = __DIR__ . '/../cache/somefile2.jpg'; + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile2.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); diff --git a/tests/TestClient.php b/tests/TestClient.php index c8395c3..7d31a53 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -127,4 +127,18 @@ public function setProtectedProperty(object $object, string $property, $value) $reflection_property->setAccessible(true); $reflection_property->setValue($object, $value); } + + public function createCacheDir(): void + { + $dir = $this->getCacheDir(); + + if (!is_dir($dir)) { + mkdir($dir); + } + } + + public function getCacheDir(): string + { + return __DIR__ . '/cache'; + } } \ No newline at end of file From a1e23df9d1a3e830ddf977347dd596a8f3d88f09 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Mon, 9 Aug 2021 22:40:27 +0200 Subject: [PATCH 19/69] update structure after merge --- .gitignore | 1 + src/Api.php | 46 +++++++++-------- src/Clients/PostingCategory.php | 25 ++++++++++ src/Clients/RecurringTemplate.php | 14 ++++++ src/Clients/Traits/GetTrait.php | 4 ++ src/PostingCategory/Client.php | 54 -------------------- src/RecurringTemplate/Client.php | 31 ------------ tests/ApiTest.php | 11 +++-- tests/Clients/PostingCategoryTest.php | 24 +++++++++ tests/Clients/RecurringTemplateTest.php | 38 ++++++++++++++ tests/PostingCategory/ClientTest.php | 66 ------------------------- tests/RecurringTemplate/ClientTest.php | 25 ---------- 12 files changed, 134 insertions(+), 205 deletions(-) create mode 100644 src/Clients/PostingCategory.php create mode 100644 src/Clients/RecurringTemplate.php delete mode 100644 src/PostingCategory/Client.php delete mode 100644 src/RecurringTemplate/Client.php create mode 100644 tests/Clients/PostingCategoryTest.php create mode 100644 tests/Clients/RecurringTemplateTest.php delete mode 100644 tests/PostingCategory/ClientTest.php delete mode 100644 tests/RecurringTemplate/ClientTest.php diff --git a/.gitignore b/.gitignore index 1448903..d58765b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ +/tests/cache/ # Created by https://www.gitignore.io/api/macos,composer,phpstorm # Edit at https://www.gitignore.io/?templates=macos,composer,phpstorm diff --git a/src/Api.php b/src/Api.php index d11ddae..b2ef033 100644 --- a/src/Api.php +++ b/src/Api.php @@ -13,14 +13,12 @@ use Clicksports\LexOffice\Clients\Payment; use Clicksports\LexOffice\Clients\PaymentCondition; use Clicksports\LexOffice\Clients\Profile; -use Clicksports\LexOffice\PostingCategory\Client as PostingCategoryClient; +use Clicksports\LexOffice\Clients\PostingCategory; use Clicksports\LexOffice\Clients\Quotation; use Clicksports\LexOffice\Clients\Voucher; use Clicksports\LexOffice\Clients\VoucherList; use Clicksports\LexOffice\Traits\CacheResponseTrait; -use Clicksports\LexOffice\RecurringTemplate\Client as RecurringTemplateClient; -use Clicksports\LexOffice\Voucher\Client as VoucherClient; -use Clicksports\LexOffice\Voucherlist\Client as VoucherlistClient; +use Clicksports\LexOffice\Clients\RecurringTemplate; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Clicksports\LexOffice\Exceptions\CacheException; use GuzzleHttp\Client; @@ -172,7 +170,7 @@ public function getResponse() /** * @return Contact */ - public function contact() + public function contact(): Contact { return new Contact($this); } @@ -180,7 +178,7 @@ public function contact() /** * @return Country */ - public function country() + public function country(): Country { return new Country($this); } @@ -188,7 +186,7 @@ public function country() /** * @return Event */ - public function event() + public function event(): Event { return new Event($this); } @@ -196,7 +194,7 @@ public function event() /** * @return Invoice */ - public function invoice() + public function invoice(): Invoice { return new Invoice($this); } @@ -204,7 +202,7 @@ public function invoice() /** * @return DownPaymentInvoice */ - public function downPaymentInvoice() + public function downPaymentInvoice(): DownPaymentInvoice { return new DownPaymentInvoice($this); } @@ -212,7 +210,7 @@ public function downPaymentInvoice() /** * @return OrderConfirmation */ - public function orderConfirmation() + public function orderConfirmation(): OrderConfirmation { return new OrderConfirmation($this); } @@ -220,7 +218,7 @@ public function orderConfirmation() /** * @return Payment */ - public function payment() + public function payment(): Payment { return new Payment($this); } @@ -228,7 +226,7 @@ public function payment() /** * @return PaymentCondition */ - public function paymentCondition() + public function paymentCondition(): PaymentCondition { return new PaymentCondition($this); } @@ -236,7 +234,7 @@ public function paymentCondition() /** * @return CreditNote */ - public function creditNote() + public function creditNote(): CreditNote { return new CreditNote($this); } @@ -244,7 +242,7 @@ public function creditNote() /** * @return Quotation */ - public function quotation() + public function quotation(): Quotation { return new Quotation($this); } @@ -252,23 +250,23 @@ public function quotation() /** * @return Voucher */ - public function voucher() + public function voucher(): Voucher { return new Voucher($this); } /** - * @return RecurringTemplateClient + * @return RecurringTemplate */ - public function recurringTemplate() + public function recurringTemplate(): RecurringTemplate { - return new RecurringTemplateClient($this); + return new RecurringTemplate($this); } /** * @return VoucherList */ - public function voucherlist() + public function voucherlist(): VoucherList { return new VoucherList($this); } @@ -276,23 +274,23 @@ public function voucherlist() /** * @return Profile */ - public function profile() + public function profile(): Profile { return new Profile($this); } /** - * @return PostingCategoryClient + * @return PostingCategory */ - public function postingCategory() + public function postingCategory(): PostingCategory { - return new PostingCategoryClient($this); + return new PostingCategory($this); } /** * @return File */ - public function file() + public function file(): File { return new File($this); } diff --git a/src/Clients/PostingCategory.php b/src/Clients/PostingCategory.php new file mode 100644 index 0000000..aa5c8a2 --- /dev/null +++ b/src/Clients/PostingCategory.php @@ -0,0 +1,25 @@ +api->newRequest('GET', $this->resource) + ->getResponse(); + } +} diff --git a/src/Clients/RecurringTemplate.php b/src/Clients/RecurringTemplate.php new file mode 100644 index 0000000..0334b94 --- /dev/null +++ b/src/Clients/RecurringTemplate.php @@ -0,0 +1,14 @@ +resource); - } - - /** - * @param array $data - * @throws BadMethodCallException - */ - public function create(array $data) - { - throw new BadMethodCallException('method create is defined for ' . $this->resource); - } - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is defined for ' . $this->resource); - } - - /** - * @return ResponseInterface - * @throws CacheException - * @throws LexOfficeApiException - */ - public function getAll() - { - return $this->api->newRequest('GET', $this->resource) - ->getResponse(); - } -} diff --git a/src/RecurringTemplate/Client.php b/src/RecurringTemplate/Client.php deleted file mode 100644 index 1d8f21f..0000000 --- a/src/RecurringTemplate/Client.php +++ /dev/null @@ -1,31 +0,0 @@ -resource); - } - - /** - * @param string $id - * @param array $data - * @throws BadMethodCallException - */ - public function update(string $id, array $data) - { - throw new BadMethodCallException('method update is not defined for ' . $this->resource); - } -} diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 728b4a4..9c59b20 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -13,9 +13,11 @@ use Clicksports\LexOffice\Clients\Payment; use Clicksports\LexOffice\Clients\PaymentCondition; use Clicksports\LexOffice\Clients\Profile; +use Clicksports\LexOffice\Clients\PostingCategory; use Clicksports\LexOffice\Clients\Quotation; use Clicksports\LexOffice\Clients\Voucher; use Clicksports\LexOffice\Clients\VoucherList; +use Clicksports\LexOffice\Clients\RecurringTemplate; use GuzzleHttp\Psr7\Response; class ApiTest extends TestClient @@ -29,7 +31,6 @@ public function createApiMockObject(Response $response, $methodExcept = []) return $stub; } - /** @noinspection PhpFullyQualifiedNameUsageInspection */ public function testClients() { $stub = $this->createApiMockObject(new Response(), [ @@ -65,8 +66,8 @@ public function testClients() $this->assertInstanceOf(Payment::class, $stub->payment()); $this->assertInstanceOf(PaymentCondition::class, $stub->paymentCondition()); $this->assertInstanceOf(File::class, $stub->file()); - $this->assertInstanceOf(\Clicksports\LexOffice\RecurringTemplate\Client::class, $stub->recurringTemplate()); - $this->assertInstanceOf(\Clicksports\LexOffice\PostingCategory\Client::class, $stub->postingCategory()); + $this->assertInstanceOf(RecurringTemplate::class, $stub->recurringTemplate()); + $this->assertInstanceOf(PostingCategory::class, $stub->postingCategory()); } public function testApiUrl() @@ -75,12 +76,12 @@ public function testApiUrl() new Response(200, [], 'post-content') ); - $this->assertStringStartsWith($stub->apiUrl, $stub->request->getUri()); + $this->assertStringStartsWith('api.lexoffice.io', $stub->request->getUri()->getHost()); $stub->apiUrl = 'https://test.de'; $stub->newRequest('POST', 'post-content'); - $this->assertStringStartsWith($stub->apiUrl, $stub->request->getUri()); + $this->assertStringStartsWith('test.de', $stub->request->getUri()->getHost()); } public function testGetResponse() diff --git a/tests/Clients/PostingCategoryTest.php b/tests/Clients/PostingCategoryTest.php new file mode 100644 index 0000000..0500552 --- /dev/null +++ b/tests/Clients/PostingCategoryTest.php @@ -0,0 +1,24 @@ +createClientMockObject( + PostingCategory::class, + new Response(200, [], '{"content": [], "totalPages": 1}'), + ['getAll'] + ); + + $response = $stub->getAll(); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } +} diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php new file mode 100644 index 0000000..1a9c12b --- /dev/null +++ b/tests/Clients/RecurringTemplateTest.php @@ -0,0 +1,38 @@ +createClientMockObject( + RecurringTemplate::class, + new Response(200, [], 'body'), + ['get'] + ); + + $response = $stub->get('resource-id'); + + $this->assertEquals('body', $response->getBody()->__toString()); + } + + public function testGenerateUrl(): void + { + $stub = $this->createClientMockObject( + RecurringTemplate::class, + new Response(200, [], 'body'), + ['generateUrl'] + ); + + $this->assertEquals( + 'recurring-templates?page=0&size=100', + $stub->generateUrl(0) + ); + } + +} diff --git a/tests/PostingCategory/ClientTest.php b/tests/PostingCategory/ClientTest.php deleted file mode 100644 index c27b2ab..0000000 --- a/tests/PostingCategory/ClientTest.php +++ /dev/null @@ -1,66 +0,0 @@ -expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['create'] - ); - - $stub->create([ - 'version' => 0 - ]); - } - - public function testGet() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['get'] - ); - - $stub->get('resource-id'); - } - - public function testGetAll() - { - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] - ); - - $response = $stub->getAll(); - - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testUpdate() - { - $this->expectException(BadMethodCallException::class); - - $stub = $this->createClientMockObject( - Client::class, - new Response(200, [], '{}'), - ['update'] - ); - - $stub->update('resource-id', []); - } -} diff --git a/tests/RecurringTemplate/ClientTest.php b/tests/RecurringTemplate/ClientTest.php deleted file mode 100644 index ca3717f..0000000 --- a/tests/RecurringTemplate/ClientTest.php +++ /dev/null @@ -1,25 +0,0 @@ -createClientMockObject( - Client::class, - new Response(200, [], 'body'), - ['generateUrl'] - ); - - $this->assertEquals( - 'recurring-templates?page=0&size=100', - $stub->generateUrl(0) - ); - } - -} From 1d237df109dad64d671a85ba5c2b5aa36d5800c5 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Mon, 9 Aug 2021 22:43:08 +0200 Subject: [PATCH 20/69] update composer lock after merge --- composer.lock | 277 +++++++++++++++++++++++++++++++------------------- 1 file changed, 173 insertions(+), 104 deletions(-) diff --git a/composer.lock b/composer.lock index 74bf611..f5ad000 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3dc1b23ceb2545dae3b4ad2bec536df5", + "content-hash": "57d668bda7ef12147e6730f6598b6b3f", "packages": [ { "name": "guzzlehttp/guzzle", @@ -166,29 +166,32 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.8.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" + "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", + "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", "shasum": "" }, "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + "php": "^7.2.5 || ^8.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "ralouphie/getallheaders": "^3.0" }, "provide": { + "psr/http-factory-implementation": "1.0", "psr/http-message-implementation": "1.0" }, "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + "bamarni/composer-bin-plugin": "^1.4.1", + "http-interop/http-factory-tests": "^0.9", + "phpunit/phpunit": "^8.5.8 || ^9.3.10" }, "suggest": { "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" @@ -196,16 +199,13 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "2.0-dev" } }, "autoload": { "psr-4": { "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -220,6 +220,11 @@ { "name": "Tobias Schultze", "homepage": "https://github.com/Tobion" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" } ], "description": "PSR-7 message implementation that also provides common utility methods", @@ -235,9 +240,9 @@ ], "support": { "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.8.1" + "source": "https://github.com/guzzle/psr7/tree/2.0.0" }, - "time": "2021-03-21T16:25:00+00:00" + "time": "2021-06-30T20:03:07+00:00" }, { "name": "psr/cache", @@ -340,6 +345,61 @@ }, "time": "2020-06-29T06:28:15+00:00" }, + { + "name": "psr/http-factory", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-factory.git", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be", + "shasum": "" + }, + "require": { + "php": ">=7.0.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interfaces for PSR-7 HTTP message factories", + "keywords": [ + "factory", + "http", + "message", + "psr", + "psr-17", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-factory/tree/master" + }, + "time": "2019-04-30T12:38:16+00:00" + }, { "name": "psr/http-message", "version": "1.0.1", @@ -508,61 +568,6 @@ ], "time": "2020-11-10T18:47:58+00:00" }, - { - "name": "fzaninotto/faker", - "version": "v1.9.2", - "source": { - "type": "git", - "url": "https://github.com/fzaninotto/Faker.git", - "reference": "848d8125239d7dbf8ab25cb7f054f1a630e68c2e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/fzaninotto/Faker/zipball/848d8125239d7dbf8ab25cb7f054f1a630e68c2e", - "reference": "848d8125239d7dbf8ab25cb7f054f1a630e68c2e", - "shasum": "" - }, - "require": { - "php": "^5.3.3 || ^7.0" - }, - "require-dev": { - "ext-intl": "*", - "phpunit/phpunit": "^4.8.35 || ^5.7", - "squizlabs/php_codesniffer": "^2.9.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.9-dev" - } - }, - "autoload": { - "psr-4": { - "Faker\\": "src/Faker/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "François Zaninotto" - } - ], - "description": "Faker is a PHP library that generates fake data for you.", - "keywords": [ - "data", - "faker", - "fixtures" - ], - "support": { - "issues": "https://github.com/fzaninotto/Faker/issues", - "source": "https://github.com/fzaninotto/Faker/tree/v1.9.2" - }, - "abandoned": true, - "time": "2020-12-11T09:56:16+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.10.2", @@ -623,16 +628,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.11.0", + "version": "v4.12.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94" + "reference": "6608f01670c3cc5079e18c1dab1104e002579143" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/fe14cf3672a149364fb66dfe11bf6549af899f94", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6608f01670c3cc5079e18c1dab1104e002579143", + "reference": "6608f01670c3cc5079e18c1dab1104e002579143", "shasum": "" }, "require": { @@ -673,22 +678,22 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.11.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.12.0" }, - "time": "2021-07-03T13:36:55+00:00" + "time": "2021-07-21T10:44:31+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -733,9 +738,9 @@ "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", "support": { "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/master" + "source": "https://github.com/phar-io/manifest/tree/2.0.3" }, - "time": "2020-06-27T14:33:11+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", @@ -1013,6 +1018,70 @@ }, "time": "2021-03-17T13:42:18+00:00" }, + { + "name": "phpstan/phpstan", + "version": "0.12.94", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6", + "reference": "3d0ba4c198a24e3c3fc489f3ec6ac9612c4be5d6", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.12-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.94" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://www.patreon.com/phpstan", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2021-07-30T09:05:27+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.6", @@ -1333,16 +1402,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.7", + "version": "9.5.8", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d0dc8b6999c937616df4fb046792004b33fd31c5" + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d0dc8b6999c937616df4fb046792004b33fd31c5", - "reference": "d0dc8b6999c937616df4fb046792004b33fd31c5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/191768ccd5c85513b4068bdbe99bb6390c7d54fb", + "reference": "191768ccd5c85513b4068bdbe99bb6390c7d54fb", "shasum": "" }, "require": { @@ -1354,7 +1423,7 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", @@ -1420,7 +1489,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.7" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.8" }, "funding": [ { @@ -1432,7 +1501,7 @@ "type": "github" } ], - "time": "2021-07-19T06:14:47+00:00" + "time": "2021-07-31T15:17:34+00:00" }, { "name": "psr/container", @@ -2819,16 +2888,16 @@ }, { "name": "symfony/polyfill-php80", - "version": "v1.23.0", + "version": "v1.23.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0" + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/eca0bf41ed421bed1b57c4958bab16aa86b757d0", - "reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", + "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", "shasum": "" }, "require": { @@ -2882,7 +2951,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" }, "funding": [ { @@ -2898,7 +2967,7 @@ "type": "tidelift" } ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-07-28T13:41:28+00:00" }, { "name": "symfony/service-contracts", @@ -3054,16 +3123,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -3092,7 +3161,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/master" + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" }, "funding": [ { @@ -3100,7 +3169,7 @@ "type": "github" } ], - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" }, { "name": "webmozart/assert", @@ -3172,5 +3241,5 @@ "ext-curl": "*" }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.0.0" } From ff6a08d2f2c9540f1518e9ddb858db16c213f06a Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Mon, 9 Aug 2021 22:56:23 +0200 Subject: [PATCH 21/69] remove CacheResponseTrait, add UPDATE.md to suggest how to implement it --- UPDATE.md | 22 ++++ src/Api.php | 60 +++------ src/Traits/CacheResponseTrait.php | 122 ----------------- tests/Traits/CacheResponseTraitTest.php | 167 ------------------------ 4 files changed, 42 insertions(+), 329 deletions(-) create mode 100644 UPDATE.md delete mode 100644 src/Traits/CacheResponseTrait.php delete mode 100644 tests/Traits/CacheResponseTraitTest.php diff --git a/UPDATE.md b/UPDATE.md new file mode 100644 index 0000000..8c17109 --- /dev/null +++ b/UPDATE.md @@ -0,0 +1,22 @@ +# Update from Version 0.x to 1.0 + +## Functions Removed + +- `$api->setCacheInterface()` +- `$api->getCacheResponse()` +- `$api->setCacheResponse()` + +For settings a Cache Interface check out [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). +And implement it with: +`$api = new \Clicksports\LexOffice\Api($apiKey, $guzzleClient);` + +## Clients Method which will throw a BadMethodException + +We implemented in the `0.x` Version some methods for the future of lexoffice API. +At the moment, it doesn't look like the endpoint will be added soon. So we will remove them. + +## Clients Namespace changed + +In Version `0.x` all Clients had a separate folder/namespace. Now they will all use the namespace +`\Clicksports\Lexoffice\Clients` + diff --git a/src/Api.php b/src/Api.php index b2ef033..a8089be 100644 --- a/src/Api.php +++ b/src/Api.php @@ -12,15 +12,13 @@ use Clicksports\LexOffice\Clients\OrderConfirmation; use Clicksports\LexOffice\Clients\Payment; use Clicksports\LexOffice\Clients\PaymentCondition; -use Clicksports\LexOffice\Clients\Profile; use Clicksports\LexOffice\Clients\PostingCategory; +use Clicksports\LexOffice\Clients\Profile; use Clicksports\LexOffice\Clients\Quotation; +use Clicksports\LexOffice\Clients\RecurringTemplate; use Clicksports\LexOffice\Clients\Voucher; use Clicksports\LexOffice\Clients\VoucherList; -use Clicksports\LexOffice\Traits\CacheResponseTrait; -use Clicksports\LexOffice\Clients\RecurringTemplate; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Clicksports\LexOffice\Exceptions\CacheException; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\RequestException; @@ -30,8 +28,6 @@ class Api { - use CacheResponseTrait; - /** * the library version */ @@ -89,7 +85,7 @@ public function __construct(string $apiKey, Client $client = null) * @param string[] $headers * @return $this */ - public function newRequest(string $method, string $resource, $headers = []): self + public function newRequest(string $method, string $resource, array $headers = []): self { $this->setRequest( new Request($method, $this->createApiUrl($resource), $headers) @@ -102,7 +98,7 @@ public function newRequest(string $method, string $resource, $headers = []): sel * @param RequestInterface $request * @return $this */ - public function setRequest(RequestInterface $request) + public function setRequest(RequestInterface $request): Api { $request = $request ->withHeader('Authorization', 'Bearer ' . $this->apiKey) @@ -129,42 +125,26 @@ protected function createApiUrl(string $resource): string /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ - public function getResponse() + public function getResponse(): ResponseInterface { - $cache = null; - if ($this->cacheInterface) { - $response = $cache = $this->getCacheResponse($this->request); + try { + return $this->client->send($this->request); + } catch (RequestException $exception) { + $response = $exception->getResponse(); + throw new LexOfficeApiException( + $exception->getMessage(), + $response ? $response->getStatusCode() : $exception->getCode(), + $exception + ); + } catch (GuzzleException $exception) { + throw new LexOfficeApiException( + $exception->getMessage(), + $exception->getCode(), + $exception + ); } - - // when no cacheInterface is set or the cache is invalid - if (!isset($response)) { - try { - $response = $this->client->send($this->request); - } catch (RequestException $exception) { - $response = $exception->getResponse(); - throw new LexOfficeApiException( - $exception->getMessage(), - $response ? $response->getStatusCode() : $exception->getCode(), - $exception - ); - } catch (GuzzleException $exception) { - throw new LexOfficeApiException( - $exception->getMessage(), - $exception->getCode(), - $exception - ); - } - } - - // set cache response when cache is invalid - if ($this->cacheInterface && !$cache) { - $this->setCacheResponse($this->request, $response); - } - - return $response; } /** diff --git a/src/Traits/CacheResponseTrait.php b/src/Traits/CacheResponseTrait.php deleted file mode 100644 index ab9094d..0000000 --- a/src/Traits/CacheResponseTrait.php +++ /dev/null @@ -1,122 +0,0 @@ -cacheInterface = $cache; - - return $this; - } - - /** - * @param RequestInterface $request - * @return string - */ - protected function getCacheName(RequestInterface $request): string - { - return 'lex-office-' . str_replace('/', '-', $request->getUri()->getPath()) . $request->getUri()->getQuery(); - } - - - /** - * @param RequestInterface $request - * @return Response|null - * @throws CacheException - */ - public function getCacheResponse(RequestInterface $request): ?Response - { - $cacheName = $this->getCacheName($request); - - if (!$this->cacheInterface) { - throw new CacheException('response could not be cached, cacheInterface is not defined'); - } - - try { - if ($request->getMethod() == 'GET') { - $cache = $this->cacheInterface->getItem($cacheName); - - if ($cache->isHit()) { - $cache = Utils::jsonDecode($cache->get()); - - return new Response( - $cache->status, - (array)$cache->headers, - Utils::streamFor($cache->body), - $cache->version, - $cache->reason - ); - } - } - } catch (InvalidArgumentException $exception) { - throw new CacheException( - 'could not load cache response from request' . $request->getUri()->getPath(), - $exception->getCode(), - $exception - ); - } - - return null; - } - - /** - * @param RequestInterface $request - * @param ResponseInterface $response - * @return $this - * @throws CacheException - */ - public function setCacheResponse(RequestInterface $request, ResponseInterface $response): self - { - if ($request->getMethod() != 'GET') { - return $this; - } - - if (!$this->cacheInterface) { - throw new CacheException('response could not be cached, cacheInterface is not defined'); - } - - try { - $cacheName = $this->getCacheName($request); - - $cache = new stdClass(); - $cache->status = $response->getStatusCode(); - $cache->headers = $response->getHeaders(); - $cache->body = $response->getBody()->__toString(); - $cache->version = $response->getProtocolVersion(); - $cache->reason = $response->getReasonPhrase(); - - $item = $this->cacheInterface->getItem($cacheName); - $item->set(Utils::jsonEncode($cache)); - - $this->cacheInterface->save($item); - } catch (InvalidArgumentException $exception) { - throw new CacheException( - 'response could not set cache for request ' . $request->getUri()->getPath(), - $exception->getCode(), - $exception - ); - } - - return $this; - } -} \ No newline at end of file diff --git a/tests/Traits/CacheResponseTraitTest.php b/tests/Traits/CacheResponseTraitTest.php deleted file mode 100644 index bd47e6c..0000000 --- a/tests/Traits/CacheResponseTraitTest.php +++ /dev/null @@ -1,167 +0,0 @@ -expectException(CacheException::class); - - $stub = $this->createApiMockObject( - new Response(), - ['setCacheResponse'] - ); - - $stub->newRequest('GET', '/'); - $stub->setCacheResponse($stub->request, new Response()); - } - - /** - * @return Api|MockObject - */ - public function testSetCacheInterface() - { - $stub = $this->createApiMockObject( - new Response(200, [], '{"cache": true}'), - ['setCacheInterface', 'setCacheResponse', 'getCacheResponse'] - ); - - $stub->setCacheInterface($this->getCacheInterface()); - - $this->assertTrue(true); - - return $stub; - } - - /** - * @depends testSetCacheInterface - * @param Api|MockObject $stub - * @throws \Clicksports\LexOffice\Exceptions\CacheException - * @throws \Clicksports\LexOffice\Exceptions\LexOfficeApiException - * @throws \Psr\Cache\InvalidArgumentException - */ - public function testGetCacheResponse($stub) - { - $cacheInterface = $this->getCacheInterface(); - $cacheKey = 'lex-office--v1--'; - - $stub->newRequest('GET', '/'); - - // execute response "curl" with caching in background - $response = $stub->getResponse(); - - $this->assertEquals( - $this->transformToString($response), - $this->transformToString($stub->getCacheResponse($stub->request)) - ); - - $this->assertEquals( - '{"status":200,"headers":[],"body":"{\"cache\": true}","version":"1.1","reason":"OK"}', - $cacheInterface->getItem($cacheKey)->get() - ); - - // remove cache - $cacheInterface->deleteItem($cacheKey); - } - - /** - * @depends testSetCacheInterface - * @param Api|MockObject $stub - * @throws \Clicksports\LexOffice\Exceptions\CacheException - * @throws \Psr\Cache\InvalidArgumentException - */ - public function testSetCacheResponse($stub) - { - $cacheInterface = $this->getCacheInterface(); - $cacheKey = 'lex-office--v1--'; - - $stub->newRequest('GET', '/'); - - $fakeResponse = new Response(200, [], 'fake'); - - $stub->setCacheResponse($stub->request, $fakeResponse); - - $this->assertEquals( - $cacheInterface->getItem($cacheKey)->get(), - $this->transformToString($fakeResponse) - ); - - // remove cache - $cacheInterface->deleteItem($cacheKey); - - // test on post - $stub->setCacheResponse(new Request('POST', '/'), $fakeResponse); - $this->assertNull($cacheInterface->getItem($cacheKey)->get()); - - // test on put - $stub->setCacheResponse(new Request('PUT', '/'), $fakeResponse); - $this->assertNull($cacheInterface->getItem($cacheKey)->get()); - - // test on delete - $stub->setCacheResponse(new Request('DELETE', '/'), $fakeResponse); - $this->assertNull($cacheInterface->getItem($cacheKey)->get()); - - $cacheInterface->deleteItem($cacheKey); - } - - /** - * @depends testSetCacheInterface - */ - public function testDifferentParamsCache($stub) - { - $stub->newRequest('GET', '/?a'); - $fakeResponse = new Response(200, [], 'fake'); - $stub->setCacheResponse($stub->request, $fakeResponse); - - $this->assertEquals( - $this->transformToString($stub->getCacheResponse($stub->request)), - $this->transformToString($fakeResponse) - ); - - $stub->newRequest('GET', '/?b'); - $fakeResponse = new Response(200, [], 'fake2'); - $stub->setCacheResponse($stub->request, $fakeResponse); - - $this->assertEquals( - $this->transformToString($stub->getCacheResponse($stub->request)), - $this->transformToString($fakeResponse) - ); - } - - protected function transformToString(ResponseInterface $response) - { - $obj = new stdClass(); - $obj->status = $response->getStatusCode(); - $obj->headers = $response->getHeaders(); - $obj->body = $response->getBody()->__toString(); - $obj->version = $response->getProtocolVersion(); - $obj->reason = $response->getReasonPhrase(); - - return json_encode($obj); - } -} \ No newline at end of file From 9fe3a1b143400b7533659525d5cf3e2a1fd5669a Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Mon, 9 Aug 2021 23:02:29 +0200 Subject: [PATCH 22/69] remove Exceptions\CacheException from all references --- src/Api.php | 2 +- src/Clients/Country.php | 3 --- src/Clients/CreditNote.php | 2 -- src/Clients/DownPaymentInvoice.php | 3 --- src/Clients/Event.php | 2 -- src/Clients/File.php | 2 -- src/Clients/Invoice.php | 2 -- src/Clients/OrderConfirmation.php | 2 -- src/Clients/Payment.php | 1 - src/Clients/PaymentCondition.php | 3 --- src/Clients/PostingCategory.php | 3 --- src/Clients/Profile.php | 2 -- src/Clients/Quotation.php | 2 -- src/Clients/Traits/CreateFinalizeTrait.php | 4 +++- src/Clients/Traits/CreateTrait.php | 2 ++ src/Clients/Traits/DeleteTrait.php | 2 ++ src/Clients/Traits/DocumentClientTrait.php | 2 ++ src/Clients/Traits/GetTrait.php | 2 -- src/Clients/Traits/UpdateTrait.php | 2 ++ src/Clients/Voucher.php | 2 -- src/Clients/VoucherList.php | 2 +- src/Exceptions/CacheException.php | 9 --------- src/PaginationClient.php | 2 -- 23 files changed, 13 insertions(+), 45 deletions(-) delete mode 100644 src/Exceptions/CacheException.php diff --git a/src/Api.php b/src/Api.php index a8089be..10812af 100644 --- a/src/Api.php +++ b/src/Api.php @@ -98,7 +98,7 @@ public function newRequest(string $method, string $resource, array $headers = [] * @param RequestInterface $request * @return $this */ - public function setRequest(RequestInterface $request): Api + public function setRequest(RequestInterface $request): self { $request = $request ->withHeader('Authorization', 'Bearer ' . $this->apiKey) diff --git a/src/Clients/Country.php b/src/Clients/Country.php index cbd3124..f5d13da 100644 --- a/src/Clients/Country.php +++ b/src/Clients/Country.php @@ -3,8 +3,6 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -14,7 +12,6 @@ class Country extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/CreditNote.php b/src/Clients/CreditNote.php index 20e6f16..994c177 100644 --- a/src/Clients/CreditNote.php +++ b/src/Clients/CreditNote.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -20,7 +19,6 @@ class CreditNote extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/DownPaymentInvoice.php b/src/Clients/DownPaymentInvoice.php index aa5d415..a5c8b17 100644 --- a/src/Clients/DownPaymentInvoice.php +++ b/src/Clients/DownPaymentInvoice.php @@ -5,8 +5,6 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -19,7 +17,6 @@ class DownPaymentInvoice extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/Event.php b/src/Clients/Event.php index f5c7840..ddecaf5 100644 --- a/src/Clients/Event.php +++ b/src/Clients/Event.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\DeleteTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -19,7 +18,6 @@ class Event extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/File.php b/src/Clients/File.php index 15eeaf3..0a1da74 100644 --- a/src/Clients/File.php +++ b/src/Clients/File.php @@ -4,7 +4,6 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -24,7 +23,6 @@ class File extends BaseClient * @param string $type * @return ResponseInterface * @throws LexOfficeApiException - * @throws CacheException */ public function upload(string $filepath, string $type): ResponseInterface { diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index 0d1720b..bac0a0a 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -20,7 +19,6 @@ class Invoice extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 6aa0676..39c00da 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -20,7 +19,6 @@ class OrderConfirmation extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/Payment.php b/src/Clients/Payment.php index 0e2efd3..d900818 100644 --- a/src/Clients/Payment.php +++ b/src/Clients/Payment.php @@ -5,7 +5,6 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Traits\DocumentClientTrait; class Payment extends BaseClient { diff --git a/src/Clients/PaymentCondition.php b/src/Clients/PaymentCondition.php index 6b0b609..24ba2ec 100644 --- a/src/Clients/PaymentCondition.php +++ b/src/Clients/PaymentCondition.php @@ -3,8 +3,6 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -14,7 +12,6 @@ class PaymentCondition extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/PostingCategory.php b/src/Clients/PostingCategory.php index aa5c8a2..b4ba4d9 100644 --- a/src/Clients/PostingCategory.php +++ b/src/Clients/PostingCategory.php @@ -3,8 +3,6 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -14,7 +12,6 @@ class PostingCategory extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/Profile.php b/src/Clients/Profile.php index 1d2c60c..c82b33e 100644 --- a/src/Clients/Profile.php +++ b/src/Clients/Profile.php @@ -4,7 +4,6 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\BaseClient; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -14,7 +13,6 @@ class Profile extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function get(): ResponseInterface diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 9938b27..80310d7 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -20,7 +19,6 @@ class Quotation extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/Traits/CreateFinalizeTrait.php b/src/Clients/Traits/CreateFinalizeTrait.php index c8b00c3..bf7f310 100644 --- a/src/Clients/Traits/CreateFinalizeTrait.php +++ b/src/Clients/Traits/CreateFinalizeTrait.php @@ -2,6 +2,7 @@ namespace Clicksports\LexOffice\Clients\Traits; +use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait CreateFinalizeTrait @@ -10,8 +11,9 @@ trait CreateFinalizeTrait * @param array[] $data * @param bool $finalized * @return ResponseInterface + * @throws LexOfficeApiException */ - public function create(array $data, $finalized = false): ResponseInterface + public function create(array $data, bool $finalized = false): ResponseInterface { $api = $this->api->newRequest('POST', $this->resource . ($finalized ? '?finalize=true' : '')); diff --git a/src/Clients/Traits/CreateTrait.php b/src/Clients/Traits/CreateTrait.php index af1ec88..8bc6f5a 100644 --- a/src/Clients/Traits/CreateTrait.php +++ b/src/Clients/Traits/CreateTrait.php @@ -2,6 +2,7 @@ namespace Clicksports\LexOffice\Clients\Traits; +use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait CreateTrait @@ -9,6 +10,7 @@ trait CreateTrait /** * @param array[] $data * @return ResponseInterface + * @throws LexOfficeApiException */ public function create(array $data): ResponseInterface { diff --git a/src/Clients/Traits/DeleteTrait.php b/src/Clients/Traits/DeleteTrait.php index ab112c5..0b54ae8 100644 --- a/src/Clients/Traits/DeleteTrait.php +++ b/src/Clients/Traits/DeleteTrait.php @@ -2,6 +2,7 @@ namespace Clicksports\LexOffice\Clients\Traits; +use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait DeleteTrait @@ -9,6 +10,7 @@ trait DeleteTrait /** * @param string $id * @return ResponseInterface + * @throws LexOfficeApiException */ public function delete(string $id): ResponseInterface { diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 54dbfe5..e663605 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -3,6 +3,7 @@ namespace Clicksports\LexOffice\Clients\Traits; use Clicksports\LexOffice\Clients\File; +use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; use stdClass; @@ -12,6 +13,7 @@ trait DocumentClientTrait * @param string $id * @param bool $asContent * @return ResponseInterface + * @throws LexOfficeApiException */ public function document(string $id, bool $asContent = false): ResponseInterface { diff --git a/src/Clients/Traits/GetTrait.php b/src/Clients/Traits/GetTrait.php index ff1c7c4..4ec8f63 100644 --- a/src/Clients/Traits/GetTrait.php +++ b/src/Clients/Traits/GetTrait.php @@ -2,7 +2,6 @@ namespace Clicksports\LexOffice\Clients\Traits; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -11,7 +10,6 @@ trait GetTrait /** * @param string $id * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function get(string $id): ResponseInterface diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php index 0709ba2..83f31a9 100644 --- a/src/Clients/Traits/UpdateTrait.php +++ b/src/Clients/Traits/UpdateTrait.php @@ -2,6 +2,7 @@ namespace Clicksports\LexOffice\Clients\Traits; +use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait UpdateTrait @@ -10,6 +11,7 @@ trait UpdateTrait * @param string $id * @param array[] $data * @return ResponseInterface + * @throws LexOfficeApiException */ public function update(string $id, array $data): ResponseInterface { diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index 7a1bf53..76a6df0 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -6,7 +6,6 @@ use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; use Clicksports\LexOffice\Clients\Traits\UpdateTrait; -use Clicksports\LexOffice\Exceptions\CacheException; use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; @@ -20,7 +19,6 @@ class Voucher extends BaseClient /** * @return ResponseInterface - * @throws CacheException * @throws LexOfficeApiException */ public function getAll(): ResponseInterface diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index 59ab74d..e569a12 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -20,7 +20,7 @@ class VoucherList extends PaginationClient /** * @return $this */ - public function setToEverything() + public function setToEverything(): self { $this->types = [ 'salesinvoice', diff --git a/src/Exceptions/CacheException.php b/src/Exceptions/CacheException.php deleted file mode 100644 index 8ba0448..0000000 --- a/src/Exceptions/CacheException.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Mon, 9 Aug 2021 23:33:42 +0200 Subject: [PATCH 23/69] update composer json --- UPDATE.md | 8 +- composer.json | 7 +- composer.lock | 626 +-------------------------------------- src/PaginationClient.php | 4 +- src/Utils.php | 2 +- 5 files changed, 14 insertions(+), 633 deletions(-) diff --git a/UPDATE.md b/UPDATE.md index 8c17109..a0df83c 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -10,6 +10,11 @@ For settings a Cache Interface check out [guzzle-cache-middleware](https://githu And implement it with: `$api = new \Clicksports\LexOffice\Api($apiKey, $guzzleClient);` +## Exceptions Removed + +- `\Clicksports\Lexoffice\Exception\CacheException` +- `\Clicksports\Lexoffice\Exception\BadMethodException` + ## Clients Method which will throw a BadMethodException We implemented in the `0.x` Version some methods for the future of lexoffice API. @@ -18,5 +23,4 @@ At the moment, it doesn't look like the endpoint will be added soon. So we will ## Clients Namespace changed In Version `0.x` all Clients had a separate folder/namespace. Now they will all use the namespace -`\Clicksports\Lexoffice\Clients` - +`\Clicksports\Lexoffice\Clients` \ No newline at end of file diff --git a/composer.json b/composer.json index b0e88dd..27960bd 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,15 @@ "php": "^7.4 | ^8", "ext-json": "*", "ext-curl": "*", - "guzzlehttp/guzzle": "^6.2 | ^7.0", - "psr/cache": "^1.0" + "guzzlehttp/guzzle": "^6.2 | ^7.0" }, "require-dev": { "phpunit/phpunit": "^9.0", - "symfony/cache": "^5.1", "phpstan/phpstan": "^0.12.32" }, + "suggest": { + "kevinrob/guzzle-cache-middleware": "*" + }, "autoload": { "psr-4": { "Clicksports\\LexOffice\\": "src/" diff --git a/composer.lock b/composer.lock index f5ad000..2636497 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "57d668bda7ef12147e6730f6598b6b3f", + "content-hash": "5b2289d0c6a7a51f94db4f07cee2b87b", "packages": [ { "name": "guzzlehttp/guzzle", @@ -244,55 +244,6 @@ }, "time": "2021-06-30T20:03:07+00:00" }, - { - "name": "psr/cache", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/cache.git", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", - "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Cache\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for caching libraries", - "keywords": [ - "cache", - "psr", - "psr-6" - ], - "support": { - "source": "https://github.com/php-fig/cache/tree/master" - }, - "time": "2016-08-06T20:24:11+00:00" - }, { "name": "psr/http-client", "version": "1.0.1", @@ -1503,104 +1454,6 @@ ], "time": "2021-07-31T15:17:34+00:00" }, - { - "name": "psr/container", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf", - "shasum": "" - }, - "require": { - "php": ">=7.2.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Psr\\Container\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common Container Interface (PHP FIG PSR-11)", - "homepage": "https://github.com/php-fig/container", - "keywords": [ - "PSR-11", - "container", - "container-interface", - "container-interop", - "psr" - ], - "support": { - "issues": "https://github.com/php-fig/container/issues", - "source": "https://github.com/php-fig/container/tree/1.1.1" - }, - "time": "2021-03-05T17:36:06+00:00" - }, - { - "name": "psr/log", - "version": "1.1.4", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", - "reference": "d49695b909c3b7628b6289db5479a1c204601f11", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "support": { - "source": "https://github.com/php-fig/log/tree/1.1.4" - }, - "time": "2021-05-03T11:20:27+00:00" - }, { "name": "sebastian/cli-parser", "version": "1.0.1", @@ -2565,248 +2418,6 @@ ], "time": "2020-09-28T06:39:44+00:00" }, - { - "name": "symfony/cache", - "version": "v5.3.4", - "source": { - "type": "git", - "url": "https://github.com/symfony/cache.git", - "reference": "944db6004fc374fbe032d18e07cce51cc4e1e661" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/cache/zipball/944db6004fc374fbe032d18e07cce51cc4e1e661", - "reference": "944db6004fc374fbe032d18e07cce51cc4e1e661", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/cache": "^1.0|^2.0", - "psr/log": "^1.1|^2|^3", - "symfony/cache-contracts": "^1.1.7|^2", - "symfony/deprecation-contracts": "^2.1", - "symfony/polyfill-php80": "^1.16", - "symfony/service-contracts": "^1.1|^2", - "symfony/var-exporter": "^4.4|^5.0" - }, - "conflict": { - "doctrine/dbal": "<2.10", - "symfony/dependency-injection": "<4.4", - "symfony/http-kernel": "<4.4", - "symfony/var-dumper": "<4.4" - }, - "provide": { - "psr/cache-implementation": "1.0|2.0", - "psr/simple-cache-implementation": "1.0", - "symfony/cache-implementation": "1.0|2.0" - }, - "require-dev": { - "cache/integration-tests": "dev-master", - "doctrine/cache": "^1.6|^2.0", - "doctrine/dbal": "^2.10|^3.0", - "predis/predis": "^1.1", - "psr/simple-cache": "^1.0", - "symfony/config": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/filesystem": "^4.4|^5.0", - "symfony/http-kernel": "^4.4|^5.0", - "symfony/messenger": "^4.4|^5.0", - "symfony/var-dumper": "^4.4|^5.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\Cache\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Provides an extended PSR-6, PSR-16 (and tags) implementation", - "homepage": "https://symfony.com", - "keywords": [ - "caching", - "psr6" - ], - "support": { - "source": "https://github.com/symfony/cache/tree/v5.3.4" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-07-23T15:55:36+00:00" - }, - { - "name": "symfony/cache-contracts", - "version": "v2.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/cache-contracts.git", - "reference": "c0446463729b89dd4fa62e9aeecc80287323615d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/cache-contracts/zipball/c0446463729b89dd4fa62e9aeecc80287323615d", - "reference": "c0446463729b89dd4fa62e9aeecc80287323615d", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/cache": "^1.0|^2.0|^3.0" - }, - "suggest": { - "symfony/cache-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Cache\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to caching", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "support": { - "source": "https://github.com/symfony/cache-contracts/tree/v2.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-03-23T23:28:01+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v2.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v2.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-03-23T23:28:01+00:00" - }, { "name": "symfony/polyfill-ctype", "version": "v1.23.0", @@ -2886,241 +2497,6 @@ ], "time": "2021-02-19T12:13:01+00:00" }, - { - "name": "symfony/polyfill-php80", - "version": "v1.23.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/1100343ed1a92e3a38f9ae122fc0eb21602547be", - "reference": "1100343ed1a92e3a38f9ae122fc0eb21602547be", - "shasum": "" - }, - "require": { - "php": ">=7.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "1.23-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.23.1" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-07-28T13:41:28+00:00" - }, - { - "name": "symfony/service-contracts", - "version": "v2.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/service-contracts.git", - "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", - "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "psr/container": "^1.1" - }, - "suggest": { - "symfony/service-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\Service\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to writing services", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "support": { - "source": "https://github.com/symfony/service-contracts/tree/v2.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-04-01T10:43:52+00:00" - }, - { - "name": "symfony/var-exporter", - "version": "v5.3.4", - "source": { - "type": "git", - "url": "https://github.com/symfony/var-exporter.git", - "reference": "b7898a65fc91e7c41de7a88c7db9aee9c0d432f0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/var-exporter/zipball/b7898a65fc91e7c41de7a88c7db9aee9c0d432f0", - "reference": "b7898a65fc91e7c41de7a88c7db9aee9c0d432f0", - "shasum": "" - }, - "require": { - "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.16" - }, - "require-dev": { - "symfony/var-dumper": "^4.4.9|^5.0.9" - }, - "type": "library", - "autoload": { - "psr-4": { - "Symfony\\Component\\VarExporter\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Allows exporting any serializable PHP data structure to plain PHP code", - "homepage": "https://symfony.com", - "keywords": [ - "clone", - "construct", - "export", - "hydrate", - "instantiate", - "serialize" - ], - "support": { - "source": "https://github.com/symfony/var-exporter/tree/v5.3.4" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2021-07-21T12:38:00+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.1", diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 4e39245..3f0882d 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -40,7 +40,7 @@ public function getPage(int $page): ResponseInterface public function getAll(): ResponseInterface { $response = $this->getPage(0); - /** @var stdClass{totalPages:int, content:\stdClass[]} $result */ + /** @var stdClass{totalPages:int, content:stdClass[]} $result */ $result = $this->getAsJson($response); if ($result->totalPages == 1) { @@ -50,7 +50,7 @@ public function getAll(): ResponseInterface // update content to get all contacts for ($i = 1; $i < $result->totalPages; $i++) { $responsePage = $this->getPage($i); - /** @var stdClass{totalPages:int, content:\stdClass[]} $resultPage */ + /** @var stdClass{totalPages:int, content:stdClass[]} $resultPage */ $resultPage = $this->getAsJson($responsePage); foreach ($resultPage->content as $entity) { diff --git a/src/Utils.php b/src/Utils.php index 4af7063..398aa89 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -14,7 +14,7 @@ class Utils * @param array{size?: int, metadata?: array, mode?: bool, seekable?: bool} $options * @return Stream */ - public static function streamFor($resource = '', array $options = []): Stream + public static function streamFor(string $resource = '', array $options = []): Stream { if (is_scalar($resource)) { $stream = fopen('php://temp', 'r+'); From 95b7878a16329e339cd4cbd0bf146b1fa7d797a3 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 20:52:30 +0200 Subject: [PATCH 24/69] add GetAllVoucherListTrait.php, add declare strict type --- src/Clients/CreditNote.php | 18 ++---------- src/Clients/DownPaymentInvoice.php | 19 ++---------- src/Clients/Invoice.php | 19 ++---------- src/Clients/OrderConfirmation.php | 19 ++---------- src/Clients/PostingCategory.php | 2 +- src/Clients/Quotation.php | 19 ++---------- src/Clients/RecurringTemplate.php | 2 +- src/Clients/Traits/CreateFinalizeTrait.php | 2 +- src/Clients/Traits/CreateTrait.php | 2 +- src/Clients/Traits/DeleteTrait.php | 2 +- src/Clients/Traits/GetAllVoucherListTrait.php | 29 +++++++++++++++++++ src/Clients/Traits/GetTrait.php | 2 +- src/Clients/Traits/UpdateTrait.php | 2 +- 13 files changed, 51 insertions(+), 86 deletions(-) create mode 100644 src/Clients/Traits/GetAllVoucherListTrait.php diff --git a/src/Clients/CreditNote.php b/src/Clients/CreditNote.php index 994c177..c500d75 100644 --- a/src/Clients/CreditNote.php +++ b/src/Clients/CreditNote.php @@ -5,29 +5,17 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Psr\Http\Message\ResponseInterface; class CreditNote extends BaseClient { use GetTrait; use CreateFinalizeTrait; + use GetAllVoucherListTrait; use DocumentClientTrait; protected string $resource = 'credit-notes'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ - public function getAll(): ResponseInterface - { - $client = new VoucherList($this->api); - - $client->setToEverything(); - $client->types = ['creditnote']; - - return $client->getAll(); - } + protected array $getAllTypes = ['creditnote']; } diff --git a/src/Clients/DownPaymentInvoice.php b/src/Clients/DownPaymentInvoice.php index a5c8b17..8d14d65 100644 --- a/src/Clients/DownPaymentInvoice.php +++ b/src/Clients/DownPaymentInvoice.php @@ -4,28 +4,15 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Psr\Http\Message\ResponseInterface; class DownPaymentInvoice extends BaseClient { use GetTrait; + use GetAllVoucherListTrait; use DocumentClientTrait; protected string $resource = 'down-payment-invoices'; - - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ - public function getAll(): ResponseInterface - { - $client = new VoucherList($this->api); - - $client->setToEverything(); - $client->types = ['downpaymentinvoice']; - - return $client->getAll(); - } + protected array $getAllTypes = ['downpaymentinvoice']; } diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index bac0a0a..bddb891 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -5,29 +5,16 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Psr\Http\Message\ResponseInterface; class Invoice extends BaseClient { use GetTrait; + use GetAllVoucherListTrait; use DocumentClientTrait; use CreateFinalizeTrait; protected string $resource = 'invoices'; - - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ - public function getAll(): ResponseInterface - { - $client = new VoucherList($this->api); - - $client->setToEverything(); - $client->types = ['invoice']; - - return $client->getAll(); - } + protected array $getAllTypes = ['invoice']; } diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 39c00da..1d0aa71 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -5,29 +5,16 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; +use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; -use Clicksports\LexOffice\Exceptions\LexOfficeApiException; -use Psr\Http\Message\ResponseInterface; class OrderConfirmation extends BaseClient { use GetTrait; + use GetAllVoucherListTrait; use CreateTrait; use DocumentClientTrait; protected string $resource = 'order-confirmations'; - - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ - public function getAll(): ResponseInterface - { - $client = new VoucherList($this->api); - - $client->setToEverything(); - $client->types = ['orderconfirmation']; - - return $client->getAll(); - } + protected array $getAllTypes = ['orderconfirmation']; } diff --git a/src/Clients/PostingCategory.php b/src/Clients/PostingCategory.php index b4ba4d9..63a2550 100644 --- a/src/Clients/PostingCategory.php +++ b/src/Clients/PostingCategory.php @@ -1,4 +1,4 @@ -api); - - $client->setToEverything(); - $client->types = ['quotation']; - - return $client->getAll(); - } + protected array $getAllTypes = ['quotation']; } diff --git a/src/Clients/RecurringTemplate.php b/src/Clients/RecurringTemplate.php index 0334b94..0d03fba 100644 --- a/src/Clients/RecurringTemplate.php +++ b/src/Clients/RecurringTemplate.php @@ -1,4 +1,4 @@ -api); + + if (!$states) { + $client->setToEverything(); + } else { + $client->statuses = $states; + } + $client->types = $this->getAllTypes; + + return $client->getAll(); + } +} \ No newline at end of file diff --git a/src/Clients/Traits/GetTrait.php b/src/Clients/Traits/GetTrait.php index 4ec8f63..2d906c6 100644 --- a/src/Clients/Traits/GetTrait.php +++ b/src/Clients/Traits/GetTrait.php @@ -1,4 +1,4 @@ - Date: Thu, 12 Aug 2021 20:53:05 +0200 Subject: [PATCH 25/69] update phpunit config --- .gitignore | 1 + phpunit.xml | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index d58765b..bd7c403 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /tests/cache/ +.phpunit.cache/ # Created by https://www.gitignore.io/api/macos,composer,phpstorm # Edit at https://www.gitignore.io/?templates=macos,composer,phpstorm diff --git a/phpunit.xml b/phpunit.xml index 3135c50..479301a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,25 @@ - + verbose="true"> - + tests - \ No newline at end of file + + + + src + + + From 4cfdfd400eed69e71cbe777ca85fa811564d12f1 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 20:53:20 +0200 Subject: [PATCH 26/69] remove cache section in readme --- README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README.md b/README.md index d8c0045..6d7710a 100644 --- a/README.md +++ b/README.md @@ -25,20 +25,6 @@ $apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file $api = new \Clicksports\LexOffice\Api($apiKey); ``` -### set cache - -```php -// can be any PSR-6 compatibly cache handler -// in this example we are using symfony/cache -$cacheInterface = new \Symfony\Component\Cache\Adapter\FilesystemAdapter( - 'lexoffice', - 3600, - __DIR__ . '/cache' -); - -$api->setCacheInterface($cacheInterface); -``` - ### Contact Endpoint ```php From 1e84fc78e890803e077e733267f3b668bb1db9c7 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 21:10:13 +0200 Subject: [PATCH 27/69] update tests for clients who supports getAll($states) --- tests/Clients/CreditNoteTest.php | 13 ++++++++++--- tests/Clients/DownPaymentInvoiceTest.php | 13 ++++++++++--- tests/Clients/InvoiceTest.php | 13 ++++++++++--- tests/Clients/OrderConfirmationTest.php | 13 ++++++++++--- tests/Clients/QuotationTest.php | 13 ++++++++++--- tests/TestClient.php | 10 ++++++---- 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 153c662..068c41b 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -25,15 +25,22 @@ public function testCreate() public function testGetAll() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMultiMockObject( CreditNote::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), + [ + new Response(200, [], '{"content": ["a"], "totalPages": 1}'), + new Response(200, [], '{"content": ["b"], "totalPages": 1}') + ], ['getAll'] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); + + $response = $stub->getAll(['open']); + + $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } public function testDocument() diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index 2bc261f..da5b848 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -24,15 +24,22 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMultiMockObject( DownPaymentInvoice::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), + [ + new Response(200, [], '{"content": ["a"], "totalPages": 1}'), + new Response(200, [], '{"content": ["b"], "totalPages": 1}') + ], ['getAll'] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); + + $response = $stub->getAll(['open']); + + $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } public function testDocument() diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 856ea92..8e3d026 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -39,15 +39,22 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMultiMockObject( Invoice::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), + [ + new Response(200, [], '{"content": ["a"], "totalPages": 1}'), + new Response(200, [], '{"content": ["b"], "totalPages": 1}') + ], ['getAll'] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); + + $response = $stub->getAll(['open']); + + $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } public function testDocument() diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index e184fdc..679ffaa 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -39,15 +39,22 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMultiMockObject( OrderConfirmation::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), + [ + new Response(200, [], '{"content": ["a"], "totalPages": 1}'), + new Response(200, [], '{"content": ["b"], "totalPages": 1}') + ], ['getAll'] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); + + $response = $stub->getAll(['open']); + + $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } public function testDocument() diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 2f7212f..f60ac63 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -39,15 +39,22 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMockObject( + $stub = $this->createClientMultiMockObject( Quotation::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), + [ + new Response(200, [], '{"content": ["a"], "totalPages": 1}'), + new Response(200, [], '{"content": ["b"], "totalPages": 1}') + ], ['getAll'] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); + + $response = $stub->getAll(['open']); + + $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } public function testDocument() diff --git a/tests/TestClient.php b/tests/TestClient.php index 7d31a53..e7bde95 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -53,10 +53,11 @@ public function createApiMultiMockObject(array $responses, $methodExcept = []) } /** - * @param string $className + * @template T + * @param class-string $className * @param Response $response * @param string[] $methodExcept - * @return MockObject|ClientInterface + * @return MockObject|T */ public function createClientMockObject(string $className, Response $response, array $methodExcept = []) { @@ -64,10 +65,11 @@ public function createClientMockObject(string $className, Response $response, ar } /** - * @param string $className + * @template T + * @param class-string $className * @param Response[] $responses * @param string[] $methodExcept - * @return MockObject|ClientInterface + * @return MockObject|T */ public function createClientMultiMockObject(string $className, array $responses, array $methodExcept = []) { From 8f168ce476fe26774f2b1af835448e9f9aa22822 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 21:17:53 +0200 Subject: [PATCH 28/69] add getPage option for Clients which has already VoucherListTrait --- src/Clients/CreditNote.php | 6 ++--- src/Clients/DownPaymentInvoice.php | 6 ++--- src/Clients/Invoice.php | 6 ++--- src/Clients/OrderConfirmation.php | 6 ++--- src/Clients/Quotation.php | 6 ++--- ...cherListTrait.php => VoucherListTrait.php} | 24 +++++++++++++++++-- tests/Clients/CreditNoteTest.php | 15 ++++++++++++ tests/Clients/DownPaymentInvoiceTest.php | 15 ++++++++++++ tests/Clients/InvoiceTest.php | 15 ++++++++++++ tests/Clients/OrderConfirmationTest.php | 15 ++++++++++++ tests/Clients/QuotationTest.php | 15 ++++++++++++ tests/{Traits => }/PaginationClientTest.php | 3 +-- 12 files changed, 113 insertions(+), 19 deletions(-) rename src/Clients/Traits/{GetAllVoucherListTrait.php => VoucherListTrait.php} (52%) rename tests/{Traits => }/PaginationClientTest.php (94%) diff --git a/src/Clients/CreditNote.php b/src/Clients/CreditNote.php index c500d75..d98d537 100644 --- a/src/Clients/CreditNote.php +++ b/src/Clients/CreditNote.php @@ -5,17 +5,17 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; class CreditNote extends BaseClient { use GetTrait; use CreateFinalizeTrait; - use GetAllVoucherListTrait; + use VoucherListTrait; use DocumentClientTrait; protected string $resource = 'credit-notes'; - protected array $getAllTypes = ['creditnote']; + protected array $voucherListTypes = ['creditnote']; } diff --git a/src/Clients/DownPaymentInvoice.php b/src/Clients/DownPaymentInvoice.php index 8d14d65..6962b03 100644 --- a/src/Clients/DownPaymentInvoice.php +++ b/src/Clients/DownPaymentInvoice.php @@ -4,15 +4,15 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; class DownPaymentInvoice extends BaseClient { use GetTrait; - use GetAllVoucherListTrait; + use VoucherListTrait; use DocumentClientTrait; protected string $resource = 'down-payment-invoices'; - protected array $getAllTypes = ['downpaymentinvoice']; + protected array $voucherListTypes = ['downpaymentinvoice']; } diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index bddb891..96b533f 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -5,16 +5,16 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; class Invoice extends BaseClient { use GetTrait; - use GetAllVoucherListTrait; + use VoucherListTrait; use DocumentClientTrait; use CreateFinalizeTrait; protected string $resource = 'invoices'; - protected array $getAllTypes = ['invoice']; + protected array $voucherListTypes = ['invoice']; } diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 1d0aa71..3f23b75 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -5,16 +5,16 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; class OrderConfirmation extends BaseClient { use GetTrait; - use GetAllVoucherListTrait; + use VoucherListTrait; use CreateTrait; use DocumentClientTrait; protected string $resource = 'order-confirmations'; - protected array $getAllTypes = ['orderconfirmation']; + protected array $voucherListTypes = ['orderconfirmation']; } diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 5ad4be1..15b72da 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -5,16 +5,16 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\GetAllVoucherListTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; class Quotation extends BaseClient { use GetTrait; - use GetAllVoucherListTrait; + use VoucherListTrait; use DocumentClientTrait; use CreateFinalizeTrait; protected string $resource = 'quotations'; - protected array $getAllTypes = ['quotation']; + protected array $voucherListTypes = ['quotation']; } diff --git a/src/Clients/Traits/GetAllVoucherListTrait.php b/src/Clients/Traits/VoucherListTrait.php similarity index 52% rename from src/Clients/Traits/GetAllVoucherListTrait.php rename to src/Clients/Traits/VoucherListTrait.php index ef90a4b..84c4cec 100644 --- a/src/Clients/Traits/GetAllVoucherListTrait.php +++ b/src/Clients/Traits/VoucherListTrait.php @@ -6,8 +6,28 @@ use Clicksports\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; -trait GetAllVoucherListTrait +trait VoucherListTrait { + /** + * @param int $page + * @param string[] $states + * @return ResponseInterface + * @throws LexOfficeApiException + */ + public function getPage(int $page, array $states = []): ResponseInterface + { + $client = new VoucherList($this->api); + $client->types = $this->voucherListTypes; + + if (!$states) { + $client->setToEverything(); + } else { + $client->statuses = $states; + } + + return $client->getPage($page); + } + /** * @param string[] $states * @return ResponseInterface @@ -16,13 +36,13 @@ trait GetAllVoucherListTrait public function getAll(array $states = []): ResponseInterface { $client = new VoucherList($this->api); + $client->types = $this->voucherListTypes; if (!$states) { $client->setToEverything(); } else { $client->statuses = $states; } - $client->types = $this->getAllTypes; return $client->getAll(); } diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 068c41b..c493d9f 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -43,6 +43,21 @@ public function testGetAll() $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } + public function testGetPage() + { + $stub = $this->createClientMultiMockObject( + CreditNote::class, + [ + new Response(200, [], '{"content": [], "totalPages": 1}'), + ], + ['getPage'] + ); + + $response = $stub->getPage(0); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } + public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index da5b848..000725e 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -42,6 +42,21 @@ public function testGetAll() $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } + public function testGetPage() + { + $stub = $this->createClientMultiMockObject( + DownPaymentInvoice::class, + [ + new Response(200, [], '{"content": [], "totalPages": 1}'), + ], + ['getPage'] + ); + + $response = $stub->getPage(0); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } + public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 8e3d026..2405809 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -57,6 +57,21 @@ public function testGetAll() $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } + public function testGetPage() + { + $stub = $this->createClientMultiMockObject( + Invoice::class, + [ + new Response(200, [], '{"content": [], "totalPages": 1}'), + ], + ['getPage'] + ); + + $response = $stub->getPage(0); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } + public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 679ffaa..d6eac8e 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -57,6 +57,21 @@ public function testGetAll() $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } + public function testGetPage() + { + $stub = $this->createClientMultiMockObject( + OrderConfirmation::class, + [ + new Response(200, [], '{"content": [], "totalPages": 1}'), + ], + ['getPage'] + ); + + $response = $stub->getPage(0); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } + public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index f60ac63..2610509 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -57,6 +57,21 @@ public function testGetAll() $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); } + public function testGetPage() + { + $stub = $this->createClientMultiMockObject( + Quotation::class, + [ + new Response(200, [], '{"content": [], "totalPages": 1}'), + ], + ['getPage'] + ); + + $response = $stub->getPage(0); + + $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + } + public function testDocument() { $stub = $this->createClientMockObject( diff --git a/tests/Traits/PaginationClientTest.php b/tests/PaginationClientTest.php similarity index 94% rename from tests/Traits/PaginationClientTest.php rename to tests/PaginationClientTest.php index 1932132..ebab09a 100644 --- a/tests/Traits/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -1,8 +1,7 @@ Date: Thu, 12 Aug 2021 21:22:10 +0200 Subject: [PATCH 29/69] add phpdoc for voucherListTypes --- src/Clients/CreditNote.php | 3 ++- src/Clients/DownPaymentInvoice.php | 4 +++- src/Clients/Invoice.php | 4 +++- src/Clients/OrderConfirmation.php | 4 +++- src/Clients/Quotation.php | 4 +++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Clients/CreditNote.php b/src/Clients/CreditNote.php index d98d537..6b8711d 100644 --- a/src/Clients/CreditNote.php +++ b/src/Clients/CreditNote.php @@ -5,8 +5,8 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; class CreditNote extends BaseClient { @@ -17,5 +17,6 @@ class CreditNote extends BaseClient protected string $resource = 'credit-notes'; + /** @var string[] */ protected array $voucherListTypes = ['creditnote']; } diff --git a/src/Clients/DownPaymentInvoice.php b/src/Clients/DownPaymentInvoice.php index 6962b03..354e9f4 100644 --- a/src/Clients/DownPaymentInvoice.php +++ b/src/Clients/DownPaymentInvoice.php @@ -4,8 +4,8 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; class DownPaymentInvoice extends BaseClient { @@ -14,5 +14,7 @@ class DownPaymentInvoice extends BaseClient use DocumentClientTrait; protected string $resource = 'down-payment-invoices'; + + /** @var string[] */ protected array $voucherListTypes = ['downpaymentinvoice']; } diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index 96b533f..30f8992 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -5,8 +5,8 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; class Invoice extends BaseClient { @@ -16,5 +16,7 @@ class Invoice extends BaseClient use CreateFinalizeTrait; protected string $resource = 'invoices'; + + /** @var string[] */ protected array $voucherListTypes = ['invoice']; } diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 3f23b75..c7fcb7c 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -5,8 +5,8 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; class OrderConfirmation extends BaseClient { @@ -16,5 +16,7 @@ class OrderConfirmation extends BaseClient use DocumentClientTrait; protected string $resource = 'order-confirmations'; + + /** @var string[] */ protected array $voucherListTypes = ['orderconfirmation']; } diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 15b72da..aeb94e5 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -5,8 +5,8 @@ use Clicksports\LexOffice\BaseClient; use Clicksports\LexOffice\Clients\Traits\CreateFinalizeTrait; use Clicksports\LexOffice\Clients\Traits\DocumentClientTrait; -use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; use Clicksports\LexOffice\Clients\Traits\GetTrait; +use Clicksports\LexOffice\Clients\Traits\VoucherListTrait; class Quotation extends BaseClient { @@ -16,5 +16,7 @@ class Quotation extends BaseClient use CreateFinalizeTrait; protected string $resource = 'quotations'; + + /** @var string[] */ protected array $voucherListTypes = ['quotation']; } From f36231457c27fdc11f154e3d8ba23c247bb50286 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 21:27:06 +0200 Subject: [PATCH 30/69] update readme --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d7710a..fcad977 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ $response = $api->country()->getAll(); ### Invoices Endpoint ```php $response = $api->invoice()->getAll(); +$response = $api->invoice()->getAll(array $states); +$response = $api->invoice()->getPage(0); +$response = $api->invoice()->getPage(0, array $states); $response = $api->invoice()->get($entityId); $response = $api->invoice()->create($data); $response = $api->invoice()->document($entityId); // get document ID @@ -65,7 +68,9 @@ $response = $api->invoice()->document($entityId, true); // get file content ### Down Payment Invoices Endpoint ```php $response = $api->downPaymentInvoice()->getAll(); -$response = $api->downPaymentInvoice()->get($entityId); +$response = $api->downPaymentInvoice()->getAll(array $states); +$response = $api->downPaymentInvoice()->getPage(0); +$response = $api->downPaymentInvoice()->getPage(0, array $states);$response = $api->downPaymentInvoice()->get($entityId); $response = $api->downPaymentInvoice()->create($data); $response = $api->downPaymentInvoice()->document($entityId); // get document ID $response = $api->downPaymentInvoice()->document($entityId, true); // get file content @@ -74,6 +79,9 @@ $response = $api->downPaymentInvoice()->document($entityId, true); // get file c ### Order Confirmation Endpoint ```php $response = $api->orderConfirmation()->getAll(); +$response = $api->orderConfirmation()->getAll(array $states); +$response = $api->orderConfirmation()->getPage(0); +$response = $api->orderConfirmation()->getPage(0, array $states); $response = $api->orderConfirmation()->get($entityId); $response = $api->orderConfirmation()->create($data); $response = $api->orderConfirmation()->document($entityId); // get document ID @@ -83,6 +91,9 @@ $response = $api->orderConfirmation()->document($entityId, true); // get file co ### Quotation Endpoint ```php $response = $api->quotation()->getAll(); +$response = $api->quotation()->getAll(array $states); +$response = $api->quotation()->getPage(0); +$response = $api->quotation()->getPage(0, array $states); $response = $api->quotation()->get($entityId); $response = $api->quotation()->create($data); $response = $api->quotation()->document($entityId); // get document ID @@ -103,6 +114,9 @@ $response = $api->voucher()->document($entityId, true); // get file content ### Credit Notes Endpoint ```php $response = $api->creditNote()->getAll(); +$response = $api->creditNote()->getAll(array $states); +$response = $api->creditNote()->getPage(0); +$response = $api->creditNote()->getPage(0, array $states); $response = $api->creditNote()->get($entityId); $response = $api->creditNote()->create($data); $response = $api->creditNote()->document($entityId); // get document ID From 16134504c1668b68a2519d79db8a7dec4fd8c524 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Thu, 12 Aug 2021 21:35:29 +0200 Subject: [PATCH 31/69] small fixes --- .gitignore | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bd7c403..8c28fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,7 @@ crashlytics.properties crashlytics-build.properties fabric.properties -# Editor-based Rest Country +# Editor-based Rest Client .idea/httpRequests # Android studio 3.1+ serialized cache file diff --git a/README.md b/README.md index fcad977..e94de27 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ $response = $api->invoice()->document($entityId, true); // get file content $response = $api->downPaymentInvoice()->getAll(); $response = $api->downPaymentInvoice()->getAll(array $states); $response = $api->downPaymentInvoice()->getPage(0); -$response = $api->downPaymentInvoice()->getPage(0, array $states);$response = $api->downPaymentInvoice()->get($entityId); +$response = $api->downPaymentInvoice()->getPage(0, array $states); +$response = $api->downPaymentInvoice()->get($entityId); $response = $api->downPaymentInvoice()->create($data); $response = $api->downPaymentInvoice()->document($entityId); // get document ID $response = $api->downPaymentInvoice()->document($entityId, true); // get file content From 857039274ba328f97db71316c9d5f821960e5e79 Mon Sep 17 00:00:00 2001 From: Alexander Schlegel Date: Mon, 23 Aug 2021 10:09:52 +0200 Subject: [PATCH 32/69] add filters for VoucherList and Contact --- src/Clients/Contact.php | 11 ++++++++++- src/Clients/VoucherList.php | 29 ++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index 00c4015..739e9ed 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -17,6 +17,12 @@ class Contact extends PaginationClient public string $sortProperty = 'name'; + public ?int $number = null; + + public ?bool $customer = null; + + public ?bool $vendor = null; + /** * @param int $page * @return string @@ -25,6 +31,9 @@ public function generateUrl(int $page): string { return parent::generateUrl($page) . '&direction=' . $this->sortDirection . - '&property=' .$this->sortProperty; + '&property=' . $this->sortProperty . + ($this->number !== null ? '&number=' . $this->number : '' ) . + ($this->customer !== null ? '&customer=' . $this->customer : '' ) . + ($this->vendor !== null ? '&vendor=' . $this->vendor : '' ); } } diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index e569a12..fcfbc95 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -3,6 +3,7 @@ namespace Clicksports\LexOffice\Clients; use Clicksports\LexOffice\PaginationClient; +use DateTimeInterface; class VoucherList extends PaginationClient { @@ -17,6 +18,22 @@ class VoucherList extends PaginationClient /** @var string[] */ public array $statuses = []; + public ?bool $archived = null; + + public ?string $contactId = null; + + public ?DateTimeInterface $voucherDateFrom = null; + + public ?DateTimeInterface $voucherDateTo = null; + + public ?DateTimeInterface $createdDateFrom = null; + + public ?DateTimeInterface $createdDateTo = null; + + public ?DateTimeInterface $updatedDateFrom = null; + + public ?DateTimeInterface $updatedDateTo = null; + /** * @return $this */ @@ -54,9 +71,19 @@ public function setToEverything(): self */ public function generateUrl(int $page): string { + $dateFormat = DateTimeInterface::ISO8601; + return parent::generateUrl($page) . '&sort=' . $this->sortColumn . ',' . $this->sortDirection . '&voucherType=' . implode(',', $this->types) . - '&voucherStatus=' . implode(',', $this->statuses); + '&voucherStatus=' . implode(',', $this->statuses) . + ($this->archived !== null ? '&archived=' . $this->archived : '') . + ($this->contactId !== null ? '&contactId=' . $this->contactId : '') . + ($this->voucherDateFrom !== null ? '&voucherDateFrom=' . $this->voucherDateFrom->format($dateFormat) : '') . + ($this->voucherDateTo !== null ? '&voucherDateTo=' . $this->voucherDateTo->format($dateFormat) : '') . + ($this->createdDateFrom !== null ? '&createdDateFrom=' . $this->createdDateFrom->format($dateFormat) : '') . + ($this->createdDateTo !== null ? '&createdDateTo=' . $this->createdDateTo->format($dateFormat) : '') . + ($this->updatedDateFrom !== null ? '&updatedDateFrom=' . $this->updatedDateFrom->format($dateFormat) : '') . + ($this->updatedDateTo !== null ? '&updatedDateTo=' . $this->updatedDateTo->format($dateFormat) : ''); } } From 456467c05d1a8042a9a5c942a4e8ed7be73ddadb Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 21:18:24 +0100 Subject: [PATCH 33/69] update phpstan --- composer.json | 2 +- composer.lock | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 995acf4..82c47d8 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.0", - "phpstan/phpstan": "^0.12.32" + "phpstan/phpstan": "^1.10" }, "suggest": { "kevinrob/guzzle-cache-middleware": "*" diff --git a/composer.lock b/composer.lock index 58b44d2..ed82891 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "32ef1eba9abeaeccb0e0e2d35092f155", + "content-hash": "8d09f9db68a84de1f3d508b1301f243b", "packages": [ { "name": "guzzlehttp/guzzle", @@ -902,20 +902,20 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.100", + "version": "1.10.44", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "48236ddf823547081b2b153d1cd2994b784328c3" + "reference": "bf84367c53a23f759513985c54ffe0d0c249825b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/48236ddf823547081b2b153d1cd2994b784328c3", - "reference": "48236ddf823547081b2b153d1cd2994b784328c3", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bf84367c53a23f759513985c54ffe0d0c249825b", + "reference": "bf84367c53a23f759513985c54ffe0d0c249825b", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -925,11 +925,6 @@ "phpstan.phar" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -940,9 +935,16 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.100" + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" }, "funding": [ { @@ -958,7 +960,7 @@ "type": "tidelift" } ], - "time": "2022-11-01T09:52:08+00:00" + "time": "2023-11-21T16:30:46+00:00" }, { "name": "phpunit/php-code-coverage", From 24b861eb667f09c0f359df33f809c5cbb0dfa0ca Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 21:57:39 +0100 Subject: [PATCH 34/69] test fix after merge --- .gitignore | 121 ++++- composer.json | 4 +- composer.lock | 587 +++++++++-------------- phpunit.xml | 43 +- tests/ApiTest.php | 24 +- tests/Clients/ContactTest.php | 14 +- tests/Clients/CountryTest.php | 4 +- tests/Clients/CreditNoteTest.php | 38 +- tests/Clients/DownPaymentInvoiceTest.php | 51 +- tests/Clients/EventTest.php | 11 +- tests/Clients/FileTest.php | 24 +- tests/Clients/InvoiceTest.php | 41 +- tests/Clients/OrderConfirmationTest.php | 41 +- tests/Clients/PaymentConditionTest.php | 4 +- tests/Clients/PaymentTest.php | 4 +- tests/Clients/PostingCategoryTest.php | 4 +- tests/Clients/ProfileTest.php | 3 +- tests/Clients/QuotationTest.php | 41 +- tests/Clients/RecurringTemplateTest.php | 6 +- tests/Clients/VoucherListTest.php | 3 +- tests/Clients/VoucherTest.php | 14 +- tests/PaginationClientTest.php | 12 +- tests/TestClient.php | 40 +- 23 files changed, 438 insertions(+), 696 deletions(-) diff --git a/.gitignore b/.gitignore index 8c28fd0..666c262 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ +/cache/ -/tests/cache/ -.phpunit.cache/ -# Created by https://www.gitignore.io/api/macos,composer,phpstorm -# Edit at https://www.gitignore.io/?templates=macos,composer,phpstorm +# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,linux,composer,phpunit,phpstorm+all,visualstudiocode +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,linux,composer,phpunit,phpstorm+all,visualstudiocode ### Composer ### composer.phar @@ -12,6 +11,21 @@ composer.phar # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file # composer.lock +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + ### macOS ### # General .DS_Store @@ -21,6 +35,7 @@ composer.phar # Icon must end with two \r Icon + # Thumbnails ._* @@ -40,8 +55,12 @@ Network Trash Folder Temporary Items .apdisk -### PhpStorm ### -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +### macOS Patch ### +# iCloud generated files +*.icloud + +### PhpStorm+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff @@ -51,6 +70,9 @@ Temporary Items .idea/**/dictionaries .idea/**/shelf +# AWS User-specific +.idea/**/aws.xml + # Generated files .idea/**/contentModel.xml @@ -71,6 +93,9 @@ Temporary Items # When using Gradle or Maven with auto-import, you should exclude module files, # since they will be recreated, and may cause churn. Uncomment if using # auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml # .idea/modules.xml # .idea/*.iml # .idea/modules @@ -98,6 +123,9 @@ atlassian-ide-plugin.xml # Cursive Clojure plugin .idea/replstate.xml +# SonarLint plugin +.idea/sonarlint/ + # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties @@ -110,22 +138,73 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser -### PhpStorm Patch ### -# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 - -# *.iml -# modules.xml -# .idea/misc.xml -# *.ipr +### PhpStorm+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. -# Sonarlint plugin -.idea/**/sonarlint/ +.idea/* -# SonarQube Plugin -.idea/**/sonarIssues.xml +!.idea/codeStyles +!.idea/runConfigurations -# Markdown Navigator plugin -.idea/**/markdown-navigator.xml -.idea/**/markdown-navigator/ +### PHPUnit ### +# Covers PHPUnit +# Reference: https://phpunit.de/ -# End of https://www.gitignore.io/api/macos,composer,phpstorm +# Generated files +.phpunit.result.cache +.phpunit.cache + +# PHPUnit +/app/phpunit.xml +/phpunit.xml + +# Build data +/build/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/windows,macos,linux,composer,phpunit,phpstorm+all,visualstudiocode diff --git a/composer.json b/composer.json index 82c47d8..e46b873 100644 --- a/composer.json +++ b/composer.json @@ -20,8 +20,8 @@ "guzzlehttp/guzzle": "^6.2 | ^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.0", - "phpstan/phpstan": "^1.10" + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.4" }, "suggest": { "kevinrob/guzzle-cache-middleware": "*" diff --git a/composer.lock b/composer.lock index ed82891..fa622cb 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8d09f9db68a84de1f3d508b1301f243b", + "content-hash": "a42c7df46aebdc60ea2f2bb9d5136182", "packages": [ { "name": "guzzlehttp/guzzle", @@ -604,76 +604,6 @@ } ], "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "shasum": "" - }, - "require": { - "php": "^8.1" - }, - "require-dev": { - "doctrine/coding-standard": "^11", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", - "vimeo/psalm": "^5.4" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "https://ocramius.github.io/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", - "keywords": [ - "constructor", - "instantiate" - ], - "support": { - "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" - }, - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Finstantiator", - "type": "tidelift" - } - ], - "time": "2022-12-30T00:23:10+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.11.1", @@ -964,16 +894,16 @@ }, { "name": "phpunit/php-code-coverage", - "version": "9.2.29", + "version": "10.1.9", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" + "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", - "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/a56a9ab2f680246adcf3db43f38ddf1765774735", + "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735", "shasum": "" }, "require": { @@ -981,18 +911,18 @@ "ext-libxml": "*", "ext-xmlwriter": "*", "nikic/php-parser": "^4.15", - "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0.3", - "phpunit/php-text-template": "^2.0.2", - "sebastian/code-unit-reverse-lookup": "^2.0.2", - "sebastian/complexity": "^2.0", - "sebastian/environment": "^5.1.2", - "sebastian/lines-of-code": "^1.0.3", - "sebastian/version": "^3.0.1", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-text-template": "^3.0", + "sebastian/code-unit-reverse-lookup": "^3.0", + "sebastian/complexity": "^3.0", + "sebastian/environment": "^6.0", + "sebastian/lines-of-code": "^2.0", + "sebastian/version": "^4.0", "theseer/tokenizer": "^1.2.0" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.1" }, "suggest": { "ext-pcov": "PHP extension that provides line coverage", @@ -1001,7 +931,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.2-dev" + "dev-main": "10.1-dev" } }, "autoload": { @@ -1030,7 +960,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.9" }, "funding": [ { @@ -1038,32 +968,32 @@ "type": "github" } ], - "time": "2023-09-19T04:57:46+00:00" + "time": "2023-11-23T12:23:20+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.6", + "version": "4.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", - "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c", + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -1090,7 +1020,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.6" + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0" }, "funding": [ { @@ -1098,28 +1029,28 @@ "type": "github" } ], - "time": "2021-12-02T12:48:52+00:00" + "time": "2023-08-31T06:24:48+00:00" }, { "name": "phpunit/php-invoker", - "version": "3.1.1", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67" + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/5a10147d0aaf65b58940a0b72f71c9ac0423cc67", - "reference": "5a10147d0aaf65b58940a0b72f71c9ac0423cc67", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { "ext-pcntl": "*", - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "suggest": { "ext-pcntl": "*" @@ -1127,7 +1058,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -1153,7 +1084,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-invoker/issues", - "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" }, "funding": [ { @@ -1161,32 +1092,32 @@ "type": "github" } ], - "time": "2020-09-28T05:58:55+00:00" + "time": "2023-02-03T06:56:09+00:00" }, { "name": "phpunit/php-text-template", - "version": "2.0.4", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28" + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", - "reference": "5da5f67fc95621df9ff4c4e5a84d6a8a2acf7c28", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -1212,7 +1143,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1" }, "funding": [ { @@ -1220,32 +1152,32 @@ "type": "github" } ], - "time": "2020-10-26T05:33:50+00:00" + "time": "2023-08-31T14:07:24+00:00" }, { "name": "phpunit/php-timer", - "version": "5.0.3", + "version": "6.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2" + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", - "reference": "5a63ce20ed1b5bf577850e2c4e87f4aa902afbd2", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-main": "6.0-dev" } }, "autoload": { @@ -1271,7 +1203,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" }, "funding": [ { @@ -1279,24 +1211,23 @@ "type": "github" } ], - "time": "2020-10-26T13:16:10+00:00" + "time": "2023-02-03T06:57:52+00:00" }, { "name": "phpunit/phpunit", - "version": "9.6.13", + "version": "10.4.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be" + "reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f3d767f7f9e191eab4189abe41ab37797e30b1be", - "reference": "f3d767f7f9e191eab4189abe41ab37797e30b1be", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/cacd8b9dd224efa8eb28beb69004126c7ca1a1a1", + "reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", @@ -1306,27 +1237,26 @@ "myclabs/deep-copy": "^1.10.1", "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", - "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.28", - "phpunit/php-file-iterator": "^3.0.5", - "phpunit/php-invoker": "^3.1.1", - "phpunit/php-text-template": "^2.0.3", - "phpunit/php-timer": "^5.0.2", - "sebastian/cli-parser": "^1.0.1", - "sebastian/code-unit": "^1.0.6", - "sebastian/comparator": "^4.0.8", - "sebastian/diff": "^4.0.3", - "sebastian/environment": "^5.1.3", - "sebastian/exporter": "^4.0.5", - "sebastian/global-state": "^5.0.1", - "sebastian/object-enumerator": "^4.0.3", - "sebastian/resource-operations": "^3.0.3", - "sebastian/type": "^3.2", - "sebastian/version": "^3.0.2" + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.1.5", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-invoker": "^4.0", + "phpunit/php-text-template": "^3.0", + "phpunit/php-timer": "^6.0", + "sebastian/cli-parser": "^2.0", + "sebastian/code-unit": "^2.0", + "sebastian/comparator": "^5.0", + "sebastian/diff": "^5.0", + "sebastian/environment": "^6.0", + "sebastian/exporter": "^5.1", + "sebastian/global-state": "^6.0.1", + "sebastian/object-enumerator": "^5.0", + "sebastian/recursion-context": "^5.0", + "sebastian/type": "^4.0", + "sebastian/version": "^4.0" }, "suggest": { - "ext-soap": "To be able to generate mocks based on WSDL files", - "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + "ext-soap": "To be able to generate mocks based on WSDL files" }, "bin": [ "phpunit" @@ -1334,7 +1264,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.6-dev" + "dev-main": "10.4-dev" } }, "autoload": { @@ -1366,7 +1296,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.13" + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.2" }, "funding": [ { @@ -1382,32 +1312,32 @@ "type": "tidelift" } ], - "time": "2023-09-19T05:39:22+00:00" + "time": "2023-10-26T07:21:45+00:00" }, { "name": "sebastian/cli-parser", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2" + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/442e7c7e687e42adc03470c7b668bc4b2402c0b2", - "reference": "442e7c7e687e42adc03470c7b668bc4b2402c0b2", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "2.0-dev" } }, "autoload": { @@ -1430,7 +1360,7 @@ "homepage": "https://github.com/sebastianbergmann/cli-parser", "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" }, "funding": [ { @@ -1438,32 +1368,32 @@ "type": "github" } ], - "time": "2020-09-28T06:08:49+00:00" + "time": "2023-02-03T06:58:15+00:00" }, { "name": "sebastian/code-unit", - "version": "1.0.8", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120" + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/1fc9f64c0927627ef78ba436c9b17d967e68e120", - "reference": "1fc9f64c0927627ef78ba436c9b17d967e68e120", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "2.0-dev" } }, "autoload": { @@ -1486,7 +1416,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit", "support": { "issues": "https://github.com/sebastianbergmann/code-unit/issues", - "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" }, "funding": [ { @@ -1494,32 +1424,32 @@ "type": "github" } ], - "time": "2020-10-26T13:08:54+00:00" + "time": "2023-02-03T06:58:43+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "2.0.3", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5" + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", - "reference": "ac91f01ccec49fb77bdc6fd1e548bc70f7faa3e5", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -1541,7 +1471,7 @@ "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", "support": { "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", - "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" }, "funding": [ { @@ -1549,34 +1479,36 @@ "type": "github" } ], - "time": "2020-09-28T05:30:19+00:00" + "time": "2023-02-03T06:59:15+00:00" }, { "name": "sebastian/comparator", - "version": "4.0.8", + "version": "5.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "fa0f136dd2334583309d32b62544682ee972b51a" + "reference": "2db5010a484d53ebf536087a70b4a5423c102372" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/fa0f136dd2334583309d32b62544682ee972b51a", - "reference": "fa0f136dd2334583309d32b62544682ee972b51a", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", + "reference": "2db5010a484d53ebf536087a70b4a5423c102372", "shasum": "" }, "require": { - "php": ">=7.3", - "sebastian/diff": "^4.0", - "sebastian/exporter": "^4.0" + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/diff": "^5.0", + "sebastian/exporter": "^5.0" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "5.0-dev" } }, "autoload": { @@ -1615,7 +1547,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.8" + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" }, "funding": [ { @@ -1623,33 +1556,33 @@ "type": "github" } ], - "time": "2022-09-14T12:41:17+00:00" + "time": "2023-08-14T13:18:12+00:00" }, { "name": "sebastian/complexity", - "version": "2.0.2", + "version": "3.1.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88" + "reference": "68cfb347a44871f01e33ab0ef8215966432f6957" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/739b35e53379900cc9ac327b2147867b8b6efd88", - "reference": "739b35e53379900cc9ac327b2147867b8b6efd88", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68cfb347a44871f01e33ab0ef8215966432f6957", + "reference": "68cfb347a44871f01e33ab0ef8215966432f6957", "shasum": "" }, "require": { - "nikic/php-parser": "^4.7", - "php": ">=7.3" + "nikic/php-parser": "^4.10", + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-main": "3.1-dev" } }, "autoload": { @@ -1672,7 +1605,8 @@ "homepage": "https://github.com/sebastianbergmann/complexity", "support": { "issues": "https://github.com/sebastianbergmann/complexity/issues", - "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/3.1.0" }, "funding": [ { @@ -1680,33 +1614,33 @@ "type": "github" } ], - "time": "2020-10-26T15:52:27+00:00" + "time": "2023-09-28T11:50:59+00:00" }, { "name": "sebastian/diff", - "version": "4.0.5", + "version": "5.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", - "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3", + "phpunit/phpunit": "^10.0", "symfony/process": "^4.2 || ^5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "5.0-dev" } }, "autoload": { @@ -1738,7 +1672,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" }, "funding": [ { @@ -1746,27 +1681,27 @@ "type": "github" } ], - "time": "2023-05-07T05:35:17+00:00" + "time": "2023-05-01T07:48:21+00:00" }, { "name": "sebastian/environment", - "version": "5.1.5", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed" + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", - "reference": "830c43a844f1f8d5b7a1f6d6076b784454d8b7ed", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "suggest": { "ext-posix": "*" @@ -1774,7 +1709,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.1-dev" + "dev-main": "6.0-dev" } }, "autoload": { @@ -1793,7 +1728,7 @@ } ], "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", + "homepage": "https://github.com/sebastianbergmann/environment", "keywords": [ "Xdebug", "environment", @@ -1801,7 +1736,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/5.1.5" + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" }, "funding": [ { @@ -1809,34 +1745,34 @@ "type": "github" } ], - "time": "2023-02-03T06:03:51+00:00" + "time": "2023-04-11T05:39:26+00:00" }, { "name": "sebastian/exporter", - "version": "4.0.5", + "version": "5.1.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d" + "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", - "reference": "ac230ed27f0f98f597c8a2b6eb7ac563af5e5b9d", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/64f51654862e0f5e318db7e9dcc2292c63cdbddc", + "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc", "shasum": "" }, "require": { - "php": ">=7.3", - "sebastian/recursion-context": "^4.0" + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/recursion-context": "^5.0" }, "require-dev": { - "ext-mbstring": "*", - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "5.1-dev" } }, "autoload": { @@ -1878,7 +1814,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.5" + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.1" }, "funding": [ { @@ -1886,38 +1823,35 @@ "type": "github" } ], - "time": "2022-09-14T06:03:37+00:00" + "time": "2023-09-24T13:22:09+00:00" }, { "name": "sebastian/global-state", - "version": "5.0.6", + "version": "6.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bde739e7565280bda77be70044ac1047bc007e34" + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", - "reference": "bde739e7565280bda77be70044ac1047bc007e34", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", "shasum": "" }, "require": { - "php": ">=7.3", - "sebastian/object-reflector": "^2.0", - "sebastian/recursion-context": "^4.0" + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" }, "require-dev": { "ext-dom": "*", - "phpunit/phpunit": "^9.3" - }, - "suggest": { - "ext-uopz": "*" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "5.0-dev" + "dev-main": "6.0-dev" } }, "autoload": { @@ -1942,7 +1876,8 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" }, "funding": [ { @@ -1950,33 +1885,33 @@ "type": "github" } ], - "time": "2023-08-02T09:26:13+00:00" + "time": "2023-07-19T07:19:23+00:00" }, { "name": "sebastian/lines-of-code", - "version": "1.0.3", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc" + "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/c1c2e997aa3146983ed888ad08b15470a2e22ecc", - "reference": "c1c2e997aa3146983ed888ad08b15470a2e22ecc", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/649e40d279e243d985aa8fb6e74dd5bb28dc185d", + "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d", "shasum": "" }, "require": { - "nikic/php-parser": "^4.6", - "php": ">=7.3" + "nikic/php-parser": "^4.10", + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "2.0-dev" } }, "autoload": { @@ -1999,7 +1934,8 @@ "homepage": "https://github.com/sebastianbergmann/lines-of-code", "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.1" }, "funding": [ { @@ -2007,34 +1943,34 @@ "type": "github" } ], - "time": "2020-11-28T06:42:11+00:00" + "time": "2023-08-31T09:25:50+00:00" }, { "name": "sebastian/object-enumerator", - "version": "4.0.4", + "version": "5.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "5c9eeac41b290a3712d88851518825ad78f45c71" + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71", - "reference": "5c9eeac41b290a3712d88851518825ad78f45c71", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", "shasum": "" }, "require": { - "php": ">=7.3", - "sebastian/object-reflector": "^2.0", - "sebastian/recursion-context": "^4.0" + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "5.0-dev" } }, "autoload": { @@ -2056,7 +1992,7 @@ "homepage": "https://github.com/sebastianbergmann/object-enumerator/", "support": { "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", - "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" }, "funding": [ { @@ -2064,32 +2000,32 @@ "type": "github" } ], - "time": "2020-10-26T13:12:34+00:00" + "time": "2023-02-03T07:08:32+00:00" }, { "name": "sebastian/object-reflector", - "version": "2.0.4", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7" + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", - "reference": "b4f479ebdbf63ac605d183ece17d8d7fe49c15c7", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-main": "3.0-dev" } }, "autoload": { @@ -2111,7 +2047,7 @@ "homepage": "https://github.com/sebastianbergmann/object-reflector/", "support": { "issues": "https://github.com/sebastianbergmann/object-reflector/issues", - "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" }, "funding": [ { @@ -2119,32 +2055,32 @@ "type": "github" } ], - "time": "2020-10-26T13:14:26+00:00" + "time": "2023-02-03T07:06:18+00:00" }, { "name": "sebastian/recursion-context", - "version": "4.0.5", + "version": "5.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1" + "reference": "05909fb5bc7df4c52992396d0116aed689f93712" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", - "reference": "e75bd0f07204fec2a0af9b0f3cfe97d05f92efc1", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.3" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0-dev" + "dev-main": "5.0-dev" } }, "autoload": { @@ -2174,7 +2110,7 @@ "homepage": "https://github.com/sebastianbergmann/recursion-context", "support": { "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.5" + "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0" }, "funding": [ { @@ -2182,87 +2118,32 @@ "type": "github" } ], - "time": "2023-02-03T06:07:39+00:00" - }, - { - "name": "sebastian/resource-operations", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/resource-operations.git", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "reference": "0f4443cb3a1d92ce809899753bc0d5d5a8dd19a8", - "shasum": "" - }, - "require": { - "php": ">=7.3" - }, - "require-dev": { - "phpunit/phpunit": "^9.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides a list of PHP built-in functions that operate on resources", - "homepage": "https://www.github.com/sebastianbergmann/resource-operations", - "support": { - "issues": "https://github.com/sebastianbergmann/resource-operations/issues", - "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2020-09-28T06:45:17+00:00" + "time": "2023-02-03T07:05:40+00:00" }, { "name": "sebastian/type", - "version": "3.2.1", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7" + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", - "reference": "75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^10.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.2-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -2285,7 +2166,7 @@ "homepage": "https://github.com/sebastianbergmann/type", "support": { "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/3.2.1" + "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" }, "funding": [ { @@ -2293,29 +2174,29 @@ "type": "github" } ], - "time": "2023-02-03T06:13:03+00:00" + "time": "2023-02-03T07:10:45+00:00" }, { "name": "sebastian/version", - "version": "3.0.2", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/version.git", - "reference": "c6c1022351a901512170118436c764e473f6de8c" + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c", - "reference": "c6c1022351a901512170118436c764e473f6de8c", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", "shasum": "" }, "require": { - "php": ">=7.3" + "php": ">=8.1" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-main": "4.0-dev" } }, "autoload": { @@ -2338,7 +2219,7 @@ "homepage": "https://github.com/sebastianbergmann/version", "support": { "issues": "https://github.com/sebastianbergmann/version/issues", - "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" }, "funding": [ { @@ -2346,7 +2227,7 @@ "type": "github" } ], - "time": "2020-09-28T06:39:44+00:00" + "time": "2023-02-07T11:34:05+00:00" }, { "name": "theseer/tokenizer", diff --git a/phpunit.xml b/phpunit.xml index 479301a..fe4d9ef 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,25 +1,22 @@ - - - - tests - - - - - - src - - + + + + tests + + + + + + src + + diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 9c59b20..9ee08e5 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -22,10 +22,9 @@ class ApiTest extends TestClient { - public function createApiMockObject(Response $response, $methodExcept = []) + public function createApiMockObject(Response $response) { - $stub = parent::createApiMockObject($response, $methodExcept); - + $stub = parent::createApiMockObject($response); $stub->newRequest('GET', '/'); return $stub; @@ -33,24 +32,7 @@ public function createApiMockObject(Response $response, $methodExcept = []) public function testClients() { - $stub = $this->createApiMockObject(new Response(), [ - 'contact', - 'country', - 'event', - 'invoice', - 'downPaymentInvoice', - 'orderConfirmation', - 'quotation', - 'voucher', - 'voucherlist', - 'profile', - 'creditNote', - 'payment', - 'paymentCondition', - 'file', - 'recurringTemplate', - 'postingCategory' - ]); + $stub = $this->createApiMockObject(new Response()); $this->assertInstanceOf(Country::class, $stub->country()); $this->assertInstanceOf(Contact::class, $stub->contact()); diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index a9f5332..b759738 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -1,4 +1,4 @@ -createClientMockObject( Contact::class, - new Response(200, [], 'body'), - ['generateUrl'] + new Response(200, [], 'body') ); $this->assertEquals( @@ -26,8 +25,7 @@ public function testCreate() { $stub = $this->createClientMockObject( Contact::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -41,8 +39,7 @@ public function testGet() { $stub = $this->createClientMockObject( Contact::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -54,8 +51,7 @@ public function testUpdate() { $stub = $this->createClientMockObject( Contact::class, - new Response(200, [], 'body'), - ['update'] + new Response(200, [], 'body') ); $response = $stub->update('resource-id', []); diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php index b25a770..ab6d6c5 100644 --- a/tests/Clients/CountryTest.php +++ b/tests/Clients/CountryTest.php @@ -2,7 +2,6 @@ namespace Clicksports\LexOffice\Tests\Clients; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Clients\Country; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -13,8 +12,7 @@ public function testGetAll() { $stub = $this->createClientMockObject( Country::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index c493d9f..f711cf4 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -1,4 +1,4 @@ -createClientMockObject( CreditNote::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -25,36 +24,13 @@ public function testCreate() public function testGetAll() { - $stub = $this->createClientMultiMockObject( + $stub = $this->createClientMockObject( CreditNote::class, - [ - new Response(200, [], '{"content": ["a"], "totalPages": 1}'), - new Response(200, [], '{"content": ["b"], "totalPages": 1}') - ], - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); - $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); - - $response = $stub->getAll(['open']); - - $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testGetPage() - { - $stub = $this->createClientMultiMockObject( - CreditNote::class, - [ - new Response(200, [], '{"content": [], "totalPages": 1}'), - ], - ['getPage'] - ); - - $response = $stub->getPage(0); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } @@ -62,8 +38,7 @@ public function testDocument() { $stub = $this->createClientMockObject( CreditNote::class, - new Response(200, [], '{"documentFileId": "fake-id"}'), - ['document'] + new Response(200, [], '{"documentFileId": "fake-id"}') ); $response = $stub->document('resource-id'); @@ -78,8 +53,7 @@ public function testDocument() [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') - ], - ['document'] + ] ); $response = $stub->document('resource-id', true); diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index 000725e..fe895d5 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -1,59 +1,22 @@ -createClientMockObject( - DownPaymentInvoice::class, - new Response(200, [], 'body'), - ['get'] - ); - - $response = $stub->get('resource-id'); - - $this->assertEquals('body', $response->getBody()->__toString()); - } - public function testGetAll() { - $stub = $this->createClientMultiMockObject( + $stub = $this->createClientMockObject( DownPaymentInvoice::class, - [ - new Response(200, [], '{"content": ["a"], "totalPages": 1}'), - new Response(200, [], '{"content": ["b"], "totalPages": 1}') - ], - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); - $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); - - $response = $stub->getAll(['open']); - - $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testGetPage() - { - $stub = $this->createClientMultiMockObject( - DownPaymentInvoice::class, - [ - new Response(200, [], '{"content": [], "totalPages": 1}'), - ], - ['getPage'] - ); - - $response = $stub->getPage(0); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } @@ -61,8 +24,7 @@ public function testDocument() { $stub = $this->createClientMockObject( DownPaymentInvoice::class, - new Response(200, [], '{"documentFileId": "fake-id"}'), - ['document'] + new Response(200, [], '{"documentFileId": "fake-id"}') ); $response = $stub->document('resource-id'); @@ -77,8 +39,7 @@ public function testDocument() [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') - ], - ['document'] + ] ); $response = $stub->document('resource-id', true); diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index 5cf86c4..b0b62eb 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -1,4 +1,4 @@ -createClientMockObject( Event::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -28,8 +27,7 @@ public function testGetAll() { $stub = $this->createClientMockObject( Event::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); @@ -41,8 +39,7 @@ public function testDelete() { $stub = $this->createClientMockObject( Event::class, - new Response(200, [], 'body'), - ['delete'] + new Response(200, [], 'body') ); $response = $stub->delete('resource-id'); diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index fd77ec7..e9ea6c6 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -1,9 +1,9 @@ -createClientMockObject( File::class, - new Response(200, [], '{}'), - ['upload'] + new Response(200, [], '{}') ); $stub->upload('not_allowed.gif', 'voucher'); @@ -29,8 +28,7 @@ public function testUploadNotFound() $stub = $this->createClientMockObject( File::class, - new Response(200, [], '{}'), - ['upload'] + new Response(200, [], '{}') ); $stub->upload('not_existing.jpg', 'voucher'); @@ -42,12 +40,10 @@ public function testUploadToBig() $stub = $this->createClientMockObject( File::class, - new Response(200, [], '{}'), - ['upload'] + new Response(200, [], '{}') ); - $this->createCacheDir(); - $file = $this->getCacheDir() . '/somefile.jpg'; + $file = __DIR__ . '/somefile.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); @@ -62,12 +58,10 @@ public function testUpload() { $stub = $this->createClientMockObject( File::class, - new Response(200, [], '{}'), - ['upload'] + new Response(200, [], '{}') ); - $this->createCacheDir(); - $file = $this->getCacheDir() . '/somefile2.jpg'; + $file = __DIR__ . '/somefile2.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 2405809..b91f251 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -1,4 +1,4 @@ -createClientMockObject( Invoice::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -28,8 +27,7 @@ public function testGet() { $stub = $this->createClientMockObject( Invoice::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -39,36 +37,13 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMultiMockObject( + $stub = $this->createClientMockObject( Invoice::class, - [ - new Response(200, [], '{"content": ["a"], "totalPages": 1}'), - new Response(200, [], '{"content": ["b"], "totalPages": 1}') - ], - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); - $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); - - $response = $stub->getAll(['open']); - - $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testGetPage() - { - $stub = $this->createClientMultiMockObject( - Invoice::class, - [ - new Response(200, [], '{"content": [], "totalPages": 1}'), - ], - ['getPage'] - ); - - $response = $stub->getPage(0); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } @@ -76,8 +51,7 @@ public function testDocument() { $stub = $this->createClientMockObject( Invoice::class, - new Response(200, [], '{"documentFileId": "fake-id"}'), - ['document'] + new Response(200, [], '{"documentFileId": "fake-id"}') ); $response = $stub->document('resource-id'); @@ -92,8 +66,7 @@ public function testDocument() [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') - ], - ['document'] + ] ); $response = $stub->document('resource-id', true); diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index d6eac8e..2e2068d 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -1,4 +1,4 @@ -createClientMockObject( OrderConfirmation::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -28,8 +27,7 @@ public function testGet() { $stub = $this->createClientMockObject( OrderConfirmation::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -39,36 +37,13 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMultiMockObject( + $stub = $this->createClientMockObject( OrderConfirmation::class, - [ - new Response(200, [], '{"content": ["a"], "totalPages": 1}'), - new Response(200, [], '{"content": ["b"], "totalPages": 1}') - ], - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); - $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); - - $response = $stub->getAll(['open']); - - $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testGetPage() - { - $stub = $this->createClientMultiMockObject( - OrderConfirmation::class, - [ - new Response(200, [], '{"content": [], "totalPages": 1}'), - ], - ['getPage'] - ); - - $response = $stub->getPage(0); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } @@ -76,8 +51,7 @@ public function testDocument() { $stub = $this->createClientMockObject( OrderConfirmation::class, - new Response(200, [], '{"documentFileId": "fake-id"}'), - ['document'] + new Response(200, [], '{"documentFileId": "fake-id"}') ); $response = $stub->document('resource-id'); @@ -92,8 +66,7 @@ public function testDocument() [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') - ], - ['document'] + ] ); $response = $stub->document('resource-id', true); diff --git a/tests/Clients/PaymentConditionTest.php b/tests/Clients/PaymentConditionTest.php index eb7b6f5..6cd8ed1 100644 --- a/tests/Clients/PaymentConditionTest.php +++ b/tests/Clients/PaymentConditionTest.php @@ -2,7 +2,6 @@ namespace Clicksports\LexOffice\Tests\Clients; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Clients\PaymentCondition; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -13,8 +12,7 @@ public function testGetAll() { $stub = $this->createClientMockObject( PaymentCondition::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); diff --git a/tests/Clients/PaymentTest.php b/tests/Clients/PaymentTest.php index 5338627..2dc9bd1 100644 --- a/tests/Clients/PaymentTest.php +++ b/tests/Clients/PaymentTest.php @@ -2,7 +2,6 @@ namespace Clicksports\LexOffice\Tests\Clients; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Clients\Payment; use GuzzleHttp\Psr7\Response; use Clicksports\LexOffice\Tests\TestClient; @@ -13,8 +12,7 @@ public function testGet() { $stub = $this->createClientMockObject( Payment::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); diff --git a/tests/Clients/PostingCategoryTest.php b/tests/Clients/PostingCategoryTest.php index 0500552..8fa0a58 100644 --- a/tests/Clients/PostingCategoryTest.php +++ b/tests/Clients/PostingCategoryTest.php @@ -2,7 +2,6 @@ namespace Clicksports\LexOffice\Tests\Clients; -use Clicksports\LexOffice\Exceptions\BadMethodCallException; use Clicksports\LexOffice\Clients\PostingCategory; use Clicksports\LexOffice\Tests\TestClient; use GuzzleHttp\Psr7\Response; @@ -13,8 +12,7 @@ public function testGetAll(): void { $stub = $this->createClientMockObject( PostingCategory::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 4f6f989..a8115fc 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -12,8 +12,7 @@ public function testGet() { $stub = $this->createClientMockObject( Profile::class, - new Response(200, [], '{}'), - ['get'] + new Response(200, [], '{}') ); $this->assertEquals( diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 2610509..081e27c 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -1,4 +1,4 @@ -createClientMockObject( Quotation::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -28,8 +27,7 @@ public function testGet() { $stub = $this->createClientMockObject( Quotation::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -39,36 +37,13 @@ public function testGet() public function testGetAll() { - $stub = $this->createClientMultiMockObject( + $stub = $this->createClientMockObject( Quotation::class, - [ - new Response(200, [], '{"content": ["a"], "totalPages": 1}'), - new Response(200, [], '{"content": ["b"], "totalPages": 1}') - ], - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); - $this->assertEquals('{"content": ["a"], "totalPages": 1}', $response->getBody()->__toString()); - - $response = $stub->getAll(['open']); - - $this->assertEquals('{"content": ["b"], "totalPages": 1}', $response->getBody()->__toString()); - } - - public function testGetPage() - { - $stub = $this->createClientMultiMockObject( - Quotation::class, - [ - new Response(200, [], '{"content": [], "totalPages": 1}'), - ], - ['getPage'] - ); - - $response = $stub->getPage(0); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } @@ -76,8 +51,7 @@ public function testDocument() { $stub = $this->createClientMockObject( Quotation::class, - new Response(200, [], '{"documentFileId": "fake-id"}'), - ['document'] + new Response(200, [], '{"documentFileId": "fake-id"}') ); $response = $stub->document('resource-id'); @@ -92,8 +66,7 @@ public function testDocument() [ new Response(200, [], '{"documentFileId": "fake-id"}'), new Response(200, [], '{}') - ], - ['document'] + ] ); $response = $stub->document('resource-id', true); diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php index 1a9c12b..92414df 100644 --- a/tests/Clients/RecurringTemplateTest.php +++ b/tests/Clients/RecurringTemplateTest.php @@ -12,8 +12,7 @@ public function testGet(): void { $stub = $this->createClientMockObject( RecurringTemplate::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -25,8 +24,7 @@ public function testGenerateUrl(): void { $stub = $this->createClientMockObject( RecurringTemplate::class, - new Response(200, [], 'body'), - ['generateUrl'] + new Response(200, [], 'body') ); $this->assertEquals( diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 2dc7ab0..1e51cf9 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -13,8 +13,7 @@ public function testGenerateUrl() { $stub = $this->createClientMockObject( VoucherList::class, - new Response(200, [], 'body'), - ['generateUrl'] + new Response(200, [], 'body') ); $stub->types = ['invoice']; diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 1f834d6..383f993 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -1,4 +1,4 @@ -createClientMockObject( Voucher::class, - new Response(200, [], 'body'), - ['create'] + new Response(200, [], 'body') ); $response = $stub->create([ @@ -28,8 +27,7 @@ public function testGet() { $stub = $this->createClientMockObject( Voucher::class, - new Response(200, [], 'body'), - ['get'] + new Response(200, [], 'body') ); $response = $stub->get('resource-id'); @@ -41,8 +39,7 @@ public function testGetAll() { $stub = $this->createClientMockObject( Voucher::class, - new Response(200, [], '{"content": [], "totalPages": 1}'), - ['getAll'] + new Response(200, [], '{"content": [], "totalPages": 1}') ); $response = $stub->getAll(); @@ -54,8 +51,7 @@ public function testUpdate() { $stub = $this->createClientMockObject( Voucher::class, - new Response(200, [], '{}'), - ['update'] + new Response(200, [], '{}') ); $response = $stub->update('resource-id', []); diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index ebab09a..0ef3cf7 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -10,8 +10,7 @@ class PaginationClientTest extends TestClient public function testGenerateUrl() { $stub = $this->createPaginationClientMockObject( - [new Response()], - ['generateUrl'] + [new Response()] ); $this->assertEquals( @@ -23,8 +22,7 @@ public function testGenerateUrl() public function testGetAll() { $stub = $this->createPaginationClientMockObject( - [new Response(200, [], '{"content": [], "totalPages": 1}')], - ['getAll', 'getPage'] + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $this->assertEquals( @@ -37,8 +35,7 @@ public function testGetAll() [ new Response(200, [], '{"content": [{"name": "a"}], "totalPages": 2}'), new Response(200, [], '{"content": [{"name": "b"}], "totalPages": 2}') - ], - ['getAll', 'getPage'] + ] ); $this->assertEquals( @@ -50,8 +47,7 @@ public function testGetAll() public function testGetPage() { $stub = $this->createPaginationClientMockObject( - [new Response(200, [], '{"content": [], "totalPages": 1}')], - ['getPage'] + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $this->assertEquals( diff --git a/tests/TestClient.php b/tests/TestClient.php index e7bde95..b821946 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -3,7 +3,6 @@ namespace Clicksports\LexOffice\Tests; use Clicksports\LexOffice\Api; -use Clicksports\LexOffice\ClientInterface; use Clicksports\LexOffice\PaginationClient; use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; @@ -18,37 +17,30 @@ class TestClient extends TestCase { /** * @param Response $response - * @param string[] $methodExcept * @return Api|MockObject */ - public function createApiMockObject(Response $response, $methodExcept = []) + public function createApiMockObject(Response $response) { - return $this->createApiMultiMockObject([$response], $methodExcept); + return $this->createApiMultiMockObject([$response]); } /** * @param Response[] $responses - * @param string[] $methodExcept * @return MockObject|Api */ - public function createApiMultiMockObject(array $responses, $methodExcept = []) + public function createApiMultiMockObject(array $responses) { $responseMock = new MockHandler($responses); return $this ->getMockBuilder(Api::class) + ->addMethods([]) ->setConstructorArgs([ '', new Client([ 'handler' => HandlerStack::create($responseMock) ]) ]) - ->setMethodsExcept([ - ...$methodExcept, - 'setRequest', - 'newRequest', - 'getResponse' - ]) ->getMock(); } @@ -56,54 +48,44 @@ public function createApiMultiMockObject(array $responses, $methodExcept = []) * @template T * @param class-string $className * @param Response $response - * @param string[] $methodExcept * @return MockObject|T */ - public function createClientMockObject(string $className, Response $response, array $methodExcept = []) + public function createClientMockObject(string $className, Response $response) { - return $this->createClientMultiMockObject($className, [$response], $methodExcept); + return $this->createClientMultiMockObject($className, [$response]); } /** * @template T * @param class-string $className * @param Response[] $responses - * @param string[] $methodExcept * @return MockObject|T */ - public function createClientMultiMockObject(string $className, array $responses, array $methodExcept = []) + public function createClientMultiMockObject(string $className, array $responses) { $api = $this->createApiMultiMockObject($responses); return $this ->getMockBuilder($className) + ->addMethods([]) ->setConstructorArgs([$api]) - ->setMethodsExcept([ - ...$methodExcept, - 'getAsJson', - 'createStream' - ]) ->getMock(); } /** * @param Response[] $responses - * @param string[] $methodExcept * @return MockObject|PaginationClient * @throws ReflectionException */ - public function createPaginationClientMockObject(array $responses, array $methodExcept = []) + public function createPaginationClientMockObject(array $responses) { $api = $this->createApiMultiMockObject($responses); $stub = $this ->getMockBuilder(PaginationClient::class) + ->addMethods([]) ->setConstructorArgs([$api]) - ->setMethodsExcept([ - ...$methodExcept, - 'getAsJson' - ]) - ->getMock(); + ->getMockForAbstractClass(); $this->setProtectedProperty($stub, 'resource', 'resource'); From d154344d01a5a935222fbee4c0d90cef1072087c Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 22:09:06 +0100 Subject: [PATCH 35/69] remove php8.0 support --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- composer.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b252927..42006e8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.3, 8.2, 8.1, 8.0] + php: [8.3, 8.2, 8.1] dependency-version: [prefer-lowest, prefer-stable] guzzle: [7.*, 6.2] diff --git a/composer.json b/composer.json index e46b873..23588d3 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ ], "license": "MIT", "require": { - "php": "^8", + "php": "^8.1", "ext-json": "*", "ext-curl": "*", "guzzlehttp/guzzle": "^6.2 | ^7.0" diff --git a/composer.lock b/composer.lock index fa622cb..1240a38 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a42c7df46aebdc60ea2f2bb9d5136182", + "content-hash": "aa25055c94c55b93b571ae0a656a08c5", "packages": [ { "name": "guzzlehttp/guzzle", @@ -2286,7 +2286,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8", + "php": "^8.1", "ext-json": "*", "ext-curl": "*" }, From 1d006682dbb42f5297120d02ece27740e453458d Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 22:09:31 +0100 Subject: [PATCH 36/69] improve doc types --- src/Clients/Traits/CreateFinalizeTrait.php | 2 +- src/Clients/Traits/CreateTrait.php | 2 +- src/Clients/Traits/UpdateTrait.php | 2 +- src/Utils.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Clients/Traits/CreateFinalizeTrait.php b/src/Clients/Traits/CreateFinalizeTrait.php index 3182684..05d7057 100644 --- a/src/Clients/Traits/CreateFinalizeTrait.php +++ b/src/Clients/Traits/CreateFinalizeTrait.php @@ -8,7 +8,7 @@ trait CreateFinalizeTrait { /** - * @param array[] $data + * @param mixed[] $data * @param bool $finalized * @return ResponseInterface * @throws LexOfficeApiException diff --git a/src/Clients/Traits/CreateTrait.php b/src/Clients/Traits/CreateTrait.php index 5a47e1c..db5d494 100644 --- a/src/Clients/Traits/CreateTrait.php +++ b/src/Clients/Traits/CreateTrait.php @@ -8,7 +8,7 @@ trait CreateTrait { /** - * @param array[] $data + * @param mixed[] $data * @return ResponseInterface * @throws LexOfficeApiException */ diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php index f5eb889..44428d7 100644 --- a/src/Clients/Traits/UpdateTrait.php +++ b/src/Clients/Traits/UpdateTrait.php @@ -9,7 +9,7 @@ trait UpdateTrait { /** * @param string $id - * @param array[] $data + * @param mixed[] $data * @return ResponseInterface * @throws LexOfficeApiException */ diff --git a/src/Utils.php b/src/Utils.php index 398aa89..2c8587d 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,7 +11,7 @@ class Utils { /** * @param string $resource - * @param array{size?: int, metadata?: array, mode?: bool, seekable?: bool} $options + * @param array{size?: int, metadata?: mixed[], mode?: bool, seekable?: bool} $options * @return Stream */ public static function streamFor(string $resource = '', array $options = []): Stream @@ -32,7 +32,7 @@ public static function streamFor(string $resource = '', array $options = []): St /** * @param mixed $value * @param int $options - * @param int $depth + * @param int<1, max> $depth * @return string */ public static function jsonEncode($value, int $options = 0, int $depth = 512): string @@ -49,7 +49,7 @@ public static function jsonEncode($value, int $options = 0, int $depth = 512): s /** * @param string $json * @param bool $assoc - * @param int $depth + * @param int<1, max> $depth * @param int $options * @return mixed */ From 4946d1cd7b16fb2a966c648717a3680756c1c859 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 22:09:53 +0100 Subject: [PATCH 37/69] fix datetime format for voucherlist --- src/Clients/VoucherList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index fcfbc95..859be98 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -71,7 +71,7 @@ public function setToEverything(): self */ public function generateUrl(int $page): string { - $dateFormat = DateTimeInterface::ISO8601; + $dateFormat = DateTimeInterface::ATOM; return parent::generateUrl($page) . '&sort=' . $this->sortColumn . ',' . $this->sortDirection . From d337ef5d95eef5d7498bd0cae8beb3d00484c86f Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 22:19:37 +0100 Subject: [PATCH 38/69] small test improvments + VERSION constant removed --- .gitignore | 2 +- phpstan.neon | 2 +- src/Api.php | 5 ----- tests/Clients/FileTest.php | 4 ++-- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 666c262..0cdf7a0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/cache/ +/tests/cache/ # Created by https://www.toptal.com/developers/gitignore/api/windows,macos,linux,composer,phpunit,phpstorm+all,visualstudiocode # Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,linux,composer,phpunit,phpstorm+all,visualstudiocode diff --git a/phpstan.neon b/phpstan.neon index 3ff6fa8..af2c49d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,4 @@ parameters: - level: 7 + level: 8 paths: - src \ No newline at end of file diff --git a/src/Api.php b/src/Api.php index 10812af..887a889 100644 --- a/src/Api.php +++ b/src/Api.php @@ -28,11 +28,6 @@ class Api { - /** - * the library version - */ - public const VERSION = "0.14.1"; - /** * the lex-office api url * diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index e9ea6c6..797f259 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -43,7 +43,7 @@ public function testUploadToBig() new Response(200, [], '{}') ); - $file = __DIR__ . '/somefile.jpg'; + $file = __DIR__ . '/../cache/somefile.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); @@ -61,7 +61,7 @@ public function testUpload() new Response(200, [], '{}') ); - $file = __DIR__ . '/somefile2.jpg'; + $file = __DIR__ . '/../cache/somefile2.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); From f3241ad1ab6d3cf474920309a5eade34590d7fc1 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 22:30:59 +0100 Subject: [PATCH 39/69] change namespace --- LICENSE | 2 +- README.md | 14 ++++---- UPDATE.md | 32 ++++++++++-------- composer.json | 6 ++-- composer.lock | 2 +- src/Api.php | 38 +++++++++++----------- src/BaseClient.php | 2 +- src/ClientInterface.php | 2 +- src/Clients/Contact.php | 10 +++--- src/Clients/Country.php | 6 ++-- src/Clients/CreditNote.php | 12 +++---- src/Clients/DownPaymentInvoice.php | 10 +++--- src/Clients/Event.php | 10 +++--- src/Clients/File.php | 8 ++--- src/Clients/Invoice.php | 12 +++---- src/Clients/OrderConfirmation.php | 12 +++---- src/Clients/Payment.php | 8 ++--- src/Clients/PaymentCondition.php | 6 ++-- src/Clients/PostingCategory.php | 6 ++-- src/Clients/Profile.php | 6 ++-- src/Clients/Quotation.php | 12 +++---- src/Clients/RecurringTemplate.php | 8 ++--- src/Clients/Traits/CreateFinalizeTrait.php | 4 +-- src/Clients/Traits/CreateTrait.php | 4 +-- src/Clients/Traits/DeleteTrait.php | 4 +-- src/Clients/Traits/DocumentClientTrait.php | 6 ++-- src/Clients/Traits/GetTrait.php | 4 +-- src/Clients/Traits/UpdateTrait.php | 4 +-- src/Clients/Traits/VoucherListTrait.php | 6 ++-- src/Clients/Voucher.php | 12 +++---- src/Clients/VoucherList.php | 4 +-- src/Exceptions/LexOfficeApiException.php | 2 +- src/PaginationClient.php | 2 +- src/Utils.php | 2 +- tests/ApiTest.php | 36 ++++++++++---------- tests/Clients/ContactTest.php | 6 ++-- tests/Clients/CountryTest.php | 6 ++-- tests/Clients/CreditNoteTest.php | 6 ++-- tests/Clients/DownPaymentInvoiceTest.php | 6 ++-- tests/Clients/EventTest.php | 6 ++-- tests/Clients/FileTest.php | 8 ++--- tests/Clients/InvoiceTest.php | 6 ++-- tests/Clients/OrderConfirmationTest.php | 6 ++-- tests/Clients/PaymentConditionTest.php | 6 ++-- tests/Clients/PaymentTest.php | 6 ++-- tests/Clients/PostingCategoryTest.php | 6 ++-- tests/Clients/ProfileTest.php | 6 ++-- tests/Clients/QuotationTest.php | 6 ++-- tests/Clients/RecurringTemplateTest.php | 6 ++-- tests/Clients/VoucherListTest.php | 6 ++-- tests/Clients/VoucherTest.php | 6 ++-- tests/PaginationClientTest.php | 2 +- tests/TestClient.php | 6 ++-- 53 files changed, 213 insertions(+), 207 deletions(-) diff --git a/LICENSE b/LICENSE index c2a338b..e85dca7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 CLICKSPORTS GmbH +Copyright (c) 2023 Sysix Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ea5dc36..3ebfcb8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Lexoffice PHP API -![tests](https://github.com/clicksports/lexoffice-php-api/workflows/tests/badge.svg) -[![Latest Stable Version](https://poser.pugx.org/clicksports/lex-office-api/v)](//packagist.org/packages/clicksports/lex-office-api) -[![License](https://poser.pugx.org/clicksports/lex-office-api/license)](//packagist.org/packages/clicksports/lex-office-api) +![tests](https://github.com/sysix/lexoffice-php-api/workflows/tests/badge.svg) +[![Latest Stable Version](https://poser.pugx.org/sysix/lex-office-api/v)](//packagist.org/packages/sysix/lex-office-api) +[![License](https://poser.pugx.org/sysix/lex-office-api/license)](//packagist.org/packages/sysix/lex-office-api) ## Requirements @@ -12,7 +12,7 @@ Extensions: [Composer](https://getcomposer.org/), [PHP-JSON](https://www.php.net ## Install composer: -`composer require clicksports/lex-office-api` +`composer require sysix/lex-office-api` ## Usage @@ -22,14 +22,14 @@ You need an [API Key](https://app.lexoffice.de/addons/public-api) for that. ### Basic ```php $apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file -$api = new \Clicksports\LexOffice\Api($apiKey); +$api = new \Sysix\LexOffice\Api($apiKey); ``` ### Contact Endpoint ```php // get a page -/** @var \Clicksports\LexOffice\Api $api */ +/** @var \Sysix\LexOffice\Api $api */ $client = $api->contact(); $client->size = 100; @@ -221,7 +221,7 @@ $json = $api->*()->getAsJson($response); ```php try { $api->*->*(); -} catch(\Clicksports\LexOffice\Exceptions\LexOfficeApiException $exception) { +} catch(\Sysix\LexOffice\Exceptions\LexOfficeApiException $exception) { $json = $api->*()->getAsJson($exception->getPrevious()->getResponse()); } ``` diff --git a/UPDATE.md b/UPDATE.md index a0df83c..c88fb47 100644 --- a/UPDATE.md +++ b/UPDATE.md @@ -1,26 +1,32 @@ # Update from Version 0.x to 1.0 -## Functions Removed +## Namespace Changed -- `$api->setCacheInterface()` -- `$api->getCacheResponse()` -- `$api->setCacheResponse()` +All Classses with started with `\Clicksports\Lexoffice` are now under `\Sysix\Lexoffice`. -For settings a Cache Interface check out [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). -And implement it with: -`$api = new \Clicksports\LexOffice\Api($apiKey, $guzzleClient);` +## Clients Namespace changed -## Exceptions Removed +In Version `0.x` all Clients had a separate folder/namespace. Now they will all use the namespace +`\Sysix\Lexoffice\Clients` -- `\Clicksports\Lexoffice\Exception\CacheException` -- `\Clicksports\Lexoffice\Exception\BadMethodException` +## Cache removed + +For settings a Cache Interface check out [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). +And implement it with: +`$api = new \Sysix\LexOffice\Api($apiKey, $guzzleClient);` ## Clients Method which will throw a BadMethodException We implemented in the `0.x` Version some methods for the future of lexoffice API. At the moment, it doesn't look like the endpoint will be added soon. So we will remove them. -## Clients Namespace changed +## Functions Removed -In Version `0.x` all Clients had a separate folder/namespace. Now they will all use the namespace -`\Clicksports\Lexoffice\Clients` \ No newline at end of file +- `$api->setCacheInterface()` +- `$api->getCacheResponse()` +- `$api->setCacheResponse()` + +## Exceptions Removed + +- `\Sysix\Lexoffice\Exception\CacheException` +- `\Sysix\Lexoffice\Exception\BadMethodException` \ No newline at end of file diff --git a/composer.json b/composer.json index 23588d3..6d4cce8 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "clicksports/lex-office-api", + "name": "sysix/lex-office-api", "type": "library", "description": "Simple API Integration for Lex-Office", "scripts": { @@ -28,12 +28,12 @@ }, "autoload": { "psr-4": { - "Clicksports\\LexOffice\\": "src/" + "Sysix\\LexOffice\\": "src/" } }, "autoload-dev": { "psr-4": { - "Clicksports\\LexOffice\\Tests\\": "tests/" + "Sysix\\LexOffice\\Tests\\": "tests/" } }, "minimum-stability": "dev", diff --git a/composer.lock b/composer.lock index 1240a38..6ace916 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "aa25055c94c55b93b571ae0a656a08c5", + "content-hash": "96f02fa62947984831e70f87007efe49", "packages": [ { "name": "guzzlehttp/guzzle", diff --git a/src/Api.php b/src/Api.php index 887a889..607d2ca 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1,24 +1,24 @@ Date: Sat, 25 Nov 2023 23:20:36 +0100 Subject: [PATCH 40/69] update UPGRADE.md --- .gitattributes | 3 ++- README.md | 2 +- UPDATE.md => UPGRADE.md | 12 +++++++++++- composer.json | 3 ++- 4 files changed, 16 insertions(+), 4 deletions(-) rename UPDATE.md => UPGRADE.md (68%) diff --git a/.gitattributes b/.gitattributes index 6c17557..d684144 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,4 +2,5 @@ /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/phpunit.xml \ No newline at end of file +/phpunit.xml export-ignore +/phpstan.neon export-ignore \ No newline at end of file diff --git a/README.md b/README.md index 3ebfcb8..7a2c1f1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ## Requirements -PHP: >= 7.4 +PHP: >= 8.1 Extensions: [Composer](https://getcomposer.org/), [PHP-JSON](https://www.php.net/manual/en/book.json.php) ## Install diff --git a/UPDATE.md b/UPGRADE.md similarity index 68% rename from UPDATE.md rename to UPGRADE.md index c88fb47..2a0b3d0 100644 --- a/UPDATE.md +++ b/UPGRADE.md @@ -9,6 +9,12 @@ All Classses with started with `\Clicksports\Lexoffice` are now under `\Sysix\Le In Version `0.x` all Clients had a separate folder/namespace. Now they will all use the namespace `\Sysix\Lexoffice\Clients` +| Old Class | New Class | +| --- | --- | +| `new \Clicksports\Lexoffice\Country\Client()` | `new \Sysix\Lexoffice\Clients\Country()` | +| `new \Clicksports\Lexoffice\Voucher\Client()` | `new \Sysix\Lexoffice\Clients\Voucher()` | +| ... | ... | + ## Cache removed For settings a Cache Interface check out [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). @@ -29,4 +35,8 @@ At the moment, it doesn't look like the endpoint will be added soon. So we will ## Exceptions Removed - `\Sysix\Lexoffice\Exception\CacheException` -- `\Sysix\Lexoffice\Exception\BadMethodException` \ No newline at end of file +- `\Sysix\Lexoffice\Exception\BadMethodException` + +## Strict Typed + +Every Method is has now strict Parameters and strict Return Types. If you extend some classes, you probably need to update them too. \ No newline at end of file diff --git a/composer.json b/composer.json index 6d4cce8..74aa385 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "phpunit/phpunit": "^10.4" }, "suggest": { - "kevinrob/guzzle-cache-middleware": "*" + "kevinrob/guzzle-cache-middleware": "*", + "spatie/guzzle-rate-limiter-middleware": "*" }, "autoload": { "psr-4": { From 86a416697fcefa1ae43ff463d18ec844f65bd6cb Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 23:22:43 +0100 Subject: [PATCH 41/69] fix unit test --- tests/Clients/FileTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index f75616e..c1f2bfa 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -43,7 +43,8 @@ public function testUploadToBig() new Response(200, [], '{}') ); - $file = __DIR__ . '/../cache/somefile.jpg'; + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); @@ -61,7 +62,8 @@ public function testUpload() new Response(200, [], '{}') ); - $file = __DIR__ . '/../cache/somefile2.jpg'; + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile2.jpg'; $fp = fopen($file, 'w+'); // fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); From 36fe4943ddccbcb4f854be6cb3a57efa3a7bb867 Mon Sep 17 00:00:00 2001 From: Sysix Date: Sat, 25 Nov 2023 23:47:41 +0100 Subject: [PATCH 42/69] improve Code styles in tests --- phpstan.neon | 3 ++- tests/ApiTest.php | 14 ++++++++++---- tests/Clients/ContactTest.php | 8 ++++---- tests/Clients/CountryTest.php | 2 +- tests/Clients/CreditNoteTest.php | 6 +++--- tests/Clients/DownPaymentInvoiceTest.php | 4 ++-- tests/Clients/EventTest.php | 6 +++--- tests/Clients/FileTest.php | 22 ++++++++++++++++------ tests/Clients/InvoiceTest.php | 8 ++++---- tests/Clients/OrderConfirmationTest.php | 8 ++++---- tests/Clients/PaymentConditionTest.php | 2 +- tests/Clients/PaymentTest.php | 2 +- tests/Clients/ProfileTest.php | 2 +- tests/Clients/QuotationTest.php | 8 ++++---- tests/Clients/VoucherListTest.php | 2 +- tests/Clients/VoucherTest.php | 8 ++++---- tests/PaginationClientTest.php | 6 +++--- tests/TestClient.php | 23 ++++++++++++----------- 18 files changed, 76 insertions(+), 58 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index af2c49d..49cb743 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,5 @@ parameters: level: 8 paths: - - src \ No newline at end of file + - src + - tests \ No newline at end of file diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 5d4cb91..3c17e1e 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -2,6 +2,7 @@ namespace Sysix\LexOffice\Tests; +use Sysix\LexOffice\Api; use Sysix\LexOffice\Clients\Contact; use Sysix\LexOffice\Clients\Country; use Sysix\LexOffice\Clients\CreditNote; @@ -19,9 +20,14 @@ use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Clients\RecurringTemplate; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\MockObject\MockObject; class ApiTest extends TestClient { + /** + * @param Response $response + * @return Api&MockObject + */ public function createApiMockObject(Response $response) { $stub = parent::createApiMockObject($response); @@ -30,7 +36,7 @@ public function createApiMockObject(Response $response) return $stub; } - public function testClients() + public function testClients(): void { $stub = $this->createApiMockObject(new Response()); @@ -52,7 +58,7 @@ public function testClients() $this->assertInstanceOf(PostingCategory::class, $stub->postingCategory()); } - public function testApiUrl() + public function testApiUrl(): void { $stub = $this->createApiMockObject( new Response(200, [], 'post-content') @@ -66,7 +72,7 @@ public function testApiUrl() $this->assertStringStartsWith('test.de', $stub->request->getUri()->getHost()); } - public function testGetResponse() + public function testGetResponse(): void { $responseMock = new Response(200, [], 'response-body'); $stub = $this->createApiMockObject($responseMock); @@ -80,7 +86,7 @@ public function testGetResponse() $this->assertEquals($responseMock->getReasonPhrase(), $response->getReasonPhrase()); } - public function testRequestHeaders() + public function testRequestHeaders(): void { $stub = $this->createApiMockObject( new Response(200, [], 'post-content') diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index b7efe57..eb4fd6c 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -8,7 +8,7 @@ class ContactTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createClientMockObject( Contact::class, @@ -21,7 +21,7 @@ public function testGenerateUrl() ); } - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Contact::class, @@ -35,7 +35,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Contact::class, @@ -47,7 +47,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testUpdate() + public function testUpdate(): void { $stub = $this->createClientMockObject( Contact::class, diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php index 33bd2d8..46389bb 100644 --- a/tests/Clients/CountryTest.php +++ b/tests/Clients/CountryTest.php @@ -8,7 +8,7 @@ class CountryTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Country::class, diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 56ed25e..562e8da 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -8,7 +8,7 @@ class CreditNoteTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( CreditNote::class, @@ -22,7 +22,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( CreditNote::class, @@ -34,7 +34,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( CreditNote::class, diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index fb358fb..566a7af 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -8,7 +8,7 @@ class DownPaymentInvoiceTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( DownPaymentInvoice::class, @@ -20,7 +20,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( DownPaymentInvoice::class, diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index 4a21bf5..eeee8d7 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -9,7 +9,7 @@ class EventTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Event::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Event::class, @@ -35,7 +35,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDelete() + public function testDelete(): void { $stub = $this->createClientMockObject( Event::class, diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index c1f2bfa..9ad18a7 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -10,7 +10,7 @@ class FileTest extends TestClient { - public function testUploadNotSupportedExtension() + public function testUploadNotSupportedExtension(): void { $this->expectException(LexOfficeApiException::class); @@ -22,7 +22,7 @@ public function testUploadNotSupportedExtension() $stub->upload('not_allowed.gif', 'voucher'); } - public function testUploadNotFound() + public function testUploadNotFound(): void { $this->expectException(LexOfficeApiException::class); @@ -34,7 +34,7 @@ public function testUploadNotFound() $stub->upload('not_existing.jpg', 'voucher'); } - public function testUploadToBig() + public function testUploadToBig(): void { $this->expectException(LexOfficeApiException::class); @@ -45,7 +45,12 @@ public function testUploadToBig() $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile.jpg'; - $fp = fopen($file, 'w+'); // + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); fclose($fp); @@ -55,7 +60,7 @@ public function testUploadToBig() unlink($file); } - public function testUpload() + public function testUpload(): void { $stub = $this->createClientMockObject( File::class, @@ -64,7 +69,12 @@ public function testUpload() $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile2.jpg'; - $fp = fopen($file, 'w+'); // + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + fseek($fp, 5,SEEK_CUR); fwrite($fp,'a'); fclose($fp); diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index bba0ab3..794f69c 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -9,7 +9,7 @@ class InvoiceTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Invoice::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( Invoice::class, diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 6e44251..f5a9f44 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -9,7 +9,7 @@ class OrderConfirmationTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( OrderConfirmation::class, diff --git a/tests/Clients/PaymentConditionTest.php b/tests/Clients/PaymentConditionTest.php index 276bc82..0a3959c 100644 --- a/tests/Clients/PaymentConditionTest.php +++ b/tests/Clients/PaymentConditionTest.php @@ -8,7 +8,7 @@ class PaymentConditionTest extends TestClient { - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( PaymentCondition::class, diff --git a/tests/Clients/PaymentTest.php b/tests/Clients/PaymentTest.php index a5ecb62..a2b179c 100644 --- a/tests/Clients/PaymentTest.php +++ b/tests/Clients/PaymentTest.php @@ -8,7 +8,7 @@ class PaymentTest extends TestClient { - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Payment::class, diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 4dcb70d..1ddc371 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -8,7 +8,7 @@ class ProfileTest extends TestClient { - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Profile::class, diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index eea48ec..23d4a9d 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -9,7 +9,7 @@ class QuotationTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Quotation::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testDocument() + public function testDocument(): void { $stub = $this->createClientMockObject( Quotation::class, diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index b5d8e4a..7ba083b 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -9,7 +9,7 @@ class VoucherListTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createClientMockObject( VoucherList::class, diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index b250bf0..5ed5a6c 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -9,7 +9,7 @@ class VoucherTest extends TestClient { - public function testCreate() + public function testCreate(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -23,7 +23,7 @@ public function testCreate() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGet() + public function testGet(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -35,7 +35,7 @@ public function testGet() $this->assertEquals('body', $response->getBody()->__toString()); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createClientMockObject( Voucher::class, @@ -47,7 +47,7 @@ public function testGetAll() $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); } - public function testUpdate() + public function testUpdate(): void { $stub = $this->createClientMockObject( Voucher::class, diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index 494434a..96c652e 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -7,7 +7,7 @@ class PaginationClientTest extends TestClient { - public function testGenerateUrl() + public function testGenerateUrl(): void { $stub = $this->createPaginationClientMockObject( [new Response()] @@ -19,7 +19,7 @@ public function testGenerateUrl() ); } - public function testGetAll() + public function testGetAll(): void { $stub = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] @@ -44,7 +44,7 @@ public function testGetAll() ); } - public function testGetPage() + public function testGetPage(): void { $stub = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] diff --git a/tests/TestClient.php b/tests/TestClient.php index 17902bf..66e08a2 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -4,6 +4,7 @@ use Sysix\LexOffice\Api; use Sysix\LexOffice\PaginationClient; +use Sysix\LexOffice\ClientInterface; use GuzzleHttp\Client; use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; @@ -17,7 +18,7 @@ class TestClient extends TestCase { /** * @param Response $response - * @return Api|MockObject + * @return Api&MockObject */ public function createApiMockObject(Response $response) { @@ -26,7 +27,7 @@ public function createApiMockObject(Response $response) /** * @param Response[] $responses - * @return MockObject|Api + * @return Api&MockObject */ public function createApiMultiMockObject(array $responses) { @@ -34,7 +35,7 @@ public function createApiMultiMockObject(array $responses) return $this ->getMockBuilder(Api::class) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([ '', new Client([ @@ -45,10 +46,10 @@ public function createApiMultiMockObject(array $responses) } /** - * @template T + * @template T of ClientInterface * @param class-string $className * @param Response $response - * @return MockObject|T + * @return T&MockObject */ public function createClientMockObject(string $className, Response $response) { @@ -56,10 +57,10 @@ public function createClientMockObject(string $className, Response $response) } /** - * @template T + * @template T of ClientInterface * @param class-string $className * @param Response[] $responses - * @return MockObject|T + * @return T&MockObject */ public function createClientMultiMockObject(string $className, array $responses) { @@ -67,14 +68,14 @@ public function createClientMultiMockObject(string $className, array $responses) return $this ->getMockBuilder($className) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([$api]) ->getMock(); } /** * @param Response[] $responses - * @return MockObject|PaginationClient + * @return PaginationClient&MockObject * @throws ReflectionException */ public function createPaginationClientMockObject(array $responses) @@ -83,9 +84,9 @@ public function createPaginationClientMockObject(array $responses) $stub = $this ->getMockBuilder(PaginationClient::class) - ->addMethods([]) + ->onlyMethods([]) ->setConstructorArgs([$api]) - ->getMockForAbstractClass(); + ->getMock(); $this->setProtectedProperty($stub, 'resource', 'resource'); From c2cdb628d4cd9b561fb8363c13d2b0cc5327d729 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:07:44 +0100 Subject: [PATCH 43/69] remove redundant phpdocs, remove catching of request exceptions, allow PSR-18 --- README.md | 14 +-- src/Api.php | 127 ++------------------- src/BaseClient.php | 21 +--- src/Clients/Contact.php | 4 - src/Clients/Country.php | 5 - src/Clients/Event.php | 7 +- src/Clients/File.php | 3 - src/Clients/PaymentCondition.php | 5 - src/Clients/PostingCategory.php | 5 - src/Clients/Profile.php | 5 - src/Clients/Traits/CreateFinalizeTrait.php | 4 - src/Clients/Traits/CreateTrait.php | 3 - src/Clients/Traits/DeleteTrait.php | 7 +- src/Clients/Traits/DocumentClientTrait.php | 7 -- src/Clients/Traits/GetTrait.php | 6 - src/Clients/Traits/UpdateTrait.php | 4 - src/Clients/Traits/VoucherListTrait.php | 6 - src/Clients/Voucher.php | 5 - src/Clients/VoucherList.php | 7 -- src/PaginationClient.php | 13 --- src/Utils.php | 7 +- tests/TestClient.php | 2 - 22 files changed, 18 insertions(+), 249 deletions(-) diff --git a/README.md b/README.md index 7a2c1f1..905cf68 100644 --- a/README.md +++ b/README.md @@ -210,18 +210,8 @@ $response = $api->file()->get($entityId); ``` -### get JSON from Response +### get JSON from Success and Error Response ```php $json = $api->*()->getAsJson($response); -``` - -### get JSON from Error Response - -```php -try { - $api->*->*(); -} catch(\Sysix\LexOffice\Exceptions\LexOfficeApiException $exception) { - $json = $api->*()->getAsJson($exception->getPrevious()->getResponse()); -} -``` +``` \ No newline at end of file diff --git a/src/Api.php b/src/Api.php index 607d2ca..bef34c9 100644 --- a/src/Api.php +++ b/src/Api.php @@ -18,67 +18,29 @@ use Sysix\LexOffice\Clients\RecurringTemplate; use Sysix\LexOffice\Clients\Voucher; use Sysix\LexOffice\Clients\VoucherList; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\GuzzleException; -use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Psr7\Request; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; class Api { - /** - * the lex-office api url - * - * @var string $apiUrl - */ public string $apiUrl = 'https://api.lexoffice.io'; - /** - * the lex-office api version - * - * @var string $apiVersion - */ protected string $apiVersion = 'v1'; - /** - * the lex-office api key - * - * @var string $apiKey - */ - protected string $apiKey; - - /** - * @var Client $client - */ - protected Client $client; - - /** - * @var RequestInterface $request - */ public RequestInterface $request; - /** - * LexOffice constructor. - * @param string $apiKey - * @param Client|null $client - */ - public function __construct(string $apiKey, Client $client = null) - { - if (is_null($client)) { - $client = new Client(); - } - $this->apiKey = $apiKey; - $this->client = $client; + public function __construct( + protected string $apiKey, + protected ClientInterface $client + ) + { } /** - * @param string $method - * @param string $resource * @param string[] $headers - * @return $this */ public function newRequest(string $method, string $resource, array $headers = []): self { @@ -89,10 +51,6 @@ public function newRequest(string $method, string $resource, array $headers = [] return $this; } - /** - * @param RequestInterface $request - * @return $this - */ public function setRequest(RequestInterface $request): self { $request = $request @@ -109,162 +67,91 @@ public function setRequest(RequestInterface $request): self return $this; } - /** - * @param string $resource - * @return string - */ protected function createApiUrl(string $resource): string { return $this->apiUrl . '/' . $this->apiVersion . '/' . $resource; } - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getResponse(): ResponseInterface { - try { - return $this->client->send($this->request); - } catch (RequestException $exception) { - $response = $exception->getResponse(); - throw new LexOfficeApiException( - $exception->getMessage(), - $response ? $response->getStatusCode() : $exception->getCode(), - $exception - ); - } catch (GuzzleException $exception) { - throw new LexOfficeApiException( - $exception->getMessage(), - $exception->getCode(), - $exception - ); - } + return $this->client->sendRequest($this->request); } - /** - * @return Contact - */ public function contact(): Contact { return new Contact($this); } - /** - * @return Country - */ public function country(): Country { return new Country($this); } - /** - * @return Event - */ public function event(): Event { return new Event($this); } - /** - * @return Invoice - */ public function invoice(): Invoice { return new Invoice($this); } - /** - * @return DownPaymentInvoice - */ public function downPaymentInvoice(): DownPaymentInvoice { return new DownPaymentInvoice($this); } - /** - * @return OrderConfirmation - */ public function orderConfirmation(): OrderConfirmation { return new OrderConfirmation($this); } - /** - * @return Payment - */ public function payment(): Payment { return new Payment($this); } - /** - * @return PaymentCondition - */ public function paymentCondition(): PaymentCondition { return new PaymentCondition($this); } - /** - * @return CreditNote - */ public function creditNote(): CreditNote { return new CreditNote($this); } - /** - * @return Quotation - */ public function quotation(): Quotation { return new Quotation($this); } - /** - * @return Voucher - */ public function voucher(): Voucher { return new Voucher($this); } - /** - * @return RecurringTemplate - */ public function recurringTemplate(): RecurringTemplate { return new RecurringTemplate($this); } - /** - * @return VoucherList - */ public function voucherlist(): VoucherList { return new VoucherList($this); } - /** - * @return Profile - */ public function profile(): Profile { return new Profile($this); } - /** - * @return PostingCategory - */ public function postingCategory(): PostingCategory { return new PostingCategory($this); } - /** - * @return File - */ public function file(): File { return new File($this); diff --git a/src/BaseClient.php b/src/BaseClient.php index e87b22a..d48dcd3 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -10,20 +10,13 @@ abstract class BaseClient implements ClientInterface { protected string $resource; - /** - * @var Api $api - */ - protected Api $api; - public function __construct(Api $lexOffice) + public function __construct( + protected Api $api + ) { - $this->api = $lexOffice; } - /** - * @param ResponseInterface $response - * @return object - */ public function getAsJson(ResponseInterface $response): object { $body = $response->getBody()->__toString(); @@ -31,11 +24,7 @@ public function getAsJson(ResponseInterface $response): object return Utils::jsonDecode($body); } - /** - * @param mixed $content - * @return StreamInterface - */ - protected function createStream($content): StreamInterface + protected function createStream(mixed $content): StreamInterface { return Utils::streamFor( Utils::jsonEncode($content) @@ -44,8 +33,6 @@ protected function createStream($content): StreamInterface /** * @param string[]|bool[]|resource[] $content - * @param string|null $boundary - * @return MultipartStream */ protected function createMultipartStream(array $content, string $boundary = null): MultipartStream { diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index d0e1a1f..535cbb9 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -25,10 +25,6 @@ class Contact extends PaginationClient public ?bool $vendor = null; - /** - * @param int $page - * @return string - */ public function generateUrl(int $page): string { return parent::generateUrl($page) . diff --git a/src/Clients/Country.php b/src/Clients/Country.php index c1160b6..6c7b32d 100644 --- a/src/Clients/Country.php +++ b/src/Clients/Country.php @@ -3,17 +3,12 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\BaseClient; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Country extends BaseClient { protected string $resource = 'countries'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getAll(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) diff --git a/src/Clients/Event.php b/src/Clients/Event.php index 988fd88..a862346 100644 --- a/src/Clients/Event.php +++ b/src/Clients/Event.php @@ -6,7 +6,6 @@ use Sysix\LexOffice\BaseClient; use Sysix\LexOffice\Clients\Traits\CreateTrait; use Sysix\LexOffice\Clients\Traits\DeleteTrait; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Event extends BaseClient @@ -16,13 +15,9 @@ class Event extends BaseClient protected string $resource = 'event-subscriptions'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getAll(): ResponseInterface { - return $this->api->newRequest('GET', 'event-subscriptions') + return $this->api->newRequest('GET', $this->resource) ->getResponse(); } } diff --git a/src/Clients/File.php b/src/Clients/File.php index eca3464..145e5e6 100644 --- a/src/Clients/File.php +++ b/src/Clients/File.php @@ -19,9 +19,6 @@ class File extends BaseClient protected array $supportedExtension = ['png', 'jpg', 'pdf']; /** - * @param string $filepath - * @param string $type - * @return ResponseInterface * @throws LexOfficeApiException */ public function upload(string $filepath, string $type): ResponseInterface diff --git a/src/Clients/PaymentCondition.php b/src/Clients/PaymentCondition.php index 47ec5c3..73df730 100644 --- a/src/Clients/PaymentCondition.php +++ b/src/Clients/PaymentCondition.php @@ -3,17 +3,12 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\BaseClient; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class PaymentCondition extends BaseClient { protected string $resource = 'payment-conditions'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getAll(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) diff --git a/src/Clients/PostingCategory.php b/src/Clients/PostingCategory.php index a2b682c..d5cedc4 100644 --- a/src/Clients/PostingCategory.php +++ b/src/Clients/PostingCategory.php @@ -3,17 +3,12 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\BaseClient; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class PostingCategory extends BaseClient { protected string $resource = 'posting-categories'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getAll(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) diff --git a/src/Clients/Profile.php b/src/Clients/Profile.php index f33fcac..707bb25 100644 --- a/src/Clients/Profile.php +++ b/src/Clients/Profile.php @@ -4,17 +4,12 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\BaseClient; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Profile extends BaseClient { protected string $resource = 'profile'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function get(): ResponseInterface { return $this->api->newRequest('GET', $this->resource) diff --git a/src/Clients/Traits/CreateFinalizeTrait.php b/src/Clients/Traits/CreateFinalizeTrait.php index c2f5e7e..77d06ef 100644 --- a/src/Clients/Traits/CreateFinalizeTrait.php +++ b/src/Clients/Traits/CreateFinalizeTrait.php @@ -2,16 +2,12 @@ namespace Sysix\LexOffice\Clients\Traits; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait CreateFinalizeTrait { /** * @param mixed[] $data - * @param bool $finalized - * @return ResponseInterface - * @throws LexOfficeApiException */ public function create(array $data, bool $finalized = false): ResponseInterface { diff --git a/src/Clients/Traits/CreateTrait.php b/src/Clients/Traits/CreateTrait.php index faf8a84..6c2a749 100644 --- a/src/Clients/Traits/CreateTrait.php +++ b/src/Clients/Traits/CreateTrait.php @@ -2,15 +2,12 @@ namespace Sysix\LexOffice\Clients\Traits; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait CreateTrait { /** * @param mixed[] $data - * @return ResponseInterface - * @throws LexOfficeApiException */ public function create(array $data): ResponseInterface { diff --git a/src/Clients/Traits/DeleteTrait.php b/src/Clients/Traits/DeleteTrait.php index 9791f7e..92652cc 100644 --- a/src/Clients/Traits/DeleteTrait.php +++ b/src/Clients/Traits/DeleteTrait.php @@ -2,16 +2,11 @@ namespace Sysix\LexOffice\Clients\Traits; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait DeleteTrait { - /** - * @param string $id - * @return ResponseInterface - * @throws LexOfficeApiException - */ + public function delete(string $id): ResponseInterface { return $this->api->newRequest('DELETE', $this->resource . '/' . $id) diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 365919c..75b2b82 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -3,18 +3,11 @@ namespace Sysix\LexOffice\Clients\Traits; use Sysix\LexOffice\Clients\File; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; use stdClass; trait DocumentClientTrait { - /** - * @param string $id - * @param bool $asContent - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function document(string $id, bool $asContent = false): ResponseInterface { $response = $this->api->newRequest('GET', $this->resource . '/' . $id . '/document') diff --git a/src/Clients/Traits/GetTrait.php b/src/Clients/Traits/GetTrait.php index cb39357..2d719f7 100644 --- a/src/Clients/Traits/GetTrait.php +++ b/src/Clients/Traits/GetTrait.php @@ -2,16 +2,10 @@ namespace Sysix\LexOffice\Clients\Traits; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait GetTrait { - /** - * @param string $id - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function get(string $id): ResponseInterface { return $this->api->newRequest('GET', $this->resource . '/' . $id) diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php index 4eb8520..13a194b 100644 --- a/src/Clients/Traits/UpdateTrait.php +++ b/src/Clients/Traits/UpdateTrait.php @@ -2,16 +2,12 @@ namespace Sysix\LexOffice\Clients\Traits; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait UpdateTrait { /** - * @param string $id * @param mixed[] $data - * @return ResponseInterface - * @throws LexOfficeApiException */ public function update(string $id, array $data): ResponseInterface { diff --git a/src/Clients/Traits/VoucherListTrait.php b/src/Clients/Traits/VoucherListTrait.php index 93f60a1..bfb4928 100644 --- a/src/Clients/Traits/VoucherListTrait.php +++ b/src/Clients/Traits/VoucherListTrait.php @@ -3,16 +3,12 @@ namespace Sysix\LexOffice\Clients\Traits; use Sysix\LexOffice\Clients\VoucherList; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; trait VoucherListTrait { /** - * @param int $page * @param string[] $states - * @return ResponseInterface - * @throws LexOfficeApiException */ public function getPage(int $page, array $states = []): ResponseInterface { @@ -30,8 +26,6 @@ public function getPage(int $page, array $states = []): ResponseInterface /** * @param string[] $states - * @return ResponseInterface - * @throws LexOfficeApiException */ public function getAll(array $states = []): ResponseInterface { diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index a228bdf..d3e064a 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -6,7 +6,6 @@ use Sysix\LexOffice\Clients\Traits\CreateTrait; use Sysix\LexOffice\Clients\Traits\GetTrait; use Sysix\LexOffice\Clients\Traits\UpdateTrait; -use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; class Voucher extends BaseClient @@ -17,10 +16,6 @@ class Voucher extends BaseClient protected string $resource = 'vouchers'; - /** - * @return ResponseInterface - * @throws LexOfficeApiException - */ public function getAll(): ResponseInterface { $client = new VoucherList($this->api); diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index 22702d8..ddccf15 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -34,9 +34,6 @@ class VoucherList extends PaginationClient public ?DateTimeInterface $updatedDateTo = null; - /** - * @return $this - */ public function setToEverything(): self { $this->types = [ @@ -65,10 +62,6 @@ public function setToEverything(): self return $this; } - /** - * @param int $page - * @return string - */ public function generateUrl(int $page): string { $dateFormat = DateTimeInterface::ATOM; diff --git a/src/PaginationClient.php b/src/PaginationClient.php index d5caca4..b7d62ad 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -9,20 +9,11 @@ abstract class PaginationClient extends BaseClient { public int $size = 100; - /** - * @param int $page - * @return string - */ public function generateUrl(int $page): string { return $this->resource . '?page=' . $page . '&size=' . $this->size; } - /** - * @param int $page - * @return ResponseInterface - * @throws Exceptions\LexOfficeApiException - */ public function getPage(int $page): ResponseInterface { $api = $this->api->newRequest( @@ -33,10 +24,6 @@ public function getPage(int $page): ResponseInterface return $api->getResponse(); } - /** - * @return ResponseInterface - * @throws Exceptions\LexOfficeApiException - */ public function getAll(): ResponseInterface { $response = $this->getPage(0); diff --git a/src/Utils.php b/src/Utils.php index 4860fc4..9eca0e0 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -35,14 +35,13 @@ public static function streamFor(string $resource = '', array $options = []): St * @param int<1, max> $depth * @return string */ - public static function jsonEncode($value, int $options = 0, int $depth = 512): string + public static function jsonEncode(mixed $value, int $options = 0, int $depth = 512): string { - $json = json_encode($value, $options, $depth); + $json = (string) json_encode($value, $options, $depth); if (JSON_ERROR_NONE !== json_last_error()) { throw new InvalidArgumentException('json_encode error: ' . json_last_error_msg()); } - /** @var string */ return $json; } @@ -53,7 +52,7 @@ public static function jsonEncode($value, int $options = 0, int $depth = 512): s * @param int $options * @return mixed */ - public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0) + public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0): mixed { $data = json_decode($json, $assoc, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) { diff --git a/tests/TestClient.php b/tests/TestClient.php index 66e08a2..39b78ff 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -17,7 +17,6 @@ class TestClient extends TestCase { /** - * @param Response $response * @return Api&MockObject */ public function createApiMockObject(Response $response) @@ -48,7 +47,6 @@ public function createApiMultiMockObject(array $responses) /** * @template T of ClientInterface * @param class-string $className - * @param Response $response * @return T&MockObject */ public function createClientMockObject(string $className, Response $response) From b1a3c08968338beef6561ee8cd5b557fefdf9079 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:09:53 +0100 Subject: [PATCH 44/69] update readme + upgrade --- README.md | 1 + UPGRADE.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 905cf68..1108543 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ You need an [API Key](https://app.lexoffice.de/addons/public-api) for that. ### Basic ```php $apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file +$httpClient = \GuzzleHttp\Client(); $api = new \Sysix\LexOffice\Api($apiKey); ``` diff --git a/UPGRADE.md b/UPGRADE.md index 2a0b3d0..ab54eba 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,4 +1,4 @@ -# Update from Version 0.x to 1.0 +# Upgrade from Version 0.x to 1.0 ## Namespace Changed @@ -11,17 +11,59 @@ In Version `0.x` all Clients had a separate folder/namespace. Now they will all | Old Class | New Class | | --- | --- | +| `new \Clicksports\Lexoffice\*\Client()` | `new \Sysix\Lexoffice\Clients\*()` | +| Examples | | `new \Clicksports\Lexoffice\Country\Client()` | `new \Sysix\Lexoffice\Clients\Country()` | | `new \Clicksports\Lexoffice\Voucher\Client()` | `new \Sysix\Lexoffice\Clients\Voucher()` | -| ... | ... | + +## Requires PHP 8.1 + +PHP 8.0 is now [End of Security Support](https://www.php.net/supported-versions.php) and our dev Packages already require PHP 8.1. +So we are dumping our software to PHP 8.1. + + +## ClientInterface is required + +In Version `0.x` the `\Sysix\LexOffice\Api` requires only one constructor parameter (The API Key). Now a second parameter is also required. +In the past a `GuzzleHttp\Client` was the second optional parameter. no any PSR-18 compatible HTTP-Client is allowed. + `GuzzleHttp\Client` was already one of it. + + If you want still use `guzzlehttp/guzzle` just update your code as following: + + ```php + $api = new \Sysix\LexOffice\Api($apiKey, new \GuzzleHttp\Client()); + ``` + +## Error Responses dont throws Exceptions + +To be [PSR-18 compatible](https://www.php-fig.org/psr/psr-18/) any responses with status code > 400 will not throw an Exception. +Make sure you check the status code before accessing the entities: + +```php +/** @var \Sysix\LexOffice\Api $api */ +$client = $api->*(); +$response = $client->*(); + +// https://developers.lexoffice.io/docs/#http-status-codes +if ($response->getStatusCode() === 200 /* 201 | 202 | 204 */ ) { + $json = $client()->getAsJson($response); +} +``` + +## Errors dont get wrapped into `\Sysix\Lexoffice\Exceptions\LexOfficeApiException` + +Because we are allowing [PSR-18 Clients](https://www.php-fig.org/psr/psr-18/) we don't wrap the `GuzzleException` into an `LexOfficeApiException`. +The Only times `LexOfficeApiException` is now thrown, is when you are uploading a file. +This can maybe change in the future! ## Cache removed -For settings a Cache Interface check out [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). +The HTTP-Client is now in charge of caching. When you are still using `guzzlehttp/guzzle`, +you can use the following middleware: [guzzle-cache-middleware](https://github.com/Kevinrob/guzzle-cache-middleware). And implement it with: `$api = new \Sysix\LexOffice\Api($apiKey, $guzzleClient);` -## Clients Method which will throw a BadMethodException +## Clients Methods which would throw an BadMethodException We implemented in the `0.x` Version some methods for the future of lexoffice API. At the moment, it doesn't look like the endpoint will be added soon. So we will remove them. @@ -39,4 +81,4 @@ At the moment, it doesn't look like the endpoint will be added soon. So we will ## Strict Typed -Every Method is has now strict Parameters and strict Return Types. If you extend some classes, you probably need to update them too. \ No newline at end of file +Every Method has now strict Parameters and strict Return Types. If you extended some classes, you probably need to update them too. \ No newline at end of file From 9db96762a4af557b128c5f416ed692a6df391356 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:10:07 +0100 Subject: [PATCH 45/69] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1108543..5b12684 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ You need an [API Key](https://app.lexoffice.de/addons/public-api) for that. ```php $apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file $httpClient = \GuzzleHttp\Client(); -$api = new \Sysix\LexOffice\Api($apiKey); +$api = new \Sysix\LexOffice\Api($apiKey, $httpClient); ``` ### Contact Endpoint From 258f73b9cb67037a4a8dcd3f213ec8b74a729e26 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:13:42 +0100 Subject: [PATCH 46/69] add sensitiveParam attribute for $apiKey --- src/Api.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Api.php b/src/Api.php index bef34c9..a261796 100644 --- a/src/Api.php +++ b/src/Api.php @@ -22,6 +22,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use SensitiveParameter; class Api { @@ -33,7 +34,7 @@ class Api public function __construct( - protected string $apiKey, + #[SensitiveParameter] protected string $apiKey, protected ClientInterface $client ) { From 0700ee2c0ea0528e6fd8b499589c316d5aaeddfc Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:35:23 +0100 Subject: [PATCH 47/69] remove guzzlehttp/guzzle requirement, add guzzlehttp/psr7 requirement --- .github/workflows/tests.yml | 1 - README.md | 13 +- composer.json | 7 +- composer.lock | 495 +++++++++++++++--------------- src/Clients/Payment.php | 1 - src/Clients/RecurringTemplate.php | 1 - tests/ApiTest.php | 4 - 7 files changed, 261 insertions(+), 261 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 42006e8..6c803c5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,7 +34,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: curl coverage: none - name: Install dependencies diff --git a/README.md b/README.md index 5b12684..014fbe3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,10 @@ ## Requirements PHP: >= 8.1 -Extensions: [Composer](https://getcomposer.org/), [PHP-JSON](https://www.php.net/manual/en/book.json.php) +Extensions: +- [Composer](https://getcomposer.org/) +- [PHP-JSON](https://www.php.net/manual/en/book.json.php) +- [PSR-18 HTTP-Client](https://packagist.org/providers/psr/http-client-implementation) ## Install @@ -16,12 +19,16 @@ composer: ## Usage -Search for the official API Documentation [here](https://developers.lexoffice.io/docs/). +Search for the [official API Documentation](https://developers.lexoffice.io/docs/). You need an [API Key](https://app.lexoffice.de/addons/public-api) for that. ### Basic ```php -$apiKey = getenv('LEX_OFFICE_API_KEY'); // store keys in .env file +// store keys in .env file +$apiKey = getenv('LEX_OFFICE_API_KEY'); + +// in this example we are using guzzlehttp/guzzle package, it can be any PSR-18 HTTP Client +// see: https://packagist.org/providers/psr/http-client-implementation $httpClient = \GuzzleHttp\Client(); $api = new \Sysix\LexOffice\Api($apiKey, $httpClient); ``` diff --git a/composer.json b/composer.json index 74aa385..38bd876 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,13 @@ "require": { "php": "^8.1", "ext-json": "*", - "ext-curl": "*", - "guzzlehttp/guzzle": "^6.2 | ^7.0" + "psr/http-client": "^1.0", + "guzzlehttp/psr7": "^2.0" }, "require-dev": { "phpstan/phpstan": "^1.10", - "phpunit/phpunit": "^10.4" + "phpunit/phpunit": "^10.4", + "guzzlehttp/guzzle": "^7.8" }, "suggest": { "kevinrob/guzzle-cache-middleware": "*", diff --git a/composer.lock b/composer.lock index 6ace916..9e8c34b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,217 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "96f02fa62947984831e70f87007efe49", + "content-hash": "7eb9637fe77a411c1c097c58b3a81e44", "packages": [ - { - "name": "guzzlehttp/guzzle", - "version": "7.8.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.5.3 || ^2.0.1", - "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", - "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", - "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23", - "psr/log": "^1.1 || ^2.0 || ^3.0" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "support": { - "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.0" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", - "type": "tidelift" - } - ], - "time": "2023-08-27T10:20:53+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "support": { - "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", - "type": "tidelift" - } - ], - "time": "2023-08-03T15:11:55+00:00" - }, { "name": "guzzlehttp/psr7", "version": "2.6.1", @@ -534,38 +325,61 @@ "source": "https://github.com/ralouphie/getallheaders/tree/develop" }, "time": "2019-03-08T08:55:37+00:00" - }, + } + ], + "packages-dev": [ { - "name": "symfony/deprecation-contracts", - "version": "v3.4.0", + "name": "guzzlehttp/guzzle", + "version": "7.8.0", "source": { "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + "url": "https://github.com/guzzle/guzzle.git", + "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", + "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", "shasum": "" }, "require": { - "php": ">=8.1" + "ext-json": "*", + "guzzlehttp/promises": "^1.5.3 || ^2.0.1", + "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "ext-curl": "*", + "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", + "php-http/message-factory": "^1.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23", + "psr/log": "^1.1 || ^2.0 || ^3.0" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" + "bamarni-bin": { + "bin-links": true, + "forward-command": false } }, "autoload": { "files": [ - "function.php" - ] + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -573,37 +387,156 @@ ], "authors": [ { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" }, { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", + "description": "Guzzle is a PHP HTTP client library", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.8.0" }, "funding": [ { - "url": "https://symfony.com/sponsor", - "type": "custom" + "url": "https://github.com/GrahamCampbell", + "type": "github" }, { - "url": "https://github.com/fabpot", + "url": "https://github.com/Nyholm", "type": "github" }, { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", "type": "tidelift" } ], - "time": "2023-05-23T14:45:45+00:00" - } - ], - "packages-dev": [ + "time": "2023-08-27T10:20:53+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", + "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", + "shasum": "" + }, + "require": { + "php": "^7.2.5 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.8.1", + "phpunit/phpunit": "^8.5.29 || ^9.5.23" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": true, + "forward-command": false + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/2.0.1" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", + "type": "tidelift" + } + ], + "time": "2023-08-03T15:11:55+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.11.1", @@ -832,16 +765,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.10.44", + "version": "1.10.46", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "bf84367c53a23f759513985c54ffe0d0c249825b" + "reference": "90d3d25c5b98b8068916bbf08ce42d5cb6c54e70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/bf84367c53a23f759513985c54ffe0d0c249825b", - "reference": "bf84367c53a23f759513985c54ffe0d0c249825b", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/90d3d25c5b98b8068916bbf08ce42d5cb6c54e70", + "reference": "90d3d25c5b98b8068916bbf08ce42d5cb6c54e70", "shasum": "" }, "require": { @@ -890,7 +823,7 @@ "type": "tidelift" } ], - "time": "2023-11-21T16:30:46+00:00" + "time": "2023-11-28T14:57:26+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2229,6 +2162,73 @@ ], "time": "2023-02-07T11:34:05+00:00" }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.4.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-23T14:45:45+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.2", @@ -2287,8 +2287,7 @@ "prefer-lowest": false, "platform": { "php": "^8.1", - "ext-json": "*", - "ext-curl": "*" + "ext-json": "*" }, "platform-dev": [], "plugin-api-version": "2.6.0" diff --git a/src/Clients/Payment.php b/src/Clients/Payment.php index 59bbc5c..f3cc6c6 100644 --- a/src/Clients/Payment.php +++ b/src/Clients/Payment.php @@ -4,7 +4,6 @@ use Sysix\LexOffice\BaseClient; use Sysix\LexOffice\Clients\Traits\GetTrait; -use Sysix\LexOffice\Exceptions\BadMethodCallException; class Payment extends BaseClient { diff --git a/src/Clients/RecurringTemplate.php b/src/Clients/RecurringTemplate.php index ba970d9..8c351a0 100644 --- a/src/Clients/RecurringTemplate.php +++ b/src/Clients/RecurringTemplate.php @@ -3,7 +3,6 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\Clients\Traits\GetTrait; -use Sysix\LexOffice\Exceptions\BadMethodCallException; use Sysix\LexOffice\PaginationClient; class RecurringTemplate extends PaginationClient diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 3c17e1e..287f3de 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -24,10 +24,6 @@ class ApiTest extends TestClient { - /** - * @param Response $response - * @return Api&MockObject - */ public function createApiMockObject(Response $response) { $stub = parent::createApiMockObject($response); From 0857daf93fa62573111b7ded1712b6195152f1ec Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:39:41 +0100 Subject: [PATCH 48/69] update tests --- .github/workflows/tests.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6c803c5..a10951b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,7 +16,6 @@ jobs: matrix: php: [8.3, 8.2, 8.1] dependency-version: [prefer-lowest, prefer-stable] - guzzle: [7.*, 6.2] name: PHP${{ matrix.php }} - G${{ matrix.guzzle }} - ${{ matrix.dependency-version }} @@ -28,7 +27,7 @@ jobs: uses: actions/cache@v2 with: path: ~/.composer/cache/files - key: dependencies-guzzle-${{ matrix.guzzle }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -36,9 +35,8 @@ jobs: php-version: ${{ matrix.php }} coverage: none - - name: Install dependencies + - name: Install prefered version dependencies run: | - composer require "guzzlehttp/guzzle:${{ matrix.guzzle }}" --no-interaction --no-update composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests From 79ee238395a493932f6b48ea94b560ac880a208c Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 1 Dec 2023 00:44:24 +0100 Subject: [PATCH 49/69] update tests --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a10951b..41c462c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -17,7 +17,7 @@ jobs: php: [8.3, 8.2, 8.1] dependency-version: [prefer-lowest, prefer-stable] - name: PHP${{ matrix.php }} - G${{ matrix.guzzle }} - ${{ matrix.dependency-version }} + name: PHP${{ matrix.php }} - ${{ matrix.dependency-version }} steps: - name: Checkout code From cbaf343356df7fb2526ec09ac1a8a1cf68439686 Mon Sep 17 00:00:00 2001 From: Sysix Date: Tue, 5 Dec 2023 23:05:43 +0100 Subject: [PATCH 50/69] add deprecation warnings for getAll() and some getPage Methodes --- README.md | 26 ++-------- UPGRADE.md | 28 ++++++++++- composer.json | 2 +- src/Api.php | 8 ++-- src/Clients/Traits/VoucherListTrait.php | 34 +++++++------- src/Clients/Voucher.php | 5 ++ src/Clients/VoucherList.php | 6 +++ src/PaginationClient.php | 5 ++ tests/ApiTest.php | 43 +++++++++++++---- tests/Clients/CreditNoteTest.php | 2 + tests/Clients/DownPaymentInvoiceTest.php | 2 + tests/Clients/InvoiceTest.php | 2 + tests/Clients/OrderConfirmationTest.php | 2 + tests/Clients/QuotationTest.php | 2 + tests/Clients/VoucherTest.php | 2 + tests/DeprecationException.php | 8 ++++ tests/PaginationClientTest.php | 46 +++++++++++++++++- tests/TestClient.php | 60 +++++++----------------- 18 files changed, 189 insertions(+), 94 deletions(-) create mode 100644 tests/DeprecationException.php diff --git a/README.md b/README.md index 014fbe3..a2b589d 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,7 @@ $response = $api->country()->getAll(); ### Invoices Endpoint ```php -$response = $api->invoice()->getAll(); -$response = $api->invoice()->getAll(array $states); -$response = $api->invoice()->getPage(0); -$response = $api->invoice()->getPage(0, array $states); +$voucherList = $api->invoice()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->invoice()->get($entityId); $response = $api->invoice()->create($data); $response = $api->invoice()->document($entityId); // get document ID @@ -76,10 +73,7 @@ $response = $api->invoice()->document($entityId, true); // get file content ### Down Payment Invoices Endpoint ```php -$response = $api->downPaymentInvoice()->getAll(); -$response = $api->downPaymentInvoice()->getAll(array $states); -$response = $api->downPaymentInvoice()->getPage(0); -$response = $api->downPaymentInvoice()->getPage(0, array $states); +$voucherList = $api->downPaymentInvoice()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->downPaymentInvoice()->get($entityId); $response = $api->downPaymentInvoice()->create($data); $response = $api->downPaymentInvoice()->document($entityId); // get document ID @@ -88,10 +82,7 @@ $response = $api->downPaymentInvoice()->document($entityId, true); // get file c ### Order Confirmation Endpoint ```php -$response = $api->orderConfirmation()->getAll(); -$response = $api->orderConfirmation()->getAll(array $states); -$response = $api->orderConfirmation()->getPage(0); -$response = $api->orderConfirmation()->getPage(0, array $states); +$voucherList = $api->orderConfirmation()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->orderConfirmation()->get($entityId); $response = $api->orderConfirmation()->create($data); $response = $api->orderConfirmation()->document($entityId); // get document ID @@ -100,10 +91,7 @@ $response = $api->orderConfirmation()->document($entityId, true); // get file co ### Quotation Endpoint ```php -$response = $api->quotation()->getAll(); -$response = $api->quotation()->getAll(array $states); -$response = $api->quotation()->getPage(0); -$response = $api->quotation()->getPage(0, array $states); +$voucherList = $api->quotation()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->quotation()->get($entityId); $response = $api->quotation()->create($data); $response = $api->quotation()->document($entityId); // get document ID @@ -112,7 +100,6 @@ $response = $api->quotation()->document($entityId, true); // get file content ### Voucher Endpoint ```php -$response = $api->voucher()->getAll(); $response = $api->voucher()->get($entityId); $response = $api->voucher()->create($data); $response = $api->voucher()->update($entityId, $data); @@ -123,10 +110,7 @@ $response = $api->voucher()->document($entityId, true); // get file content ### Credit Notes Endpoint ```php -$response = $api->creditNote()->getAll(); -$response = $api->creditNote()->getAll(array $states); -$response = $api->creditNote()->getPage(0); -$response = $api->creditNote()->getPage(0, array $states); +$voucherList = $api->creditNote()->getVoucherListClient(); // see VoucherlistClient Documentation $response = $api->creditNote()->get($entityId); $response = $api->creditNote()->create($data); $response = $api->creditNote()->document($entityId); // get document ID diff --git a/UPGRADE.md b/UPGRADE.md index ab54eba..10888e5 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -25,7 +25,7 @@ So we are dumping our software to PHP 8.1. ## ClientInterface is required In Version `0.x` the `\Sysix\LexOffice\Api` requires only one constructor parameter (The API Key). Now a second parameter is also required. -In the past a `GuzzleHttp\Client` was the second optional parameter. no any PSR-18 compatible HTTP-Client is allowed. +In the past a `GuzzleHttp\Client` was the second optional parameter. no any PSR-18 compatible HTTP-Client is allowed. `GuzzleHttp\Client` was already one of it. If you want still use `guzzlehttp/guzzle` just update your code as following: @@ -79,6 +79,32 @@ At the moment, it doesn't look like the endpoint will be added soon. So we will - `\Sysix\Lexoffice\Exception\CacheException` - `\Sysix\Lexoffice\Exception\BadMethodException` + +## Functions Deprecated + +This functions will be removed in the next major (2.0) Update + +- `\Sysix\Lexoffice\Clients\CreditNote::getAll` +- `\Sysix\Lexoffice\Clients\DownPaymentInvoice::getAll` +- `\Sysix\Lexoffice\Clients\Invoice::getAll` +- `\Sysix\Lexoffice\Clients\OrderConfirmation::getAll` +- `\Sysix\Lexoffice\Clients\Quotation::getAll` +- `\Sysix\Lexoffice\Clients\Voucher::getAll` +- `\Sysix\Lexoffice\Clients\VoucherList::setToEverything` +- +- `\Sysix\Lexoffice\Clients\CreditNote::getPage` +- `\Sysix\Lexoffice\Clients\DownPaymentInvoice::getPage` +- `\Sysix\Lexoffice\Clients\Invoice::getPage` +- `\Sysix\Lexoffice\Clients\OrderConfirmation::getPage` +- `\Sysix\Lexoffice\Clients\Quotation::getPage` +- `\Sysix\Lexoffice\Clients\Voucher::getPage` + +For almost all clients there is a new method called `getVoucherListClient` which returns a `\Sysix\LexOffice\Api\Clients\VoucherList`. +With this client there are more filters for the vouchers. + +! You need to set a non-empty `statuses` property to the `\Sysix\LexOffice\Api\Clients\VoucherList` + + ## Strict Typed Every Method has now strict Parameters and strict Return Types. If you extended some classes, you probably need to update them too. \ No newline at end of file diff --git a/composer.json b/composer.json index 38bd876..d532a73 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "sysix/lex-office-api", "type": "library", - "description": "Simple API Integration for Lex-Office", + "description": "Simple API Integration for Lexoffice", "scripts": { "test": "phpunit", "lint": "phpstan analyse --ansi --error-format raw" diff --git a/src/Api.php b/src/Api.php index a261796..a52ff7b 100644 --- a/src/Api.php +++ b/src/Api.php @@ -2,6 +2,7 @@ namespace Sysix\LexOffice; +use GuzzleHttp\Psr7\Uri; use Sysix\LexOffice\Clients\Contact; use Sysix\LexOffice\Clients\Country; use Sysix\LexOffice\Clients\CreditNote; @@ -22,6 +23,7 @@ use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UriInterface; use SensitiveParameter; class Api @@ -46,7 +48,7 @@ public function __construct( public function newRequest(string $method, string $resource, array $headers = []): self { $this->setRequest( - new Request($method, $this->createApiUrl($resource), $headers) + new Request($method, $this->createApiUri($resource), $headers) ); return $this; @@ -68,9 +70,9 @@ public function setRequest(RequestInterface $request): self return $this; } - protected function createApiUrl(string $resource): string + protected function createApiUri(string $resource): UriInterface { - return $this->apiUrl . '/' . $this->apiVersion . '/' . $resource; + return new Uri($this->apiUrl . '/' . $this->apiVersion . '/' . $resource); } public function getResponse(): ResponseInterface diff --git a/src/Clients/Traits/VoucherListTrait.php b/src/Clients/Traits/VoucherListTrait.php index bfb4928..6b987d3 100644 --- a/src/Clients/Traits/VoucherListTrait.php +++ b/src/Clients/Traits/VoucherListTrait.php @@ -8,36 +8,38 @@ trait VoucherListTrait { /** - * @param string[] $states + * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 */ - public function getPage(int $page, array $states = []): ResponseInterface + public function getPage(int $page): ResponseInterface { + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + $client = new VoucherList($this->api); $client->types = $this->voucherListTypes; - - if (!$states) { - $client->setToEverything(); - } else { - $client->statuses = $states; - } + $client->setToEverything(); return $client->getPage($page); } /** - * @param string[] $states + * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 */ - public function getAll(array $states = []): ResponseInterface + public function getAll(): ResponseInterface { + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + $client = new VoucherList($this->api); + $client->setToEverything(); $client->types = $this->voucherListTypes; - if (!$states) { - $client->setToEverything(); - } else { - $client->statuses = $states; - } - return $client->getAll(); } + + public function getVoucherListClient(): VoucherList + { + $client = new VoucherList($this->api); + $client->types = $this->voucherListTypes; + + return $client; + } } \ No newline at end of file diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index d3e064a..6d43188 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -16,8 +16,13 @@ class Voucher extends BaseClient protected string $resource = 'vouchers'; + /** + * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 + */ public function getAll(): ResponseInterface { + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + $client = new VoucherList($this->api); /** diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index ddccf15..0889892 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -4,6 +4,7 @@ use Sysix\LexOffice\PaginationClient; use DateTimeInterface; +use Psr\Http\Message\ResponseInterface; class VoucherList extends PaginationClient { @@ -34,8 +35,13 @@ class VoucherList extends PaginationClient public ?DateTimeInterface $updatedDateTo = null; + /** + * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 + */ public function setToEverything(): self { + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + $this->types = [ 'salesinvoice', 'salescreditnote', diff --git a/src/PaginationClient.php b/src/PaginationClient.php index b7d62ad..35a86f1 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -24,8 +24,13 @@ public function getPage(int $page): ResponseInterface return $api->getResponse(); } + /** + * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 + */ public function getAll(): ResponseInterface { + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + $response = $this->getPage(0); /** @var stdClass{totalPages:int, content:stdClass[]} $result */ $result = $this->getAsJson($response); diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 287f3de..e4a433e 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -20,7 +20,7 @@ use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Clients\RecurringTemplate; use GuzzleHttp\Psr7\Response; -use PHPUnit\Framework\MockObject\MockObject; +use Psr\Http\Message\ResponseInterface; class ApiTest extends TestClient { @@ -68,18 +68,43 @@ public function testApiUrl(): void $this->assertStringStartsWith('test.de', $stub->request->getUri()->getHost()); } - public function testGetResponse(): void + public function testGetSuccessResponse(): void { - $responseMock = new Response(200, [], 'response-body'); - $stub = $this->createApiMockObject($responseMock); + $stub = $this->createApiMockObject(new Response(200, [], 'response-body')); + $response = $stub->getResponse(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + } + + /** + * @link https://developers.lexoffice.io/docs/#error-codes + */ + public function testGetFailedResponse(): void + { + $stub = $this->createApiMockObject(new Response(401, [], '{"message":"Unauthorized"}')); + $response = $stub->getResponse(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $stub = $this->createApiMockObject(new Response(403, [], '{"message":"\'{accessToken}\' not a valid key=value pair (missing equal-sign) in Authorization header: \'Bearer {accessToken}\'."}')); + $response = $stub->getResponse(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $stub = $this->createApiMockObject(new Response(500, [], '{"message":null}')); + $response = $stub->getResponse(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $stub = $this->createApiMockObject(new Response(503, [], null)); + $response = $stub->getResponse(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $stub = $this->createApiMockObject(new Response(504, [], '{"message":"Endpoint request timed out}')); $response = $stub->getResponse(); - $this->assertEquals($responseMock->getHeaders(), $response->getHeaders()); - $this->assertEquals($responseMock->getBody(), $response->getBody()); - $this->assertEquals($responseMock->getStatusCode(), $response->getStatusCode()); - $this->assertEquals($responseMock->getProtocolVersion(), $response->getProtocolVersion()); - $this->assertEquals($responseMock->getReasonPhrase(), $response->getReasonPhrase()); + $this->assertInstanceOf(ResponseInterface::class, $response); } public function testRequestHeaders(): void diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 562e8da..8594602 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -24,6 +24,8 @@ public function testCreate(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( CreditNote::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index 566a7af..f7dfddf 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -10,6 +10,8 @@ class DownPaymentInvoiceTest extends TestClient { public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( DownPaymentInvoice::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 794f69c..486a97d 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -37,6 +37,8 @@ public function testGet(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( Invoice::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index f5a9f44..b91bf1b 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -37,6 +37,8 @@ public function testGet(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( OrderConfirmation::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 23d4a9d..d61b982 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -37,6 +37,8 @@ public function testGet(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( Quotation::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 5ed5a6c..05dc463 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -37,6 +37,8 @@ public function testGet(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createClientMockObject( Voucher::class, new Response(200, [], '{"content": [], "totalPages": 1}') diff --git a/tests/DeprecationException.php b/tests/DeprecationException.php new file mode 100644 index 0000000..051f73d --- /dev/null +++ b/tests/DeprecationException.php @@ -0,0 +1,8 @@ +createApiMultiMockObject($responses); + + $stub = $this + ->getMockBuilder(PaginationClient::class) + ->onlyMethods([]) + ->setConstructorArgs([$api]) + ->getMock(); + + $this->setProtectedProperty($stub, 'resource', 'resource'); + + return $stub; + } + + /** + * Sets a protected property on a given object via reflection + * + * @param object $object - instance in which protected value is being modified + * @param string $property - property on instance being modified + * @param mixed $value - new value of the property being modified + * + * @return void + * + * @throws ReflectionException + * @link https://stackoverflow.com/a/37667018/7387397 + */ + public function setProtectedProperty(object $object, string $property, $value) + { + $reflection = new ReflectionClass($object); + $reflection_property = $reflection->getProperty($property); + $reflection_property->setAccessible(true); + $reflection_property->setValue($object, $value); + } public function testGenerateUrl(): void { @@ -21,6 +64,8 @@ public function testGenerateUrl(): void public function testGetAll(): void { + $this->expectDeprecationV1Warning('getAll'); + $stub = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] ); @@ -30,7 +75,6 @@ public function testGetAll(): void $stub->getAll()->getBody()->__toString() ); - $stub = $this->createPaginationClientMockObject( [ new Response(200, [], '{"content": [{"name": "a"}], "totalPages": 2}'), diff --git a/tests/TestClient.php b/tests/TestClient.php index 39b78ff..55c1825 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -11,11 +11,15 @@ use GuzzleHttp\Psr7\Response; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use ReflectionClass; -use ReflectionException; class TestClient extends TestCase { + + public function tearDown(): void + { + // see self::expectDeprecationV1Warning() + restore_error_handler(); + } /** * @return Api&MockObject */ @@ -71,46 +75,6 @@ public function createClientMultiMockObject(string $className, array $responses) ->getMock(); } - /** - * @param Response[] $responses - * @return PaginationClient&MockObject - * @throws ReflectionException - */ - public function createPaginationClientMockObject(array $responses) - { - $api = $this->createApiMultiMockObject($responses); - - $stub = $this - ->getMockBuilder(PaginationClient::class) - ->onlyMethods([]) - ->setConstructorArgs([$api]) - ->getMock(); - - $this->setProtectedProperty($stub, 'resource', 'resource'); - - return $stub; - } - - /** - * Sets a protected property on a given object via reflection - * - * @param object $object - instance in which protected value is being modified - * @param string $property - property on instance being modified - * @param mixed $value - new value of the property being modified - * - * @return void - * - * @throws ReflectionException - * @link https://stackoverflow.com/a/37667018/7387397 - */ - public function setProtectedProperty(object $object, string $property, $value) - { - $reflection = new ReflectionClass($object); - $reflection_property = $reflection->getProperty($property); - $reflection_property->setAccessible(true); - $reflection_property->setValue($object, $value); - } - public function createCacheDir(): void { $dir = $this->getCacheDir(); @@ -124,4 +88,16 @@ public function getCacheDir(): string { return __DIR__ . '/cache'; } + + public function expectDeprecationV1Warning(string $method): void + { + set_error_handler(static function (int $errno, string $errstr): void { + throw new DeprecationException($errstr, $errno); + }, E_USER_WARNING); + + $this->expectException(DeprecationException::class); + + // we can not check for full class names, because we are mocking objects + $this->expectExceptionMessage('::' . $method . ' should not be called anymore, in future versions this method WILL not exist'); + } } \ No newline at end of file From 76379e2c1fd2181b5f2bb587a5540177f5ca66aa Mon Sep 17 00:00:00 2001 From: Sysix Date: Wed, 6 Dec 2023 00:27:12 +0100 Subject: [PATCH 51/69] build queries with http_build_query --- src/Clients/Contact.php | 17 +++++++++-------- src/Clients/VoucherList.php | 26 +++++++++++++------------- src/PaginationClient.php | 14 +++++++++++++- tests/Clients/ContactTest.php | 2 +- tests/Clients/VoucherListTest.php | 5 ++++- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index 535cbb9..30c63cc 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -25,13 +25,14 @@ class Contact extends PaginationClient public ?bool $vendor = null; - public function generateUrl(int $page): string + protected function buildQueryParams(array $params): string { - return parent::generateUrl($page) . - '&direction=' . $this->sortDirection . - '&property=' . $this->sortProperty . - ($this->number !== null ? '&number=' . $this->number : '' ) . - ($this->customer !== null ? '&customer=' . $this->customer : '' ) . - ($this->vendor !== null ? '&vendor=' . $this->vendor : '' ); + $params['direction'] = $this->sortDirection; + $params['property'] = $this->sortProperty; + $params['number'] = $this->number; + $params['customer'] = $this->customer; + $params['vendor'] = $this->vendor; + + return parent::buildQueryParams($params); } -} +} \ No newline at end of file diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index 0889892..c947d25 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -68,21 +68,21 @@ public function setToEverything(): self return $this; } - public function generateUrl(int $page): string + protected function buildQueryParams(array $params): string { $dateFormat = DateTimeInterface::ATOM; - return parent::generateUrl($page) . - '&sort=' . $this->sortColumn . ',' . $this->sortDirection . - '&voucherType=' . implode(',', $this->types) . - '&voucherStatus=' . implode(',', $this->statuses) . - ($this->archived !== null ? '&archived=' . $this->archived : '') . - ($this->contactId !== null ? '&contactId=' . $this->contactId : '') . - ($this->voucherDateFrom !== null ? '&voucherDateFrom=' . $this->voucherDateFrom->format($dateFormat) : '') . - ($this->voucherDateTo !== null ? '&voucherDateTo=' . $this->voucherDateTo->format($dateFormat) : '') . - ($this->createdDateFrom !== null ? '&createdDateFrom=' . $this->createdDateFrom->format($dateFormat) : '') . - ($this->createdDateTo !== null ? '&createdDateTo=' . $this->createdDateTo->format($dateFormat) : '') . - ($this->updatedDateFrom !== null ? '&updatedDateFrom=' . $this->updatedDateFrom->format($dateFormat) : '') . - ($this->updatedDateTo !== null ? '&updatedDateTo=' . $this->updatedDateTo->format($dateFormat) : ''); + $params['sort'] = $this->sortColumn . ',' . $this->sortDirection; + $params['voucherType'] = implode(',', $this->types); + $params['voucherStatus'] = implode(',', $this->statuses); + $params['archived'] = $this->archived; + $params['voucherDateFrom'] = $this->voucherDateFrom?->format($dateFormat); + $params['voucherDateTo'] = $this->voucherDateTo?->format($dateFormat); + $params['createdDateFrom'] = $this->createdDateFrom?->format($dateFormat); + $params['createdDateTo'] = $this->createdDateTo?->format($dateFormat); + $params['updatedDateFrom'] = $this->updatedDateFrom?->format($dateFormat); + $params['updatedDateTo'] = $this->updatedDateTo?->format($dateFormat); + + return parent::buildQueryParams($params); } } diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 35a86f1..033d92f 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -11,7 +11,19 @@ abstract class PaginationClient extends BaseClient public function generateUrl(int $page): string { - return $this->resource . '?page=' . $page . '&size=' . $this->size; + return $this->resource . '?' . $this->buildQueryParams([ + 'page'=> $page + ]); + } + + /** + * @param array $params + */ + protected function buildQueryParams(array $params): string + { + $params['size'] = $this->size; + + return http_build_query(array_filter($params, static fn ($value) => $value !== null)); } public function getPage(int $page): ResponseInterface diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index eb4fd6c..a993122 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -16,7 +16,7 @@ public function testGenerateUrl(): void ); $this->assertEquals( - 'contacts?page=0&size=100&direction=ASC&property=name', + 'contacts?page=0&direction=ASC&property=name&size=100', $stub->generateUrl(0) ); } diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 7ba083b..8d56e76 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -18,10 +18,13 @@ public function testGenerateUrl(): void $stub->types = ['invoice']; $stub->statuses = ['open']; + $stub->archived = true; $this->assertEquals( - 'voucherlist?page=0&size=100&sort=voucherNumber,DESC&voucherType=invoice&voucherStatus=open', + 'voucherlist?page=0&sort=voucherNumber,DESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', $stub->generateUrl(0) ); + + } } From 216b627212309c85867250feb05f69ec2a378a19 Mon Sep 17 00:00:00 2001 From: Sysix Date: Wed, 6 Dec 2023 22:54:27 +0100 Subject: [PATCH 52/69] rewrite tests, check for requests --- src/BaseClient.php | 2 +- src/ClientInterface.php | 4 -- src/Clients/VoucherList.php | 5 +- src/PaginationClient.php | 11 ++-- tests/Clients/ContactTest.php | 65 ++++++++++++---------- tests/Clients/CountryTest.php | 17 +++--- tests/Clients/CreditNoteTest.php | 56 ++++++++++++------- tests/Clients/DownPaymentInvoiceTest.php | 41 +++++++++----- tests/Clients/EventTest.php | 43 +++++++++------ tests/Clients/FileTest.php | 53 +++++++++++------- tests/Clients/InvoiceTest.php | 69 +++++++++++++++--------- tests/Clients/OrderConfirmationTest.php | 67 ++++++++++++++--------- tests/Clients/PaymentConditionTest.php | 15 +++--- tests/Clients/PaymentTest.php | 15 +++--- tests/Clients/PostingCategoryTest.php | 17 +++--- tests/Clients/ProfileTest.php | 17 +++--- tests/Clients/QuotationTest.php | 69 +++++++++++++++--------- tests/Clients/RecurringTemplateTest.php | 30 ++++++----- tests/Clients/VoucherListTest.php | 20 +++---- tests/Clients/VoucherTest.php | 56 ++++++++++++------- tests/PaginationClientTest.php | 29 ++++------ tests/TestClient.php | 16 +++--- tests/Utils/WarningContainer.php | 8 +++ 23 files changed, 435 insertions(+), 290 deletions(-) create mode 100644 tests/Utils/WarningContainer.php diff --git a/src/BaseClient.php b/src/BaseClient.php index d48dcd3..68a32d9 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -32,7 +32,7 @@ protected function createStream(mixed $content): StreamInterface } /** - * @param string[]|bool[]|resource[] $content + * @param array $content */ protected function createMultipartStream(array $content, string $boundary = null): MultipartStream { diff --git a/src/ClientInterface.php b/src/ClientInterface.php index 3c331b1..ba9de6a 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -4,9 +4,5 @@ interface ClientInterface { - /** - * ClientInterface constructor. - * @param Api $lexOffice - */ public function __construct(Api $lexOffice); } diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index c947d25..c98a815 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -4,7 +4,6 @@ use Sysix\LexOffice\PaginationClient; use DateTimeInterface; -use Psr\Http\Message\ResponseInterface; class VoucherList extends PaginationClient { @@ -13,10 +12,10 @@ class VoucherList extends PaginationClient public string $sortColumn = 'voucherNumber'; public string $sortDirection = 'DESC'; - /** @var string[] */ + /** @var string[] $types */ public array $types = []; - /** @var string[] */ + /** @var string[] $statuses */ public array $statuses = []; public ?bool $archived = null; diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 033d92f..cf0fde1 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -9,7 +9,7 @@ abstract class PaginationClient extends BaseClient { public int $size = 100; - public function generateUrl(int $page): string + protected function generatePageUrl(int $page): string { return $this->resource . '?' . $this->buildQueryParams([ 'page'=> $page @@ -28,12 +28,9 @@ protected function buildQueryParams(array $params): string public function getPage(int $page): ResponseInterface { - $api = $this->api->newRequest( - 'GET', - $this->generateUrl($page) - ); - - return $api->getResponse(); + return $this->api + ->newRequest('GET', $this->generatePageUrl($page)) + ->getResponse(); } /** diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index a993122..fa12d6c 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -1,61 +1,72 @@ -createClientMockObject( - Contact::class, - new Response(200, [], 'body') - ); + [$api, $client] = $this->createClientMockObject(Contact::class); + + $response = $client->getPage(0); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'contacts?page=0&direction=ASC&property=name&size=100', - $stub->generateUrl(0) + $api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&size=100', + $api->request->getUri()->__toString() ); } public function testCreate(): void { - $stub = $this->createClientMockObject( - Contact::class, - new Response(200, [], 'body') - ); + [$api, $client] = $this->createClientMockObject(Contact::class); - $response = $stub->create([ + $response = $client->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/contacts', + $api->request->getUri()->__toString() + ); } public function testGet(): void { - $stub = $this->createClientMockObject( - Contact::class, - new Response(200, [], 'body') - ); + [$api, $client] = $this->createClientMockObject(Contact::class); - $response = $stub->get('resource-id'); + $response = $client->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/contacts/resource-id', + $api->request->getUri()->__toString() + ); } public function testUpdate(): void { - $stub = $this->createClientMockObject( - Contact::class, - new Response(200, [], 'body') - ); + [$api, $client] = $this->createClientMockObject(Contact::class); - $response = $stub->update('resource-id', []); + $response = $client->update('resource-id', []); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('PUT', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/contacts/resource-id', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/CountryTest.php b/tests/Clients/CountryTest.php index 46389bb..afd2a11 100644 --- a/tests/Clients/CountryTest.php +++ b/tests/Clients/CountryTest.php @@ -2,21 +2,24 @@ namespace Sysix\LexOffice\Tests\Clients; +use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Country; -use GuzzleHttp\Psr7\Response; use Sysix\LexOffice\Tests\TestClient; class CountryTest extends TestClient { public function testGetAll(): void { - $stub = $this->createClientMockObject( - Country::class, - new Response(200, [], '{"content": [], "totalPages": 1}') - ); + [$api, $client] = $this->createClientMockObject(Country::class); + + $response = $client->getAll(); - $response = $stub->getAll(); + $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/countries', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 8594602..19b0af9 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -1,56 +1,69 @@ -createClientMockObject( - CreditNote::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(CreditNote::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/credit-notes', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( CreditNote::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=creditnote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); } public function testDocument(): void { - $stub = $this->createClientMockObject( - CreditNote::class, - new Response(200, [], '{"documentFileId": "fake-id"}') - ); + [$api, $stub] = $this->createClientMockObject(CreditNote::class); $response = $stub->document('resource-id'); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{"documentFileId": "fake-id"}', - $response->getBody()->__toString() - ); + $api->apiUrl . '/v1/credit-notes/resource-id/document', + $api->request->getUri()->__toString() + ); + } - $stub = $this->createClientMultiMockObject( + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( CreditNote::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), @@ -60,9 +73,12 @@ public function testDocument(): void $response = $stub->document('resource-id', true); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $response->getBody()->__toString() + $api->apiUrl . '/v1/files/fake-id', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index f7dfddf..acff019 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -1,7 +1,8 @@ -expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( DownPaymentInvoice::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=downpaymentinvoice&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); } public function testDocument(): void { - $stub = $this->createClientMockObject( - DownPaymentInvoice::class, - new Response(200, [], '{"documentFileId": "fake-id"}') - ); + [$api, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); $response = $stub->document('resource-id'); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{"documentFileId": "fake-id"}', - $response->getBody()->__toString() - ); + $api->apiUrl . '/v1/down-payment-invoices/resource-id/document', + $api->request->getUri()->__toString() + ); + } - $stub = $this->createClientMultiMockObject( + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( DownPaymentInvoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), @@ -46,9 +56,12 @@ public function testDocument(): void $response = $stub->document('resource-id', true); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $response->getBody()->__toString() + $api->apiUrl . '/v1/files/fake-id', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index eeee8d7..7b6f164 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -1,9 +1,9 @@ -createClientMockObject( - Event::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Event::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/event-subscriptions', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { - $stub = $this->createClientMockObject( - Event::class, - new Response(200, [], '{"content": [], "totalPages": 1}') - ); + [$api, $stub] = $this->createClientMockObject(Event::class); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/event-subscriptions', + $api->request->getUri()->__toString() + ); } public function testDelete(): void { - $stub = $this->createClientMockObject( - Event::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Event::class); $response = $stub->delete('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('DELETE', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/event-subscriptions/resource-id', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index 9ad18a7..4fc47a3 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -1,11 +1,10 @@ -expectException(LexOfficeApiException::class); - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}') - ); + [, $stub] = $this->createClientMockObject(File::class); $stub->upload('not_allowed.gif', 'voucher'); } @@ -26,10 +22,7 @@ public function testUploadNotFound(): void { $this->expectException(LexOfficeApiException::class); - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}') - ); + [, $stub] = $this->createClientMockObject(File::class,); $stub->upload('not_existing.jpg', 'voucher'); } @@ -38,10 +31,7 @@ public function testUploadToBig(): void { $this->expectException(LexOfficeApiException::class); - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}') - ); + [, $stub] = $this->createClientMockObject(File::class); $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile.jpg'; @@ -60,12 +50,9 @@ public function testUploadToBig(): void unlink($file); } - public function testUpload(): void + public function testUploadSuccess(): void { - $stub = $this->createClientMockObject( - File::class, - new Response(200, [], '{}') - ); + [$api, $stub] = $this->createClientMockObject(File::class); $this->createCacheDir(); $file = $this->getCacheDir() . '/somefile2.jpg'; @@ -84,5 +71,31 @@ public function testUpload(): void unlink($file); $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/files', + $api->request->getUri()->__toString() + ); + + $this->assertStringContainsString( + 'multipart/form-data', + $api->request->getHeaderLine('Content-Type') + ); + } + + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(File::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/files/resource-id', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 486a97d..fab4623 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -1,9 +1,10 @@ -createClientMockObject( - Invoice::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Invoice::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/invoices', + $api->request->getUri()->__toString() + ); } public function testGet(): void { - $stub = $this->createClientMockObject( - Invoice::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Invoice::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/invoices/resource-id', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( Invoice::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); } public function testDocument(): void { - $stub = $this->createClientMockObject( - Invoice::class, - new Response(200, [], '{"documentFileId": "fake-id"}') - ); + [$api, $stub] = $this->createClientMockObject(Invoice::class); $response = $stub->document('resource-id'); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{"documentFileId": "fake-id"}', - $response->getBody()->__toString() - ); + $api->apiUrl . '/v1/invoices/resource-id/document', + $api->request->getUri()->__toString() + ); + } - $stub = $this->createClientMultiMockObject( + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( Invoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), @@ -73,9 +89,12 @@ public function testDocument(): void $response = $stub->document('resource-id', true); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $response->getBody()->__toString() + $api->apiUrl . '/v1/files/fake-id', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index b91bf1b..7554f0b 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -1,7 +1,8 @@ -createClientMockObject( - OrderConfirmation::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/order-confirmations', + $api->request->getUri()->__toString() + ); } public function testGet(): void { - $stub = $this->createClientMockObject( - OrderConfirmation::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/order-confirmations/resource-id', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( OrderConfirmation::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=orderconfirmation&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); } public function testDocument(): void { - $stub = $this->createClientMockObject( - OrderConfirmation::class, - new Response(200, [], '{"documentFileId": "fake-id"}') - ); + [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); $response = $stub->document('resource-id'); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{"documentFileId": "fake-id"}', - $response->getBody()->__toString() - ); + $api->apiUrl . '/v1/order-confirmations/resource-id/document', + $api->request->getUri()->__toString() + ); + } - $stub = $this->createClientMultiMockObject( + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( OrderConfirmation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), @@ -73,9 +89,12 @@ public function testDocument(): void $response = $stub->document('resource-id', true); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $response->getBody()->__toString() + $api->apiUrl . '/v1/files/fake-id', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/PaymentConditionTest.php b/tests/Clients/PaymentConditionTest.php index 0a3959c..aca4678 100644 --- a/tests/Clients/PaymentConditionTest.php +++ b/tests/Clients/PaymentConditionTest.php @@ -2,21 +2,24 @@ namespace Sysix\LexOffice\Tests\Clients; +use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\PaymentCondition; -use GuzzleHttp\Psr7\Response; use Sysix\LexOffice\Tests\TestClient; class PaymentConditionTest extends TestClient { public function testGetAll(): void { - $stub = $this->createClientMockObject( - PaymentCondition::class, - new Response(200, [], '{"content": [], "totalPages": 1}') - ); + [$api, $stub] = $this->createClientMockObject(PaymentCondition::class); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/payment-conditions', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/PaymentTest.php b/tests/Clients/PaymentTest.php index a2b179c..82dc7cf 100644 --- a/tests/Clients/PaymentTest.php +++ b/tests/Clients/PaymentTest.php @@ -2,21 +2,24 @@ namespace Sysix\LexOffice\Tests\Clients; +use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Payment; -use GuzzleHttp\Psr7\Response; use Sysix\LexOffice\Tests\TestClient; class PaymentTest extends TestClient { public function testGet(): void { - $stub = $this->createClientMockObject( - Payment::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Payment::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/payment/resource-id', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/PostingCategoryTest.php b/tests/Clients/PostingCategoryTest.php index 3d6644d..c2c5665 100644 --- a/tests/Clients/PostingCategoryTest.php +++ b/tests/Clients/PostingCategoryTest.php @@ -1,22 +1,25 @@ -createClientMockObject( - PostingCategory::class, - new Response(200, [], '{"content": [], "totalPages": 1}') - ); + [$api, $stub] = $this->createClientMockObject(PostingCategory::class); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/posting-categories', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 1ddc371..990e678 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -2,22 +2,25 @@ namespace Sysix\LexOffice\Tests\Clients; -use Sysix\LexOffice\Clients\Profile; use GuzzleHttp\Psr7\Response; +use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Clients\Profile; use Sysix\LexOffice\Tests\TestClient; class ProfileTest extends TestClient { public function testGet(): void { - $stub = $this->createClientMockObject( - Profile::class, - new Response(200, [], '{}') - ); + [$api, $stub] = $this->createClientMockObject(Profile::class); + + $response = $stub->get(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $stub->get()->getBody()->__toString() + $api->apiUrl . '/v1/profile', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index d61b982..4caa222 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -1,9 +1,10 @@ -createClientMockObject( - Quotation::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Quotation::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/quotations', + $api->request->getUri()->__toString() + ); } public function testGet(): void { - $stub = $this->createClientMockObject( - Quotation::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Quotation::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/quotations/resource-id', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( Quotation::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=quotation&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); } public function testDocument(): void { - $stub = $this->createClientMockObject( - Quotation::class, - new Response(200, [], '{"documentFileId": "fake-id"}') - ); + [$api, $stub] = $this->createClientMockObject(Quotation::class); $response = $stub->document('resource-id'); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{"documentFileId": "fake-id"}', - $response->getBody()->__toString() - ); + $api->apiUrl . '/v1/quotations/resource-id/document', + $api->request->getUri()->__toString() + ); + } - $stub = $this->createClientMultiMockObject( + public function testDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( Quotation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), @@ -73,9 +89,12 @@ public function testDocument(): void $response = $stub->document('resource-id', true); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - '{}', - $response->getBody()->__toString() + $api->apiUrl . '/v1/files/fake-id', + $api->request->getUri()->__toString() ); } } diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php index 580dbcb..bcbec12 100644 --- a/tests/Clients/RecurringTemplateTest.php +++ b/tests/Clients/RecurringTemplateTest.php @@ -1,35 +1,37 @@ -createClientMockObject( - RecurringTemplate::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(RecurringTemplate::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/recurring-templates/resource-id', + $api->request->getUri()->__toString() + ); } - public function testGenerateUrl(): void + public function testGetPage(): void { - $stub = $this->createClientMockObject( - RecurringTemplate::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(RecurringTemplate::class); + + $stub->getPage(0); $this->assertEquals( - 'recurring-templates?page=0&size=100', - $stub->generateUrl(0) + 'https://api.lexoffice.io/v1/recurring-templates?page=0&size=100', + $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 8d56e76..572e519 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -2,29 +2,29 @@ namespace Sysix\LexOffice\Tests\Clients; +use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\VoucherList; -use GuzzleHttp\Psr7\Response; use Sysix\LexOffice\Tests\TestClient; class VoucherListTest extends TestClient { - public function testGenerateUrl(): void + public function testGetPage(): void { - $stub = $this->createClientMockObject( - VoucherList::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(VoucherList::class); $stub->types = ['invoice']; $stub->statuses = ['open']; $stub->archived = true; + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'voucherlist?page=0&sort=voucherNumber,DESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', - $stub->generateUrl(0) + 'https://api.lexoffice.io/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->request->getUri()->__toString() ); - - } } diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 05dc463..831e539 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -1,9 +1,10 @@ -createClientMockObject( - Voucher::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Voucher::class); $response = $stub->create([ 'version' => 0 ]); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/vouchers', + $api->request->getUri()->__toString() + ); } public function testGet(): void { - $stub = $this->createClientMockObject( - Voucher::class, - new Response(200, [], 'body') - ); + [$api, $stub] = $this->createClientMockObject(Voucher::class); $response = $stub->get('resource-id'); - $this->assertEquals('body', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/vouchers/resource-id', + $api->request->getUri()->__toString() + ); } public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createClientMockObject( + [$api, $stub] = $this->createClientMultiMockObject( Voucher::class, - new Response(200, [], '{"content": [], "totalPages": 1}') + [new Response(200, [], '{"content": [], "totalPages": 1}')] ); $response = $stub->getAll(); - $this->assertEquals('{"content": [], "totalPages": 1}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=salesinvoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', + $api->request->getUri()->__toString() + ); } public function testUpdate(): void { - $stub = $this->createClientMockObject( - Voucher::class, - new Response(200, [], '{}') - ); + [$api, $stub] = $this->createClientMockObject(Voucher::class); $response = $stub->update('resource-id', []); - $this->assertEquals('{}', $response->getBody()->__toString()); + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('PUT', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/vouchers/resource-id', + $api->request->getUri()->__toString() + ); } } diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index c7e8990..44a04fe 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -3,6 +3,7 @@ namespace Sysix\LexOffice\Tests; use GuzzleHttp\Psr7\Response; +use Sysix\LexOffice\Api; use Sysix\LexOffice\PaginationClient; use PHPUnit\Framework\MockObject\MockObject; use ReflectionClass; @@ -12,7 +13,7 @@ class PaginationClientTest extends TestClient { /** * @param Response[] $responses - * @return PaginationClient&MockObject + * @return array{0: Api&MockObject, 1: PaginationClient&MockObject} * @throws ReflectionException */ public function createPaginationClientMockObject(array $responses) @@ -27,7 +28,7 @@ public function createPaginationClientMockObject(array $responses) $this->setProtectedProperty($stub, 'resource', 'resource'); - return $stub; + return [$api, $stub]; } /** @@ -50,23 +51,11 @@ public function setProtectedProperty(object $object, string $property, $value) $reflection_property->setValue($object, $value); } - public function testGenerateUrl(): void - { - $stub = $this->createPaginationClientMockObject( - [new Response()] - ); - - $this->assertEquals( - 'resource?page=0&size=100', - $stub->generateUrl(0) - ); - } - public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); - $stub = $this->createPaginationClientMockObject( + [, $stub] = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] ); @@ -75,7 +64,7 @@ public function testGetAll(): void $stub->getAll()->getBody()->__toString() ); - $stub = $this->createPaginationClientMockObject( + [, $stub] = $this->createPaginationClientMockObject( [ new Response(200, [], '{"content": [{"name": "a"}], "totalPages": 2}'), new Response(200, [], '{"content": [{"name": "b"}], "totalPages": 2}') @@ -90,13 +79,15 @@ public function testGetAll(): void public function testGetPage(): void { - $stub = $this->createPaginationClientMockObject( + [$api, $stub] = $this->createPaginationClientMockObject( [new Response(200, [], '{"content": [], "totalPages": 1}')] ); + $stub->getPage(0); + $this->assertEquals( - '{"content": [], "totalPages": 1}', - $stub->getPage(0)->getBody()->__toString() + 'https://api.lexoffice.io/v1/resource?page=0&size=100', + $api->request->getUri()->__toString() ); } } diff --git a/tests/TestClient.php b/tests/TestClient.php index 55c1825..d03b6cc 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -51,28 +51,30 @@ public function createApiMultiMockObject(array $responses) /** * @template T of ClientInterface * @param class-string $className - * @return T&MockObject + * @return array{0: Api&MockObject, 1: T&MockObject} */ - public function createClientMockObject(string $className, Response $response) + public function createClientMockObject(string $className) { - return $this->createClientMultiMockObject($className, [$response]); + return $this->createClientMultiMockObject($className, [new Response()]); } /** * @template T of ClientInterface * @param class-string $className * @param Response[] $responses - * @return T&MockObject + * @return array{0: Api&MockObject, 1: T&MockObject} */ - public function createClientMultiMockObject(string $className, array $responses) + public function createClientMultiMockObject(string $className, array $responses): array { $api = $this->createApiMultiMockObject($responses); - return $this + $client = $this ->getMockBuilder($className) ->onlyMethods([]) ->setConstructorArgs([$api]) ->getMock(); + + return [$api, $client]; } public function createCacheDir(): void @@ -92,7 +94,7 @@ public function getCacheDir(): string public function expectDeprecationV1Warning(string $method): void { set_error_handler(static function (int $errno, string $errstr): void { - throw new DeprecationException($errstr, $errno); + throw new DeprecationException($errstr, $errno); }, E_USER_WARNING); $this->expectException(DeprecationException::class); diff --git a/tests/Utils/WarningContainer.php b/tests/Utils/WarningContainer.php new file mode 100644 index 0000000..2eff1d7 --- /dev/null +++ b/tests/Utils/WarningContainer.php @@ -0,0 +1,8 @@ + Date: Thu, 7 Dec 2023 00:00:34 +0100 Subject: [PATCH 53/69] add missing tests --- src/Clients/Event.php | 2 +- src/Clients/Invoice.php | 2 +- src/Clients/OrderConfirmation.php | 2 +- src/Clients/Quotation.php | 2 +- src/PaginationClient.php | 2 +- tests/Clients/ContactTest.php | 16 +++++++ tests/Clients/CreditNoteTest.php | 60 ++++++++++++++++++++++++ tests/Clients/DownPaymentInvoiceTest.php | 27 ++++++++++- tests/Clients/EventTest.php | 20 ++++---- tests/Clients/FileTest.php | 30 ++++++------ tests/Clients/InvoiceTest.php | 34 ++++++++++++++ tests/Clients/OrderConfirmationTest.php | 17 +++++++ tests/Clients/ProfileTest.php | 1 - tests/Clients/QuotationTest.php | 17 +++++++ tests/Clients/RecurringTemplateTest.php | 3 +- tests/Clients/VoucherListTest.php | 23 ++++++++- tests/Clients/VoucherTest.php | 30 ++++++------ tests/PaginationClientTest.php | 2 +- tests/TestClient.php | 2 +- 19 files changed, 241 insertions(+), 51 deletions(-) diff --git a/src/Clients/Event.php b/src/Clients/Event.php index a862346..6c32d12 100644 --- a/src/Clients/Event.php +++ b/src/Clients/Event.php @@ -10,8 +10,8 @@ class Event extends BaseClient { - use DeleteTrait; use CreateTrait; + use DeleteTrait; protected string $resource = 'event-subscriptions'; diff --git a/src/Clients/Invoice.php b/src/Clients/Invoice.php index d76f452..c29a789 100644 --- a/src/Clients/Invoice.php +++ b/src/Clients/Invoice.php @@ -10,10 +10,10 @@ class Invoice extends BaseClient { + use CreateFinalizeTrait; use GetTrait; use VoucherListTrait; use DocumentClientTrait; - use CreateFinalizeTrait; protected string $resource = 'invoices'; diff --git a/src/Clients/OrderConfirmation.php b/src/Clients/OrderConfirmation.php index 449b490..0b06f5b 100644 --- a/src/Clients/OrderConfirmation.php +++ b/src/Clients/OrderConfirmation.php @@ -10,9 +10,9 @@ class OrderConfirmation extends BaseClient { + use CreateTrait; use GetTrait; use VoucherListTrait; - use CreateTrait; use DocumentClientTrait; protected string $resource = 'order-confirmations'; diff --git a/src/Clients/Quotation.php b/src/Clients/Quotation.php index 772262b..6fdd832 100644 --- a/src/Clients/Quotation.php +++ b/src/Clients/Quotation.php @@ -10,10 +10,10 @@ class Quotation extends BaseClient { + use CreateFinalizeTrait; use GetTrait; use VoucherListTrait; use DocumentClientTrait; - use CreateFinalizeTrait; protected string $resource = 'quotations'; diff --git a/src/PaginationClient.php b/src/PaginationClient.php index cf0fde1..c00a4be 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -23,7 +23,7 @@ protected function buildQueryParams(array $params): string { $params['size'] = $this->size; - return http_build_query(array_filter($params, static fn ($value) => $value !== null)); + return http_build_query($params); } public function getPage(int $page): ResponseInterface diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index fa12d6c..e02edee 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -23,6 +23,22 @@ public function testGetPage(): void ); } + public function testGetPageWithFilters(): void + { + [$api, $client] = $this->createClientMockObject(Contact::class); + + $client->number = 12345; + $client->customer = true; + $client->vendor = false; + + $client->getPage(0); + + $this->assertEquals( + $api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&number=12345&customer=1&vendor=0&size=100', + $api->request->getUri()->__toString() + ); + } + public function testCreate(): void { [$api, $client] = $this->createClientMockObject(Contact::class); diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 19b0af9..444f05a 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -5,10 +5,26 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\CreditNote; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class CreditNoteTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/credit-notes/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testCreate(): void { [$api, $stub] = $this->createClientMockObject(CreditNote::class); @@ -26,6 +42,40 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/credit-notes?finalize=true', + $api->request->getUri()->__toString() + ); + } + + public function testGetPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(CreditNote::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=creditnote&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); @@ -46,6 +96,16 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(CreditNote::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(CreditNote::class); diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index acff019..c416c64 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -3,12 +3,28 @@ namespace Sysix\LexOffice\Tests\Clients; use Psr\Http\Message\ResponseInterface; -use Sysix\LexOffice\Clients\DownPaymentInvoice; use GuzzleHttp\Psr7\Response; +use Sysix\LexOffice\Clients\DownPaymentInvoice; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class DownPaymentInvoiceTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/down-payment-invoices/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); @@ -29,6 +45,15 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(DownPaymentInvoice::class); diff --git a/tests/Clients/EventTest.php b/tests/Clients/EventTest.php index 7b6f164..9e656d4 100644 --- a/tests/Clients/EventTest.php +++ b/tests/Clients/EventTest.php @@ -26,34 +26,34 @@ public function testCreate(): void ); } - public function testGetAll(): void + public function testDelete(): void { [$api, $stub] = $this->createClientMockObject(Event::class); - $response = $stub->getAll(); + $response = $stub->delete('resource-id'); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals('DELETE', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/event-subscriptions', + $api->apiUrl . '/v1/event-subscriptions/resource-id', $api->request->getUri()->__toString() - ); + ); } - public function testDelete(): void + public function testGetAll(): void { [$api, $stub] = $this->createClientMockObject(Event::class); - $response = $stub->delete('resource-id'); + $response = $stub->getAll(); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('DELETE', $api->request->getMethod()); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/event-subscriptions/resource-id', + $api->apiUrl . '/v1/event-subscriptions', $api->request->getUri()->__toString() - ); + ); } } diff --git a/tests/Clients/FileTest.php b/tests/Clients/FileTest.php index 4fc47a3..0f92d09 100644 --- a/tests/Clients/FileTest.php +++ b/tests/Clients/FileTest.php @@ -9,6 +9,21 @@ class FileTest extends TestClient { + public function testGet(): void + { + [$api, $stub] = $this->createClientMockObject(File::class); + + $response = $stub->get('resource-id'); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/files/resource-id', + $api->request->getUri()->__toString() + ); + } + public function testUploadNotSupportedExtension(): void { $this->expectException(LexOfficeApiException::class); @@ -83,19 +98,4 @@ public function testUploadSuccess(): void $api->request->getHeaderLine('Content-Type') ); } - - public function testGet(): void - { - [$api, $stub] = $this->createClientMockObject(File::class); - - $response = $stub->get('resource-id'); - - $this->assertInstanceOf(ResponseInterface::class, $response); - - $this->assertEquals('GET', $api->request->getMethod()); - $this->assertEquals( - $api->apiUrl . '/v1/files/resource-id', - $api->request->getUri()->__toString() - ); - } } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index fab4623..bc94aa0 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -27,6 +27,23 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(Invoice::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/invoices?finalize=true', + $api->request->getUri()->__toString() + ); + } + public function testGet(): void { [$api, $stub] = $this->createClientMockObject(Invoice::class); @@ -42,6 +59,23 @@ public function testGet(): void ); } + public function testPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(Invoice::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 7554f0b..21c225b 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -42,6 +42,23 @@ public function testGet(): void ); } + public function testGetPage(): void + { + $this->expectDeprecationV1Warning('getPage'); + + [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); + + $response = $stub->getPage(0); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=orderconfirmation&voucherStatus=draft%2Copen%2Cpaid%2Cpaidoff%2Cvoided%2Caccepted%2Crejected&size=100', + $api->request->getUri()->__toString() + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); diff --git a/tests/Clients/ProfileTest.php b/tests/Clients/ProfileTest.php index 990e678..1f6f30f 100644 --- a/tests/Clients/ProfileTest.php +++ b/tests/Clients/ProfileTest.php @@ -2,7 +2,6 @@ namespace Sysix\LexOffice\Tests\Clients; -use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Profile; use Sysix\LexOffice\Tests\TestClient; diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 4caa222..aeb861f 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -27,6 +27,23 @@ public function testCreate(): void ); } + public function testCreateFinalized(): void + { + [$api, $stub] = $this->createClientMockObject(Quotation::class); + + $response = $stub->create([ + 'version' => 0 + ], true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/quotations?finalize=true', + $api->request->getUri()->__toString() + ); + } + public function testGet(): void { [$api, $stub] = $this->createClientMockObject(Quotation::class); diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php index bcbec12..9f09410 100644 --- a/tests/Clients/RecurringTemplateTest.php +++ b/tests/Clients/RecurringTemplateTest.php @@ -29,8 +29,9 @@ public function testGetPage(): void $stub->getPage(0); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'https://api.lexoffice.io/v1/recurring-templates?page=0&size=100', + $api->apiUrl . '/v1/recurring-templates?page=0&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 572e519..c6ccd41 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -2,6 +2,7 @@ namespace Sysix\LexOffice\Tests\Clients; +use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; @@ -23,7 +24,27 @@ public function testGetPage(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - 'https://api.lexoffice.io/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->request->getUri()->__toString() + ); + } + + public function testGetAll(): void + { + $this->expectDeprecationV1Warning('getAll'); + + [$api, $stub] = $this->createClientMultiMockObject( + VoucherList::class, + [new Response(200, [], '{"content": [], "totalPages": 1}')] + ); + + $response = $stub->getAll(); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 831e539..354ffc6 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -42,37 +42,37 @@ public function testGet(): void ); } - public function testGetAll(): void + public function testUpdate(): void { - $this->expectDeprecationV1Warning('getAll'); - - [$api, $stub] = $this->createClientMultiMockObject( - Voucher::class, - [new Response(200, [], '{"content": [], "totalPages": 1}')] - ); + [$api, $stub] = $this->createClientMockObject(Voucher::class); - $response = $stub->getAll(); + $response = $stub->update('resource-id', []); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('GET', $api->request->getMethod()); + $this->assertEquals('PUT', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=salesinvoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', + $api->apiUrl . '/v1/vouchers/resource-id', $api->request->getUri()->__toString() ); } - public function testUpdate(): void + public function testGetAll(): void { - [$api, $stub] = $this->createClientMockObject(Voucher::class); + $this->expectDeprecationV1Warning('getAll'); - $response = $stub->update('resource-id', []); + [$api, $stub] = $this->createClientMultiMockObject( + Voucher::class, + [new Response(200, [], '{"content": [], "totalPages": 1}')] + ); + + $response = $stub->getAll(); $this->assertInstanceOf(ResponseInterface::class, $response); - $this->assertEquals('PUT', $api->request->getMethod()); + $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/vouchers/resource-id', + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=salesinvoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index 44a04fe..d689221 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -86,7 +86,7 @@ public function testGetPage(): void $stub->getPage(0); $this->assertEquals( - 'https://api.lexoffice.io/v1/resource?page=0&size=100', + $api->apiUrl . '/v1/resource?page=0&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/TestClient.php b/tests/TestClient.php index d03b6cc..69996d0 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -53,7 +53,7 @@ public function createApiMultiMockObject(array $responses) * @param class-string $className * @return array{0: Api&MockObject, 1: T&MockObject} */ - public function createClientMockObject(string $className) + public function createClientMockObject(string $className): array { return $this->createClientMultiMockObject($className, [new Response()]); } From 768a36b812ee43b02fdaeae1005fbb17a561667f Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 00:53:49 +0100 Subject: [PATCH 54/69] add missing getVoucherListClients tests --- README.md | 4 ++++ src/Clients/Traits/VoucherListTrait.php | 2 +- tests/Clients/InvoiceTest.php | 11 +++++++++++ tests/Clients/OrderConfirmationTest.php | 13 ++++++++++++- tests/Clients/QuotationTest.php | 10 ++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2b589d..321cba9 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,10 @@ $httpClient = \GuzzleHttp\Client(); $api = new \Sysix\LexOffice\Api($apiKey, $httpClient); ``` +#### Optimize your HTTP Client + +This library does nothing + ### Contact Endpoint ```php diff --git a/src/Clients/Traits/VoucherListTrait.php b/src/Clients/Traits/VoucherListTrait.php index 6b987d3..1b9f1e9 100644 --- a/src/Clients/Traits/VoucherListTrait.php +++ b/src/Clients/Traits/VoucherListTrait.php @@ -15,8 +15,8 @@ public function getPage(int $page): ResponseInterface trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); $client = new VoucherList($this->api); - $client->types = $this->voucherListTypes; $client->setToEverything(); + $client->types = $this->voucherListTypes; return $client->getPage($page); } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index bc94aa0..671202e 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Invoice; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class InvoiceTest extends TestClient @@ -96,6 +97,16 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(Invoice::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(Invoice::class); diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 21c225b..c05b935 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -3,8 +3,9 @@ namespace Sysix\LexOffice\Tests\Clients; use Psr\Http\Message\ResponseInterface; -use Sysix\LexOffice\Clients\OrderConfirmation; use GuzzleHttp\Psr7\Response; +use Sysix\LexOffice\Clients\OrderConfirmation; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class OrderConfirmationTest extends TestClient @@ -79,6 +80,16 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(OrderConfirmation::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(OrderConfirmation::class); diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index aeb861f..5fb9d0e 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -5,6 +5,7 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Quotation; +use Sysix\LexOffice\Clients\VoucherList; use Sysix\LexOffice\Tests\TestClient; class QuotationTest extends TestClient @@ -79,6 +80,15 @@ public function testGetAll(): void ); } + public function testGetVoucherListClient(): void + { + [, $stub] = $this->createClientMockObject(Quotation::class); + + $client = $stub->getVoucherListClient(); + + $this->assertInstanceOf(VoucherList::class, $client); + } + public function testDocument(): void { [$api, $stub] = $this->createClientMockObject(Quotation::class); From 37f5a6c05d251a8bdf641318fb26fda02340f8a5 Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 01:01:27 +0100 Subject: [PATCH 55/69] return first failed response when trying to load document as content --- src/Clients/Traits/DocumentClientTrait.php | 4 ++++ tests/Clients/CreditNoteTest.php | 18 +++++++++++++++++- tests/Clients/DownPaymentInvoiceTest.php | 19 ++++++++++++++++++- tests/Clients/InvoiceTest.php | 20 ++++++++++++++++++-- tests/Clients/OrderConfirmationTest.php | 20 ++++++++++++++++++-- tests/Clients/QuotationTest.php | 18 +++++++++++++++++- 6 files changed, 92 insertions(+), 7 deletions(-) diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 75b2b82..3a04718 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -17,6 +17,10 @@ public function document(string $id, bool $asContent = false): ResponseInterface return $response; } + if ($response->getStatusCode() !== 200) { + return $response; + } + /** @var stdClass{documentField: string} $content */ $content = $this->getAsJson($response); $fileClient = new File($this->api); diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index 444f05a..f3d105d 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -127,7 +127,7 @@ public function testDocumentContent(): void CreditNote::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), - new Response(200, [], '{}') + new Response() ] ); @@ -141,4 +141,20 @@ public function testDocumentContent(): void $api->request->getUri()->__toString() ); } + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + CreditNote::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } } diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index c416c64..0b48d21 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -75,7 +75,7 @@ public function testDocumentContent(): void DownPaymentInvoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), - new Response(200, [], '{}') + new Response() ] ); @@ -89,4 +89,21 @@ public function testDocumentContent(): void $api->request->getUri()->__toString() ); } + + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + DownPaymentInvoice::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } } diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 671202e..764f0bc 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -105,7 +105,7 @@ public function testGetVoucherListClient(): void $this->assertInstanceOf(VoucherList::class, $client); } - + public function testDocument(): void { @@ -128,7 +128,7 @@ public function testDocumentContent(): void Invoice::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), - new Response(200, [], '{}') + new Response() ] ); @@ -142,4 +142,20 @@ public function testDocumentContent(): void $api->request->getUri()->__toString() ); } + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + Invoice::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } } diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index c05b935..8f74007 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -88,7 +88,7 @@ public function testGetVoucherListClient(): void $this->assertInstanceOf(VoucherList::class, $client); } - + public function testDocument(): void { @@ -111,7 +111,7 @@ public function testDocumentContent(): void OrderConfirmation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), - new Response(200, [], '{}') + new Response() ] ); @@ -125,4 +125,20 @@ public function testDocumentContent(): void $api->request->getUri()->__toString() ); } + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + OrderConfirmation::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } } diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 5fb9d0e..393ac29 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -110,7 +110,7 @@ public function testDocumentContent(): void Quotation::class, [ new Response(200, [], '{"documentFileId": "fake-id"}'), - new Response(200, [], '{}') + new Response() ] ); @@ -124,4 +124,20 @@ public function testDocumentContent(): void $api->request->getUri()->__toString() ); } + + public function testFailedDocumentContent(): void + { + [$api, $stub] = $this->createClientMultiMockObject( + Quotation::class, + [ + new Response(500), + new Response() + ] + ); + + $response = $stub->document('resource-id', true); + + $this->assertInstanceOf(ResponseInterface::class, $response); + $this->assertEquals(500, $response->getStatusCode()); + } } From 14c33f3742b6c233103f8c5638b7008a5c8fb1a3 Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 22:07:42 +0100 Subject: [PATCH 56/69] fix test for VoucherList->getAll() --- tests/Clients/VoucherListTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index c6ccd41..421f993 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -38,13 +38,17 @@ public function testGetAll(): void [new Response(200, [], '{"content": [], "totalPages": 1}')] ); + $stub->types = ['invoice']; + $stub->statuses = ['open']; + $stub->archived = true; + $response = $stub->getAll(); $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice%2Csalescreditnote%2Cpurchaseinvoice%2Cpurchasecreditnote&voucherStatus=open%2Cpaid%2Cpaidoff%2Cvoided%2Ctransferred%2Csepadebit&size=100', + $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', $api->request->getUri()->__toString() ); } From d8c48681dff7115e4b39d24671104b457c67fdde Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 22:22:53 +0100 Subject: [PATCH 57/69] remove composer lock --- .gitignore | 2 +- composer.json | 5 +- composer.lock | 2294 ------------------------------------------------- 3 files changed, 4 insertions(+), 2297 deletions(-) delete mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 0cdf7a0..5518e80 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,7 @@ composer.phar # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -# composer.lock +composer.lock ### Linux ### *~ diff --git a/composer.json b/composer.json index d532a73..8055bc5 100644 --- a/composer.json +++ b/composer.json @@ -25,8 +25,9 @@ "guzzlehttp/guzzle": "^7.8" }, "suggest": { - "kevinrob/guzzle-cache-middleware": "*", - "spatie/guzzle-rate-limiter-middleware": "*" + "guzzlehttp/guzzle": "^7.0", + "kevinrob/guzzle-cache-middleware": "^5.0", + "spatie/guzzle-rate-limiter-middleware": "^2.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock deleted file mode 100644 index 9e8c34b..0000000 --- a/composer.lock +++ /dev/null @@ -1,2294 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "7eb9637fe77a411c1c097c58b3a81e44", - "packages": [ - { - "name": "guzzlehttp/psr7", - "version": "2.6.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "reference": "be45764272e8873c72dbe3d2edcfdfcc3bc9f727", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0", - "psr/http-factory": "^1.0", - "psr/http-message": "^1.1 || ^2.0", - "ralouphie/getallheaders": "^3.0" - }, - "provide": { - "psr/http-factory-implementation": "1.0", - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "http-interop/http-factory-tests": "^0.9", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" - }, - "suggest": { - "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "support": { - "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/2.6.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7", - "type": "tidelift" - } - ], - "time": "2023-08-27T10:13:57+00:00" - }, - { - "name": "psr/http-client", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90", - "reference": "bb5906edc1c324c9a05aa0873d40117941e5fa90", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Client\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", - "keywords": [ - "http", - "http-client", - "psr", - "psr-18" - ], - "support": { - "source": "https://github.com/php-fig/http-client" - }, - "time": "2023-09-23T14:17:50+00:00" - }, - { - "name": "psr/http-factory", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", - "shasum": "" - }, - "require": { - "php": ">=7.0.0", - "psr/http-message": "^1.0 || ^2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interfaces for PSR-7 HTTP message factories", - "keywords": [ - "factory", - "http", - "message", - "psr", - "psr-17", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" - }, - "time": "2023-04-10T20:10:41+00:00" - }, - { - "name": "psr/http-message", - "version": "2.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-message.git", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "reference": "402d35bcb92c70c026d1a6a9883f06b2ead23d71", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Message\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "https://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP messages", - "homepage": "https://github.com/php-fig/http-message", - "keywords": [ - "http", - "http-message", - "psr", - "psr-7", - "request", - "response" - ], - "support": { - "source": "https://github.com/php-fig/http-message/tree/2.0" - }, - "time": "2023-04-04T09:54:51+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" - }, - "time": "2019-03-08T08:55:37+00:00" - } - ], - "packages-dev": [ - { - "name": "guzzlehttp/guzzle", - "version": "7.8.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "reference": "1110f66a6530a40fe7aea0378fe608ee2b2248f9", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.5.3 || ^2.0.1", - "guzzlehttp/psr7": "^1.9.1 || ^2.5.1", - "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0", - "symfony/deprecation-contracts": "^2.2 || ^3.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-master#2c025848417c1135031fdf9c728ee53d0a7ceaee as 3.0.999", - "php-http/message-factory": "^1.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23", - "psr/log": "^1.1 || ^2.0 || ^3.0" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "files": [ - "src/functions_include.php" - ], - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Jeremy Lindblom", - "email": "jeremeamia@gmail.com", - "homepage": "https://github.com/jeremeamia" - }, - { - "name": "George Mponos", - "email": "gmponos@gmail.com", - "homepage": "https://github.com/gmponos" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://github.com/sagikazarmark" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "support": { - "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.8.0" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle", - "type": "tidelift" - } - ], - "time": "2023-08-27T10:20:53+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/111166291a0f8130081195ac4556a5587d7f1b5d", - "reference": "111166291a0f8130081195ac4556a5587d7f1b5d", - "shasum": "" - }, - "require": { - "php": "^7.2.5 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.8.1", - "phpunit/phpunit": "^8.5.29 || ^9.5.23" - }, - "type": "library", - "extra": { - "bamarni-bin": { - "bin-links": true, - "forward-command": false - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "hello@gjcampbell.co.uk", - "homepage": "https://github.com/GrahamCampbell" - }, - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Nyholm", - "email": "tobias.nyholm@gmail.com", - "homepage": "https://github.com/Nyholm" - }, - { - "name": "Tobias Schultze", - "email": "webmaster@tubo-world.de", - "homepage": "https://github.com/Tobion" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "support": { - "issues": "https://github.com/guzzle/promises/issues", - "source": "https://github.com/guzzle/promises/tree/2.0.1" - }, - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://github.com/Nyholm", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises", - "type": "tidelift" - } - ], - "time": "2023-08-03T15:11:55+00:00" - }, - { - "name": "myclabs/deep-copy", - "version": "1.11.1", - "source": { - "type": "git", - "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "shasum": "" - }, - "require": { - "php": "^7.1 || ^8.0" - }, - "conflict": { - "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" - }, - "require-dev": { - "doctrine/collections": "^1.6.8", - "doctrine/common": "^2.13.3 || ^3.2.2", - "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" - }, - "type": "library", - "autoload": { - "files": [ - "src/DeepCopy/deep_copy.php" - ], - "psr-4": { - "DeepCopy\\": "src/DeepCopy/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Create deep copies (clones) of your objects", - "keywords": [ - "clone", - "copy", - "duplicate", - "object", - "object graph" - ], - "support": { - "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" - }, - "funding": [ - { - "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", - "type": "tidelift" - } - ], - "time": "2023-03-08T13:26:56+00:00" - }, - { - "name": "nikic/php-parser", - "version": "v4.17.1", - "source": { - "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", - "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=7.0" - }, - "require-dev": { - "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" - }, - "bin": [ - "bin/php-parse" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.9-dev" - } - }, - "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Nikita Popov" - } - ], - "description": "A PHP parser written in PHP", - "keywords": [ - "parser", - "php" - ], - "support": { - "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" - }, - "time": "2023-08-13T19:53:39+00:00" - }, - { - "name": "phar-io/manifest", - "version": "2.0.3", - "source": { - "type": "git", - "url": "https://github.com/phar-io/manifest.git", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", - "reference": "97803eca37d319dfa7826cc2437fc020857acb53", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-phar": "*", - "ext-xmlwriter": "*", - "phar-io/version": "^3.0.1", - "php": "^7.2 || ^8.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "support": { - "issues": "https://github.com/phar-io/manifest/issues", - "source": "https://github.com/phar-io/manifest/tree/2.0.3" - }, - "time": "2021-07-20T11:28:43+00:00" - }, - { - "name": "phar-io/version", - "version": "3.2.1", - "source": { - "type": "git", - "url": "https://github.com/phar-io/version.git", - "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", - "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - }, - { - "name": "Sebastian Heuer", - "email": "sebastian@phpeople.de", - "role": "Developer" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "Developer" - } - ], - "description": "Library for handling version information and constraints", - "support": { - "issues": "https://github.com/phar-io/version/issues", - "source": "https://github.com/phar-io/version/tree/3.2.1" - }, - "time": "2022-02-21T01:04:05+00:00" - }, - { - "name": "phpstan/phpstan", - "version": "1.10.46", - "source": { - "type": "git", - "url": "https://github.com/phpstan/phpstan.git", - "reference": "90d3d25c5b98b8068916bbf08ce42d5cb6c54e70" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/90d3d25c5b98b8068916bbf08ce42d5cb6c54e70", - "reference": "90d3d25c5b98b8068916bbf08ce42d5cb6c54e70", - "shasum": "" - }, - "require": { - "php": "^7.2|^8.0" - }, - "conflict": { - "phpstan/phpstan-shim": "*" - }, - "bin": [ - "phpstan", - "phpstan.phar" - ], - "type": "library", - "autoload": { - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "PHPStan - PHP Static Analysis Tool", - "keywords": [ - "dev", - "static analysis" - ], - "support": { - "docs": "https://phpstan.org/user-guide/getting-started", - "forum": "https://github.com/phpstan/phpstan/discussions", - "issues": "https://github.com/phpstan/phpstan/issues", - "security": "https://github.com/phpstan/phpstan/security/policy", - "source": "https://github.com/phpstan/phpstan-src" - }, - "funding": [ - { - "url": "https://github.com/ondrejmirtes", - "type": "github" - }, - { - "url": "https://github.com/phpstan", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", - "type": "tidelift" - } - ], - "time": "2023-11-28T14:57:26+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "10.1.9", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/a56a9ab2f680246adcf3db43f38ddf1765774735", - "reference": "a56a9ab2f680246adcf3db43f38ddf1765774735", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-libxml": "*", - "ext-xmlwriter": "*", - "nikic/php-parser": "^4.15", - "php": ">=8.1", - "phpunit/php-file-iterator": "^4.0", - "phpunit/php-text-template": "^3.0", - "sebastian/code-unit-reverse-lookup": "^3.0", - "sebastian/complexity": "^3.0", - "sebastian/environment": "^6.0", - "sebastian/lines-of-code": "^2.0", - "sebastian/version": "^4.0", - "theseer/tokenizer": "^1.2.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.1" - }, - "suggest": { - "ext-pcov": "PHP extension that provides line coverage", - "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "10.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.9" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-11-23T12:23:20+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "4.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c", - "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-08-31T06:24:48+00:00" - }, - { - "name": "phpunit/php-invoker", - "version": "4.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-invoker.git", - "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", - "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "ext-pcntl": "*", - "phpunit/phpunit": "^10.0" - }, - "suggest": { - "ext-pcntl": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Invoke callables with a timeout", - "homepage": "https://github.com/sebastianbergmann/php-invoker/", - "keywords": [ - "process" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-invoker/issues", - "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:56:09+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "3.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748", - "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-08-31T14:07:24+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "6.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", - "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "6.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:57:52+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "10.4.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/cacd8b9dd224efa8eb28beb69004126c7ca1a1a1", - "reference": "cacd8b9dd224efa8eb28beb69004126c7ca1a1a1", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-libxml": "*", - "ext-mbstring": "*", - "ext-xml": "*", - "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.3", - "phar-io/version": "^3.0.2", - "php": ">=8.1", - "phpunit/php-code-coverage": "^10.1.5", - "phpunit/php-file-iterator": "^4.0", - "phpunit/php-invoker": "^4.0", - "phpunit/php-text-template": "^3.0", - "phpunit/php-timer": "^6.0", - "sebastian/cli-parser": "^2.0", - "sebastian/code-unit": "^2.0", - "sebastian/comparator": "^5.0", - "sebastian/diff": "^5.0", - "sebastian/environment": "^6.0", - "sebastian/exporter": "^5.1", - "sebastian/global-state": "^6.0.1", - "sebastian/object-enumerator": "^5.0", - "sebastian/recursion-context": "^5.0", - "sebastian/type": "^4.0", - "sebastian/version": "^4.0" - }, - "suggest": { - "ext-soap": "To be able to generate mocks based on WSDL files" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "10.4-dev" - } - }, - "autoload": { - "files": [ - "src/Framework/Assert/Functions.php" - ], - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.2" - }, - "funding": [ - { - "url": "https://phpunit.de/sponsors.html", - "type": "custom" - }, - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", - "type": "tidelift" - } - ], - "time": "2023-10-26T07:21:45+00:00" - }, - { - "name": "sebastian/cli-parser", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", - "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library for parsing CLI options", - "homepage": "https://github.com/sebastianbergmann/cli-parser", - "support": { - "issues": "https://github.com/sebastianbergmann/cli-parser/issues", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:58:15+00:00" - }, - { - "name": "sebastian/code-unit", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit.git", - "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", - "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Collection of value objects that represent the PHP code units", - "homepage": "https://github.com/sebastianbergmann/code-unit", - "support": { - "issues": "https://github.com/sebastianbergmann/code-unit/issues", - "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:58:43+00:00" - }, - { - "name": "sebastian/code-unit-reverse-lookup", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", - "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Looks up which function or method a line of code belongs to", - "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "support": { - "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", - "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T06:59:15+00:00" - }, - { - "name": "sebastian/comparator", - "version": "5.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", - "reference": "2db5010a484d53ebf536087a70b4a5423c102372", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-mbstring": "*", - "php": ">=8.1", - "sebastian/diff": "^5.0", - "sebastian/exporter": "^5.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "https://github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/comparator/issues", - "security": "https://github.com/sebastianbergmann/comparator/security/policy", - "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-08-14T13:18:12+00:00" - }, - { - "name": "sebastian/complexity", - "version": "3.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/complexity.git", - "reference": "68cfb347a44871f01e33ab0ef8215966432f6957" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68cfb347a44871f01e33ab0ef8215966432f6957", - "reference": "68cfb347a44871f01e33ab0ef8215966432f6957", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^4.10", - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library for calculating the complexity of PHP code units", - "homepage": "https://github.com/sebastianbergmann/complexity", - "support": { - "issues": "https://github.com/sebastianbergmann/complexity/issues", - "security": "https://github.com/sebastianbergmann/complexity/security/policy", - "source": "https://github.com/sebastianbergmann/complexity/tree/3.1.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-09-28T11:50:59+00:00" - }, - { - "name": "sebastian/diff", - "version": "5.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0", - "symfony/process": "^4.2 || ^5" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - } - ], - "description": "Diff implementation", - "homepage": "https://github.com/sebastianbergmann/diff", - "keywords": [ - "diff", - "udiff", - "unidiff", - "unified diff" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/diff/issues", - "security": "https://github.com/sebastianbergmann/diff/security/policy", - "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-05-01T07:48:21+00:00" - }, - { - "name": "sebastian/environment", - "version": "6.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", - "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "suggest": { - "ext-posix": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "6.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "https://github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/environment/issues", - "security": "https://github.com/sebastianbergmann/environment/security/policy", - "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-04-11T05:39:26+00:00" - }, - { - "name": "sebastian/exporter", - "version": "5.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/64f51654862e0f5e318db7e9dcc2292c63cdbddc", - "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc", - "shasum": "" - }, - "require": { - "ext-mbstring": "*", - "php": ">=8.1", - "sebastian/recursion-context": "^5.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.1-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@gmail.com" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "https://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/exporter/issues", - "security": "https://github.com/sebastianbergmann/exporter/security/policy", - "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-09-24T13:22:09+00:00" - }, - { - "name": "sebastian/global-state", - "version": "6.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", - "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "sebastian/object-reflector": "^3.0", - "sebastian/recursion-context": "^5.0" - }, - "require-dev": { - "ext-dom": "*", - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "6.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/global-state/issues", - "security": "https://github.com/sebastianbergmann/global-state/security/policy", - "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-07-19T07:19:23+00:00" - }, - { - "name": "sebastian/lines-of-code", - "version": "2.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/649e40d279e243d985aa8fb6e74dd5bb28dc185d", - "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d", - "shasum": "" - }, - "require": { - "nikic/php-parser": "^4.10", - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library for counting the lines of code in PHP source code", - "homepage": "https://github.com/sebastianbergmann/lines-of-code", - "support": { - "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", - "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-08-31T09:25:50+00:00" - }, - { - "name": "sebastian/object-enumerator", - "version": "5.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", - "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", - "shasum": "" - }, - "require": { - "php": ">=8.1", - "sebastian/object-reflector": "^3.0", - "sebastian/recursion-context": "^5.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Traverses array structures and object graphs to enumerate all referenced objects", - "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "support": { - "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", - "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T07:08:32+00:00" - }, - { - "name": "sebastian/object-reflector", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", - "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Allows reflection of object attributes, including inherited and non-public ones", - "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "support": { - "issues": "https://github.com/sebastianbergmann/object-reflector/issues", - "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T07:06:18+00:00" - }, - { - "name": "sebastian/recursion-context", - "version": "5.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "05909fb5bc7df4c52992396d0116aed689f93712" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712", - "reference": "05909fb5bc7df4c52992396d0116aed689f93712", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "5.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "https://github.com/sebastianbergmann/recursion-context", - "support": { - "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T07:05:40+00:00" - }, - { - "name": "sebastian/type", - "version": "4.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/type.git", - "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", - "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Collection of value objects that represent the types of the PHP type system", - "homepage": "https://github.com/sebastianbergmann/type", - "support": { - "issues": "https://github.com/sebastianbergmann/type/issues", - "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-03T07:10:45+00:00" - }, - { - "name": "sebastian/version", - "version": "4.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", - "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "4.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "support": { - "issues": "https://github.com/sebastianbergmann/version/issues", - "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "time": "2023-02-07T11:34:05+00:00" - }, - { - "name": "symfony/deprecation-contracts", - "version": "v3.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", - "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", - "shasum": "" - }, - "require": { - "php": ">=8.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "3.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "files": [ - "function.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "A generic function and convention to trigger deprecation notices", - "homepage": "https://symfony.com", - "support": { - "source": "https://github.com/symfony/deprecation-contracts/tree/v3.4.0" - }, - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2023-05-23T14:45:45+00:00" - }, - { - "name": "theseer/tokenizer", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/theseer/tokenizer.git", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": "^7.2 || ^8.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Arne Blankerts", - "email": "arne@blankerts.de", - "role": "Developer" - } - ], - "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "support": { - "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.2" - }, - "funding": [ - { - "url": "https://github.com/theseer", - "type": "github" - } - ], - "time": "2023-11-20T00:12:19+00:00" - } - ], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], - "prefer-stable": true, - "prefer-lowest": false, - "platform": { - "php": "^8.1", - "ext-json": "*" - }, - "platform-dev": [], - "plugin-api-version": "2.6.0" -} From 19f924fc493799f7e39fa4ff7c9d55133fc35a76 Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 22:23:13 +0100 Subject: [PATCH 58/69] update readme, inform to otpimize http client --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 321cba9..f87a792 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,22 @@ $api = new \Sysix\LexOffice\Api($apiKey, $httpClient); #### Optimize your HTTP Client -This library does nothing +This library only prepares the `\Psr\Http\Message\RequestInterface` for the HTTP Client and returns its Response. +There are almost no error checks, no caching and no rate limiting. Your PSR-18 HTTP Client should come with a way to deal with it. + +Here is a example with `guzzlehttp/guzzle` , `kevinrob/guzzle-cache-middleware` and `spatie/guzzle-rate-limiter-middleware`: + +```php +$apiKey = getenv('LEX_OFFICE_API_KEY'); + +$stack = \GuzzleHttp\HandlerStack(); +$stack->push(new \Kevinrob\GuzzleCache\CacheMiddleware\CacheMiddleware(), 'cache'); +$stack->push(\Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware\RateLimiterMiddleware::perSecond(2)); + +$httpClient = \GuzzleHttp\Client(['handler' => $stack]); +$api = new \Sysix\LexOffice\Api($apiKey, $httpClient); + +``` ### Contact Endpoint ```php From 8ebe058e56fb4615f66519154edb40b3c4529be1 Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 22:30:27 +0100 Subject: [PATCH 59/69] update ci tests --- .github/workflows/tests.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 41c462c..70f04c7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,12 +21,17 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: - path: ~/.composer/cache/files + path: ${{ steps.composer-cache.outputs.dir }} key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - name: Setup PHP From adccfc357876498db68f4627bc152915bf6d713e Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 23:03:51 +0100 Subject: [PATCH 60/69] cleanup BaseClient, move to Utils, deprecate getAsJson --- README.md | 3 +- UPGRADE.md | 37 +++++++++-------- src/BaseClient.php | 32 +++------------ src/Clients/File.php | 3 +- src/Clients/Traits/CreateFinalizeTrait.php | 3 +- src/Clients/Traits/CreateTrait.php | 3 +- src/Clients/Traits/DocumentClientTrait.php | 10 ++++- src/Clients/Traits/UpdateTrait.php | 3 +- src/PaginationClient.php | 16 +++++--- src/Utils.php | 47 +++++++++++++++++----- tests/Clients/CreditNoteTest.php | 2 +- tests/Clients/DownPaymentInvoiceTest.php | 2 +- tests/Clients/InvoiceTest.php | 2 +- tests/Clients/OrderConfirmationTest.php | 2 +- tests/Clients/QuotationTest.php | 2 +- tests/PaginationClientTest.php | 11 +++-- 16 files changed, 102 insertions(+), 76 deletions(-) diff --git a/README.md b/README.md index f87a792..9aabe32 100644 --- a/README.md +++ b/README.md @@ -224,5 +224,6 @@ $response = $api->file()->get($entityId); ### get JSON from Success and Error Response ```php -$json = $api->*()->getAsJson($response); +// can be possible null because the response body can be empty +$json = \Sysix\LexOffice\Utils::getJsonFromResponse($response); ``` \ No newline at end of file diff --git a/UPGRADE.md b/UPGRADE.md index 10888e5..e64b367 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -84,25 +84,24 @@ At the moment, it doesn't look like the endpoint will be added soon. So we will This functions will be removed in the next major (2.0) Update -- `\Sysix\Lexoffice\Clients\CreditNote::getAll` -- `\Sysix\Lexoffice\Clients\DownPaymentInvoice::getAll` -- `\Sysix\Lexoffice\Clients\Invoice::getAll` -- `\Sysix\Lexoffice\Clients\OrderConfirmation::getAll` -- `\Sysix\Lexoffice\Clients\Quotation::getAll` -- `\Sysix\Lexoffice\Clients\Voucher::getAll` -- `\Sysix\Lexoffice\Clients\VoucherList::setToEverything` -- -- `\Sysix\Lexoffice\Clients\CreditNote::getPage` -- `\Sysix\Lexoffice\Clients\DownPaymentInvoice::getPage` -- `\Sysix\Lexoffice\Clients\Invoice::getPage` -- `\Sysix\Lexoffice\Clients\OrderConfirmation::getPage` -- `\Sysix\Lexoffice\Clients\Quotation::getPage` -- `\Sysix\Lexoffice\Clients\Voucher::getPage` - -For almost all clients there is a new method called `getVoucherListClient` which returns a `\Sysix\LexOffice\Api\Clients\VoucherList`. -With this client there are more filters for the vouchers. - -! You need to set a non-empty `statuses` property to the `\Sysix\LexOffice\Api\Clients\VoucherList` +|Method Deprecated|Usage instead| +|---|---| +|`\Sysix\Lexoffice\Clients\CreditNote::getAll`|`\Sysix\Lexoffice\Clients\CreditNote::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\DownPaymentInvoice::getAll`|`\Sysix\Lexoffice\Clients\DownPaymentInvoice::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Invoice::getAll`|`\Sysix\Lexoffice\Clients\Invoice::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\OrderConfirmation::getAll`|`\Sysix\Lexoffice\Clients\OrderConfirmation::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Quotation::getAll`|`\Sysix\Lexoffice\Clients\Quotation::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Voucher::getAll`|`\Sysix\Lexoffice\Clients\Voucher::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\VoucherList::setToEverything`|not replacement| +|`\Sysix\Lexoffice\Clients\CreditNote::getPage`|`\Sysix\Lexoffice\Clients\CreditNote::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\DownPaymentInvoice::getPage`|`\Sysix\Lexoffice\Clients\DownPaymentInvoice::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Invoice::getPage`|`\Sysix\Lexoffice\Clients\Invoice::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\OrderConfirmation::getPage`|`\Sysix\Lexoffice\Clients\OrderConfirmation::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Quotation::getPage`|`\Sysix\Lexoffice\Clients\Quotation::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\Voucher::getPage`|`\Sysix\Lexoffice\Clients\Voucher::getVoucherListClient`| +|`\Sysix\Lexoffice\Clients\**::getAsJson`|`\Sysix\Lexoffice\Utils::getJsonFromResponse`| + +! You need to set a non-empty `statuses` property to the returned `\Sysix\LexOffice\Api\Clients\VoucherList`. ## Strict Typed diff --git a/src/BaseClient.php b/src/BaseClient.php index 68a32d9..4807746 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -3,9 +3,7 @@ namespace Sysix\LexOffice; -use GuzzleHttp\Psr7\MultipartStream; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\StreamInterface; abstract class BaseClient implements ClientInterface { @@ -17,35 +15,15 @@ public function __construct( { } - public function getAsJson(ResponseInterface $response): object - { - $body = $response->getBody()->__toString(); - - return Utils::jsonDecode($body); - } - - protected function createStream(mixed $content): StreamInterface - { - return Utils::streamFor( - Utils::jsonEncode($content) - ); - } - /** - * @param array $content + * @deprecated 1.0 use Sysix\LexOffice\Utils::getJsonFromResponse() */ - protected function createMultipartStream(array $content, string $boundary = null): MultipartStream + public function getAsJson(ResponseInterface $response): object { - $stream = []; - $boundary = $boundary ?: '--lexoffice'; + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, use \Sysix\LexOffice\Utils::getJsonFromResponse instead', E_USER_WARNING); - foreach ($content as $key => $value) { - $stream[] = [ - 'name' => $key, - 'contents' => $value - ]; - } + $body = $response->getBody()->__toString(); - return new MultipartStream($stream, $boundary); + return Utils::jsonDecode($body); } } diff --git a/src/Clients/File.php b/src/Clients/File.php index 145e5e6..0172fbd 100644 --- a/src/Clients/File.php +++ b/src/Clients/File.php @@ -6,6 +6,7 @@ use Sysix\LexOffice\Clients\Traits\GetTrait; use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Utils; class File extends BaseClient { @@ -38,7 +39,7 @@ public function upload(string $filepath, string $type): ResponseInterface throw new LexOfficeApiException('file is to big to upload: ' . $filepath . ', max upload size: ' . self::MAX_FILE_SIZE . 'bytes'); } - $body = $this->createMultipartStream([ + $body = Utils::createMultipartStream([ 'file' => fopen($filepath, 'r'), 'type' => $type ]); diff --git a/src/Clients/Traits/CreateFinalizeTrait.php b/src/Clients/Traits/CreateFinalizeTrait.php index 77d06ef..e0fe964 100644 --- a/src/Clients/Traits/CreateFinalizeTrait.php +++ b/src/Clients/Traits/CreateFinalizeTrait.php @@ -3,6 +3,7 @@ namespace Sysix\LexOffice\Clients\Traits; use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Utils; trait CreateFinalizeTrait { @@ -13,7 +14,7 @@ public function create(array $data, bool $finalized = false): ResponseInterface { $api = $this->api->newRequest('POST', $this->resource . ($finalized ? '?finalize=true' : '')); - $api->request = $api->request->withBody($this->createStream($data)); + $api->request = $api->request->withBody(Utils::createStream($data)); return $api->getResponse(); } diff --git a/src/Clients/Traits/CreateTrait.php b/src/Clients/Traits/CreateTrait.php index 6c2a749..b8b6edc 100644 --- a/src/Clients/Traits/CreateTrait.php +++ b/src/Clients/Traits/CreateTrait.php @@ -3,6 +3,7 @@ namespace Sysix\LexOffice\Clients\Traits; use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Utils; trait CreateTrait { @@ -13,7 +14,7 @@ public function create(array $data): ResponseInterface { $api = $this->api->newRequest('POST', $this->resource); - $api->request = $api->request->withBody($this->createStream($data)); + $api->request = $api->request->withBody(Utils::createStream($data)); return $api->getResponse(); } diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 3a04718..6e424e2 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -5,6 +5,7 @@ use Sysix\LexOffice\Clients\File; use Psr\Http\Message\ResponseInterface; use stdClass; +use Sysix\LexOffice\Utils; trait DocumentClientTrait { @@ -21,8 +22,13 @@ public function document(string $id, bool $asContent = false): ResponseInterface return $response; } - /** @var stdClass{documentField: string} $content */ - $content = $this->getAsJson($response); + /** @var ?stdClass{documentField: string} $content */ + $content = Utils::getJsonFromResponse($response); + + if ($content === null) { + return $response; + } + $fileClient = new File($this->api); return $fileClient->get($content->documentFileId); diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php index 13a194b..b3655ca 100644 --- a/src/Clients/Traits/UpdateTrait.php +++ b/src/Clients/Traits/UpdateTrait.php @@ -3,6 +3,7 @@ namespace Sysix\LexOffice\Clients\Traits; use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Utils; trait UpdateTrait { @@ -13,7 +14,7 @@ public function update(string $id, array $data): ResponseInterface { $api = $this->api->newRequest('PUT', $this->resource . '/' . $id); - $api->request = $api->request->withBody($this->createStream($data)); + $api->request = $api->request->withBody(Utils::createStream($data)); return $api->getResponse(); } diff --git a/src/PaginationClient.php b/src/PaginationClient.php index c00a4be..d821f19 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -41,18 +41,22 @@ public function getAll(): ResponseInterface trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); $response = $this->getPage(0); - /** @var stdClass{totalPages:int, content:stdClass[]} $result */ - $result = $this->getAsJson($response); + /** @var ?stdClass{totalPages:int, content:stdClass[]} $result */ + $result = Utils::getJsonFromResponse($response); - if ($result->totalPages == 1) { + if ($result === null || $result->totalPages == 1) { return $response; } // update content to get all contacts for ($i = 1; $i < $result->totalPages; $i++) { $responsePage = $this->getPage($i); - /** @var stdClass{totalPages:int, content:stdClass[]} $resultPage */ - $resultPage = $this->getAsJson($responsePage); + /** @var ?stdClass{totalPages:int, content:stdClass[]} $resultPage */ + $resultPage = Utils::getJsonFromResponse($responsePage); + + if ($resultPage === null) { + continue; + } foreach ($resultPage->content as $entity) { $result->content = [ @@ -62,6 +66,6 @@ public function getAll(): ResponseInterface } } - return $response->withBody($this->createStream($result)); + return $response->withBody(Utils::createStream($result)); } } \ No newline at end of file diff --git a/src/Utils.php b/src/Utils.php index 9eca0e0..d1cce28 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -5,14 +5,26 @@ use GuzzleHttp\Psr7\Stream; +use GuzzleHttp\Psr7\MultipartStream; use InvalidArgumentException; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; class Utils { + public static function getJsonFromResponse(ResponseInterface $response): mixed + { + $body = $response->getBody()->__toString(); + + if ($response->getHeaderLine("Content-Type") === "application/json") { + return self::jsonDecode($body); + } + + return null; + } + /** - * @param string $resource * @param array{size?: int, metadata?: mixed[], mode?: bool, seekable?: bool} $options - * @return Stream */ public static function streamFor(string $resource = '', array $options = []): Stream { @@ -30,10 +42,7 @@ public static function streamFor(string $resource = '', array $options = []): St } /** - * @param mixed $value - * @param int $options * @param int<1, max> $depth - * @return string */ public static function jsonEncode(mixed $value, int $options = 0, int $depth = 512): string { @@ -46,11 +55,7 @@ public static function jsonEncode(mixed $value, int $options = 0, int $depth = 5 } /** - * @param string $json - * @param bool $assoc * @param int<1, max> $depth - * @param int $options - * @return mixed */ public static function jsonDecode(string $json, bool $assoc = false, int $depth = 512, int $options = 0): mixed { @@ -61,4 +66,28 @@ public static function jsonDecode(string $json, bool $assoc = false, int $depth return $data; } + + + public static function createStream(mixed $content): StreamInterface + { + return Utils::streamFor(Utils::jsonEncode($content)); + } + + /** + * @param array $content + */ + public static function createMultipartStream(array $content, string $boundary = null): MultipartStream + { + $stream = []; + $boundary = $boundary ?: '--lexoffice'; + + foreach ($content as $key => $value) { + $stream[] = [ + 'name' => $key, + 'contents' => $value + ]; + } + + return new MultipartStream($stream, $boundary); + } } \ No newline at end of file diff --git a/tests/Clients/CreditNoteTest.php b/tests/Clients/CreditNoteTest.php index f3d105d..12b1bbb 100644 --- a/tests/Clients/CreditNoteTest.php +++ b/tests/Clients/CreditNoteTest.php @@ -126,7 +126,7 @@ public function testDocumentContent(): void [$api, $stub] = $this->createClientMultiMockObject( CreditNote::class, [ - new Response(200, [], '{"documentFileId": "fake-id"}'), + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), new Response() ] ); diff --git a/tests/Clients/DownPaymentInvoiceTest.php b/tests/Clients/DownPaymentInvoiceTest.php index 0b48d21..52db1c0 100644 --- a/tests/Clients/DownPaymentInvoiceTest.php +++ b/tests/Clients/DownPaymentInvoiceTest.php @@ -74,7 +74,7 @@ public function testDocumentContent(): void [$api, $stub] = $this->createClientMultiMockObject( DownPaymentInvoice::class, [ - new Response(200, [], '{"documentFileId": "fake-id"}'), + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), new Response() ] ); diff --git a/tests/Clients/InvoiceTest.php b/tests/Clients/InvoiceTest.php index 764f0bc..f5a4266 100644 --- a/tests/Clients/InvoiceTest.php +++ b/tests/Clients/InvoiceTest.php @@ -127,7 +127,7 @@ public function testDocumentContent(): void [$api, $stub] = $this->createClientMultiMockObject( Invoice::class, [ - new Response(200, [], '{"documentFileId": "fake-id"}'), + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), new Response() ] ); diff --git a/tests/Clients/OrderConfirmationTest.php b/tests/Clients/OrderConfirmationTest.php index 8f74007..65856fa 100644 --- a/tests/Clients/OrderConfirmationTest.php +++ b/tests/Clients/OrderConfirmationTest.php @@ -110,7 +110,7 @@ public function testDocumentContent(): void [$api, $stub] = $this->createClientMultiMockObject( OrderConfirmation::class, [ - new Response(200, [], '{"documentFileId": "fake-id"}'), + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), new Response() ] ); diff --git a/tests/Clients/QuotationTest.php b/tests/Clients/QuotationTest.php index 393ac29..d15b199 100644 --- a/tests/Clients/QuotationTest.php +++ b/tests/Clients/QuotationTest.php @@ -109,7 +109,7 @@ public function testDocumentContent(): void [$api, $stub] = $this->createClientMultiMockObject( Quotation::class, [ - new Response(200, [], '{"documentFileId": "fake-id"}'), + new Response(200, ['Content-Type' => 'application/json'], '{"documentFileId": "fake-id"}'), new Response() ] ); diff --git a/tests/PaginationClientTest.php b/tests/PaginationClientTest.php index d689221..79ca03d 100644 --- a/tests/PaginationClientTest.php +++ b/tests/PaginationClientTest.php @@ -51,7 +51,7 @@ public function setProtectedProperty(object $object, string $property, $value) $reflection_property->setValue($object, $value); } - public function testGetAll(): void + public function testGetAllSingle(): void { $this->expectDeprecationV1Warning('getAll'); @@ -63,11 +63,16 @@ public function testGetAll(): void '{"content": [], "totalPages": 1}', $stub->getAll()->getBody()->__toString() ); + } + + public function testGetAllMultiple(): void + { + $this->expectDeprecationV1Warning('getAll'); [, $stub] = $this->createPaginationClientMockObject( [ - new Response(200, [], '{"content": [{"name": "a"}], "totalPages": 2}'), - new Response(200, [], '{"content": [{"name": "b"}], "totalPages": 2}') + new Response(200, ['Content-Type' => 'application/json'], '{"content": [{"name": "a"}], "totalPages": 2}'), + new Response(200, ['Content-Type' => 'application/json'], '{"content": [{"name": "b"}], "totalPages": 2}') ] ); From 9f6b8836a5a1da761af731d3090587a446d662fe Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 23:15:22 +0100 Subject: [PATCH 61/69] update readme, add new filters --- README.md | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9aabe32..fd4c0a4 100644 --- a/README.md +++ b/README.md @@ -59,15 +59,17 @@ $api = new \Sysix\LexOffice\Api($apiKey, $httpClient); /** @var \Sysix\LexOffice\Api $api */ $client = $api->contact(); +// filters $client->size = 100; $client->sortDirection = 'ASC'; $client->sortProperty = 'name'; +$client->number = 123456; +$client->customer = true; +$client->vendor = false; // get a page $response = $client->getPage(0); -//get all -$response = $client->getAll(); // other methods $response = $client->get($entityId); @@ -169,9 +171,6 @@ $client->size = 100; // get a page $response = $client->getPage(0); - -//get all -$response = $client->getAll(); ``` @@ -182,6 +181,8 @@ $client = $api->voucherlist(); $client->size = 100; $client->sortDirection = 'DESC'; $client->sortColumn = 'voucherNumber'; + +// filters required $client->types = [ 'salesinvoice', 'salescreditnote', @@ -204,14 +205,18 @@ $client->statuses = [ 'rejected' ]; -// get everything what we can, not recommend: -//$client->setToEverything() +// filters optional +$client->archived = true; +$client->contactId = 'some-uuid-string'; +$client->voucherDateFrom = new \DateTime('2023-12-01'); +$client->voucherDateTo = new \DateTime('2023-12-01'); +$client->createdDateFrom = new \DateTime('2023-12-01');; +$client->createdDateTo = new \DateTime('2023-12-01'); +$client->updatedDateFrom = new \DateTime('2023-12-01'); +$client->updatedDateTo = new \DateTime('2023-12-01'); // get a page $response = $client->getPage(0); - -//get all -$response = $client->getAll(); ``` ### File Endpoint From 9c8aa3bd479625c8cd3f29f6df3c2f8ebf221a5c Mon Sep 17 00:00:00 2001 From: Sysix Date: Thu, 7 Dec 2023 23:35:22 +0100 Subject: [PATCH 62/69] encode incoming uuids --- src/Clients/Traits/DeleteTrait.php | 2 +- src/Clients/Traits/DocumentClientTrait.php | 2 +- src/Clients/Traits/GetTrait.php | 2 +- src/Clients/Traits/UpdateTrait.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Clients/Traits/DeleteTrait.php b/src/Clients/Traits/DeleteTrait.php index 92652cc..db1f3a1 100644 --- a/src/Clients/Traits/DeleteTrait.php +++ b/src/Clients/Traits/DeleteTrait.php @@ -9,7 +9,7 @@ trait DeleteTrait public function delete(string $id): ResponseInterface { - return $this->api->newRequest('DELETE', $this->resource . '/' . $id) + return $this->api->newRequest('DELETE', $this->resource . '/' . rawurlencode($id)) ->getResponse(); } } \ No newline at end of file diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 6e424e2..4de02a1 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -11,7 +11,7 @@ trait DocumentClientTrait { public function document(string $id, bool $asContent = false): ResponseInterface { - $response = $this->api->newRequest('GET', $this->resource . '/' . $id . '/document') + $response = $this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id) . '/document') ->getResponse(); if ($asContent === false) { diff --git a/src/Clients/Traits/GetTrait.php b/src/Clients/Traits/GetTrait.php index 2d719f7..026db7a 100644 --- a/src/Clients/Traits/GetTrait.php +++ b/src/Clients/Traits/GetTrait.php @@ -8,7 +8,7 @@ trait GetTrait { public function get(string $id): ResponseInterface { - return $this->api->newRequest('GET', $this->resource . '/' . $id) + return $this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id)) ->getResponse(); } } \ No newline at end of file diff --git a/src/Clients/Traits/UpdateTrait.php b/src/Clients/Traits/UpdateTrait.php index b3655ca..4544ad1 100644 --- a/src/Clients/Traits/UpdateTrait.php +++ b/src/Clients/Traits/UpdateTrait.php @@ -12,7 +12,7 @@ trait UpdateTrait */ public function update(string $id, array $data): ResponseInterface { - $api = $this->api->newRequest('PUT', $this->resource . '/' . $id); + $api = $this->api->newRequest('PUT', $this->resource . '/' . rawurlencode($id)); $api->request = $api->request->withBody(Utils::createStream($data)); From fbdbfdca6589c96a6d317ea21c45a1abf09bbc04 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 00:49:36 +0100 Subject: [PATCH 63/69] able to upload file to a voucher id --- README.md | 1 + src/Clients/File.php | 22 ++----- src/Clients/Voucher.php | 24 ++++++++ src/Config/FileClient/VoucherConfig.php | 31 ++++++++++ src/Config/FileClientConfig.php | 13 +++++ tests/Clients/FileTest.php | 3 +- tests/Clients/VoucherTest.php | 77 +++++++++++++++++++++++++ 7 files changed, 153 insertions(+), 18 deletions(-) create mode 100644 src/Config/FileClient/VoucherConfig.php create mode 100644 src/Config/FileClientConfig.php diff --git a/README.md b/README.md index fd4c0a4..b6a4a56 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ $response = $api->voucher()->create($data); $response = $api->voucher()->update($entityId, $data); $response = $api->voucher()->document($entityId); // get document ID $response = $api->voucher()->document($entityId, true); // get file content +$response = $api->voucher()->upload($entitiyId, $filepath); ``` diff --git a/src/Clients/File.php b/src/Clients/File.php index 0172fbd..482f3bd 100644 --- a/src/Clients/File.php +++ b/src/Clients/File.php @@ -6,38 +6,26 @@ use Sysix\LexOffice\Clients\Traits\GetTrait; use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Psr\Http\Message\ResponseInterface; +use Sysix\LexOffice\Config\FileClientConfig; use Sysix\LexOffice\Utils; class File extends BaseClient { use GetTrait; - const MAX_FILE_SIZE = 5 * 1024 * 1024; - protected string $resource = 'files'; - /** @var string[] */ - protected array $supportedExtension = ['png', 'jpg', 'pdf']; - /** * @throws LexOfficeApiException */ public function upload(string $filepath, string $type): ResponseInterface { - $regex = '/.(' . implode('|', $this->supportedExtension) . ')/'; - $matchResult = preg_match($regex, $filepath, $matches); - - if (!$matchResult || !$matches[0]) { - throw new LexOfficeApiException('file extension is not supported: ' . basename($filepath) . ' '); + if ($type !== 'voucher') { + throw new \InvalidArgumentException('only upload type voucher is supported'); } - if (!is_file($filepath)) { - throw new LexOfficeApiException('file could not be found to upload: ' . $filepath); - } - - if (filesize($filepath) > self::MAX_FILE_SIZE) { - throw new LexOfficeApiException('file is to big to upload: ' . $filepath . ', max upload size: ' . self::MAX_FILE_SIZE . 'bytes'); - } + $config = FileClientConfig::getVoucherConfig(); + $config->validateFileFromFilePath($filepath); $body = Utils::createMultipartStream([ 'file' => fopen($filepath, 'r'), diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index 6d43188..89c12f2 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -3,9 +3,12 @@ namespace Sysix\LexOffice\Clients; use Sysix\LexOffice\BaseClient; +use Sysix\LexOffice\Config\FileClientConfig; use Sysix\LexOffice\Clients\Traits\CreateTrait; use Sysix\LexOffice\Clients\Traits\GetTrait; use Sysix\LexOffice\Clients\Traits\UpdateTrait; +use Sysix\LexOffice\Exceptions\LexOfficeApiException; +use Sysix\LexOffice\Utils; use Psr\Http\Message\ResponseInterface; class Voucher extends BaseClient @@ -16,6 +19,27 @@ class Voucher extends BaseClient protected string $resource = 'vouchers'; + /** + * @throws LexOfficeApiException + */ + public function upload(string $id, string $filepath): ResponseInterface + { + $config = FileClientConfig::getVoucherConfig(); + $config->validateFileFromFilePath($filepath); + + $body = Utils::createMultipartStream([ + 'file' => fopen($filepath, 'r') + ]); + + $api = $this->api->newRequest('POST', $this->resource . '/' . rawurldecode($id), [ + 'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary() + ]); + + $api->request = $api->request->withBody($body); + + return $api->getResponse(); + } + /** * @deprecated 1.0 Not recommend anymore because of Rate Limiting, WILL be removed in 2.0 */ diff --git a/src/Config/FileClient/VoucherConfig.php b/src/Config/FileClient/VoucherConfig.php new file mode 100644 index 0000000..e48384f --- /dev/null +++ b/src/Config/FileClient/VoucherConfig.php @@ -0,0 +1,31 @@ +supportedExtension) . ')/'; + $matchResult = preg_match($regex, $filepath, $matches); + + if (!$matchResult || !$matches[0]) { + throw new LexOfficeApiException('file extension is not supported: ' . basename($filepath) . ' '); + } + + if (!is_file($filepath)) { + throw new LexOfficeApiException('file could not be found to upload: ' . $filepath); + } + + if (filesize($filepath) > self::MAX_FILE_SIZE) { + throw new LexOfficeApiException('file is to big to upload: ' . $filepath . ', max upload size: ' . self::MAX_FILE_SIZE . 'bytes'); + } + } +} \ No newline at end of file diff --git a/src/Config/FileClientConfig.php b/src/Config/FileClientConfig.php new file mode 100644 index 0000000..3e2c873 --- /dev/null +++ b/src/Config/FileClientConfig.php @@ -0,0 +1,13 @@ +fail('could not open file ' . $file); } - fseek($fp, File::MAX_FILE_SIZE + 1,SEEK_CUR); + fseek($fp, VoucherConfig::MAX_FILE_SIZE + 1,SEEK_CUR); fwrite($fp,'a'); fclose($fp); diff --git a/tests/Clients/VoucherTest.php b/tests/Clients/VoucherTest.php index 354ffc6..858200c 100644 --- a/tests/Clients/VoucherTest.php +++ b/tests/Clients/VoucherTest.php @@ -5,6 +5,8 @@ use GuzzleHttp\Psr7\Response; use Psr\Http\Message\ResponseInterface; use Sysix\LexOffice\Clients\Voucher; +use Sysix\LexOffice\Config\FileClient\VoucherConfig; +use Sysix\LexOffice\Exceptions\LexOfficeApiException; use Sysix\LexOffice\Tests\TestClient; class VoucherTest extends TestClient @@ -57,6 +59,81 @@ public function testUpdate(): void ); } + public function testUploadNotSupportedExtension(): void + { + $this->expectException(LexOfficeApiException::class); + + [, $stub] = $this->createClientMockObject(Voucher::class); + + $stub->upload('resource-id', 'not_allowed.gif'); + } + + public function testUploadNotFound(): void + { + $this->expectException(LexOfficeApiException::class); + + [, $stub] = $this->createClientMockObject(Voucher::class,); + + $stub->upload('resource-id', 'not_existing.jpg'); + } + + public function testUploadToBig(): void + { + $this->expectException(LexOfficeApiException::class); + + [, $stub] = $this->createClientMockObject(Voucher::class); + + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile.jpg'; + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + + fseek($fp, VoucherConfig::MAX_FILE_SIZE + 1,SEEK_CUR); + fwrite($fp,'a'); + fclose($fp); + + $stub->upload('resource-id', $file); + + unlink($file); + } + + public function testUploadSuccess(): void + { + [$api, $stub] = $this->createClientMockObject(Voucher::class); + + $this->createCacheDir(); + $file = $this->getCacheDir() . '/somefile2.jpg'; + $fp = fopen($file, 'w+'); + + if ($fp === false) { + $this->fail('could not open file ' . $file); + } + + fseek($fp, 5,SEEK_CUR); + fwrite($fp,'a'); + fclose($fp); + + $response = $stub->upload('resource-id', $file); + + unlink($file); + + $this->assertInstanceOf(ResponseInterface::class, $response); + + $this->assertEquals('POST', $api->request->getMethod()); + $this->assertEquals( + $api->apiUrl . '/v1/vouchers/resource-id', + $api->request->getUri()->__toString() + ); + + $this->assertStringContainsString( + 'multipart/form-data', + $api->request->getHeaderLine('Content-Type') + ); + } + public function testGetAll(): void { $this->expectDeprecationV1Warning('getAll'); From dfe93b5133ea1a6805948221fe17c157dd673120 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 00:53:49 +0100 Subject: [PATCH 64/69] encode instead of decode --- src/Clients/Voucher.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index 89c12f2..9286dfe 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -31,7 +31,7 @@ public function upload(string $id, string $filepath): ResponseInterface 'file' => fopen($filepath, 'r') ]); - $api = $this->api->newRequest('POST', $this->resource . '/' . rawurldecode($id), [ + $api = $this->api->newRequest('POST', $this->resource . '/' . rawurlencode($id), [ 'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary() ]); From d8c51ad0ab4897fabf73ce92384ef58565952b4f Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 01:13:21 +0100 Subject: [PATCH 65/69] use right trigger error level for deprecations --- src/BaseClient.php | 2 +- src/Clients/Traits/VoucherListTrait.php | 4 ++-- src/Clients/Voucher.php | 4 ++-- src/Clients/VoucherList.php | 2 +- src/PaginationClient.php | 2 +- tests/TestClient.php | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BaseClient.php b/src/BaseClient.php index 4807746..aa2058d 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -20,7 +20,7 @@ public function __construct( */ public function getAsJson(ResponseInterface $response): object { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, use \Sysix\LexOffice\Utils::getJsonFromResponse instead', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, use \Sysix\LexOffice\Utils::getJsonFromResponse instead', E_USER_DEPRECATED); $body = $response->getBody()->__toString(); diff --git a/src/Clients/Traits/VoucherListTrait.php b/src/Clients/Traits/VoucherListTrait.php index 1b9f1e9..24eaf3a 100644 --- a/src/Clients/Traits/VoucherListTrait.php +++ b/src/Clients/Traits/VoucherListTrait.php @@ -12,7 +12,7 @@ trait VoucherListTrait */ public function getPage(int $page): ResponseInterface { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED); $client = new VoucherList($this->api); $client->setToEverything(); @@ -26,7 +26,7 @@ public function getPage(int $page): ResponseInterface */ public function getAll(): ResponseInterface { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED); $client = new VoucherList($this->api); $client->setToEverything(); diff --git a/src/Clients/Voucher.php b/src/Clients/Voucher.php index 9286dfe..3f95e4f 100644 --- a/src/Clients/Voucher.php +++ b/src/Clients/Voucher.php @@ -45,7 +45,7 @@ public function upload(string $id, string $filepath): ResponseInterface */ public function getAll(): ResponseInterface { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED); $client = new VoucherList($this->api); @@ -54,7 +54,7 @@ public function getAll(): ResponseInterface */ $client->statuses = ['open', 'paid', 'paidoff', 'voided', 'transferred', 'sepadebit']; $client->types = ['salesinvoice', 'salescreditnote', 'purchaseinvoice', 'purchasecreditnote']; - + return $client->getAll(); } } diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index c98a815..205d8bb 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -39,7 +39,7 @@ class VoucherList extends PaginationClient */ public function setToEverything(): self { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED); $this->types = [ 'salesinvoice', diff --git a/src/PaginationClient.php b/src/PaginationClient.php index d821f19..7dcb876 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -38,7 +38,7 @@ public function getPage(int $page): ResponseInterface */ public function getAll(): ResponseInterface { - trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_WARNING); + trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, in future versions this method WILL not exist', E_USER_DEPRECATED); $response = $this->getPage(0); /** @var ?stdClass{totalPages:int, content:stdClass[]} $result */ diff --git a/tests/TestClient.php b/tests/TestClient.php index 69996d0..d0c63c6 100644 --- a/tests/TestClient.php +++ b/tests/TestClient.php @@ -95,7 +95,7 @@ public function expectDeprecationV1Warning(string $method): void { set_error_handler(static function (int $errno, string $errstr): void { throw new DeprecationException($errstr, $errno); - }, E_USER_WARNING); + }, E_USER_DEPRECATED); $this->expectException(DeprecationException::class); From 06d93e2398632a53d339f24054848c4fbf191912 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 02:43:57 +0100 Subject: [PATCH 66/69] level up phpstan to 9 --- phpstan.neon | 2 +- src/BaseClient.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 49cb743..d461cdd 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 8 + level: 9 paths: - src - tests \ No newline at end of file diff --git a/src/BaseClient.php b/src/BaseClient.php index aa2058d..f68b2ab 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -18,7 +18,7 @@ public function __construct( /** * @deprecated 1.0 use Sysix\LexOffice\Utils::getJsonFromResponse() */ - public function getAsJson(ResponseInterface $response): object + public function getAsJson(ResponseInterface $response): mixed { trigger_error(self::class . '::' . __METHOD__ . ' should not be called anymore, use \Sysix\LexOffice\Utils::getJsonFromResponse instead', E_USER_DEPRECATED); From b75b86224b269668f3f9729519887e819ccc4767 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 02:45:43 +0100 Subject: [PATCH 67/69] update di --- .github/workflows/shepherd.yml | 2 +- .github/workflows/update-license.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml index 336bd62..b0c6e3e 100644 --- a/.github/workflows/shepherd.yml +++ b/.github/workflows/shepherd.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest diff --git a/.github/workflows/update-license.yml b/.github/workflows/update-license.yml index 8ee1898..70134f9 100644 --- a/.github/workflows/update-license.yml +++ b/.github/workflows/update-license.yml @@ -8,7 +8,7 @@ jobs: update-license-year: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: FantasticFiasco/action-update-license-year@v2 From b1c11aee0cc8fcade33d08c0f164db4536987cfe Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 02:51:45 +0100 Subject: [PATCH 68/69] update phstan ci test --- .github/workflows/phpstan.yml | 17 +++++++++++++++++ .github/workflows/shepherd.yml | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/phpstan.yml delete mode 100644 .github/workflows/shepherd.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..bab8f6c --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,17 @@ +name: Run Shepherd + +on: [pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: php-actions/composer@v6 + - uses: php-actions/phpstan@v3 + with: + path: src/ tests/ + level: 9 + + \ No newline at end of file diff --git a/.github/workflows/shepherd.yml b/.github/workflows/shepherd.yml deleted file mode 100644 index b0c6e3e..0000000 --- a/.github/workflows/shepherd.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Run Shepherd - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: Install dependencies - run: composer install --prefer-dist --no-progress --no-suggest - - - name: Run Psalm - run: ./vendor/bin/phpstan analyse --ansi --error-format github \ No newline at end of file From 7c35d071497932ba480464cd6dbfd8b650cfa1c0 Mon Sep 17 00:00:00 2001 From: Sysix Date: Fri, 8 Dec 2023 23:27:49 +0100 Subject: [PATCH 69/69] pagination client can be sorted (expect contact) --- README.md | 16 +++++++--------- src/Clients/Contact.php | 5 ----- src/Clients/RecurringTemplate.php | 2 ++ src/Clients/Traits/DocumentClientTrait.php | 3 ++- src/Clients/VoucherList.php | 6 ++---- src/PaginationClient.php | 9 +++++++++ tests/Clients/ContactTest.php | 4 ++-- tests/Clients/RecurringTemplateTest.php | 2 +- tests/Clients/VoucherListTest.php | 4 ++-- 9 files changed, 27 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b6a4a56..95c5ce2 100644 --- a/README.md +++ b/README.md @@ -55,14 +55,11 @@ $api = new \Sysix\LexOffice\Api($apiKey, $httpClient); ### Contact Endpoint ```php -// get a page /** @var \Sysix\LexOffice\Api $api */ $client = $api->contact(); // filters $client->size = 100; -$client->sortDirection = 'ASC'; -$client->sortProperty = 'name'; $client->number = 123456; $client->customer = true; $client->vendor = false; @@ -70,7 +67,6 @@ $client->vendor = false; // get a page $response = $client->getPage(0); - // other methods $response = $client->get($entityId); $response = $client->create($data); @@ -162,16 +158,18 @@ $response = $api->profile()->get(); ### Recurring Templates Endpoint ```php -// get single entitiy -$response = $api->recurringTemplate()->get($entityId); - -// use pagination $client = $api->recurringTemplate(); -$client->size = 100; +// filters +$client->size = 100; +$client->sortDirection = 'DESC'; +$client->sortColumn = 'updatedDate'; // get a page $response = $client->getPage(0); + +// other methods +$response = $api->recurringTemplate()->get($entityId); ``` diff --git a/src/Clients/Contact.php b/src/Clients/Contact.php index 30c63cc..81ca36e 100644 --- a/src/Clients/Contact.php +++ b/src/Clients/Contact.php @@ -15,9 +15,6 @@ class Contact extends PaginationClient protected string $resource = 'contacts'; - public string $sortDirection = 'ASC'; - - public string $sortProperty = 'name'; public ?int $number = null; @@ -27,8 +24,6 @@ class Contact extends PaginationClient protected function buildQueryParams(array $params): string { - $params['direction'] = $this->sortDirection; - $params['property'] = $this->sortProperty; $params['number'] = $this->number; $params['customer'] = $this->customer; $params['vendor'] = $this->vendor; diff --git a/src/Clients/RecurringTemplate.php b/src/Clients/RecurringTemplate.php index 8c351a0..1a41c2e 100644 --- a/src/Clients/RecurringTemplate.php +++ b/src/Clients/RecurringTemplate.php @@ -10,4 +10,6 @@ class RecurringTemplate extends PaginationClient use GetTrait; protected string $resource = 'recurring-templates'; + + public string $sortColumn = 'updatedDate'; } diff --git a/src/Clients/Traits/DocumentClientTrait.php b/src/Clients/Traits/DocumentClientTrait.php index 4de02a1..1e675fe 100644 --- a/src/Clients/Traits/DocumentClientTrait.php +++ b/src/Clients/Traits/DocumentClientTrait.php @@ -11,7 +11,8 @@ trait DocumentClientTrait { public function document(string $id, bool $asContent = false): ResponseInterface { - $response = $this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id) . '/document') + $response = $this->api + ->newRequest('GET', $this->resource . '/' . rawurlencode($id) . '/document') ->getResponse(); if ($asContent === false) { diff --git a/src/Clients/VoucherList.php b/src/Clients/VoucherList.php index 205d8bb..4e1f332 100644 --- a/src/Clients/VoucherList.php +++ b/src/Clients/VoucherList.php @@ -10,13 +10,12 @@ class VoucherList extends PaginationClient protected string $resource = 'voucherlist'; public string $sortColumn = 'voucherNumber'; - public string $sortDirection = 'DESC'; /** @var string[] $types */ - public array $types = []; + public array $types; /** @var string[] $statuses */ - public array $statuses = []; + public array $statuses; public ?bool $archived = null; @@ -71,7 +70,6 @@ protected function buildQueryParams(array $params): string { $dateFormat = DateTimeInterface::ATOM; - $params['sort'] = $this->sortColumn . ',' . $this->sortDirection; $params['voucherType'] = implode(',', $this->types); $params['voucherStatus'] = implode(',', $this->statuses); $params['archived'] = $this->archived; diff --git a/src/PaginationClient.php b/src/PaginationClient.php index 7dcb876..53dacc1 100644 --- a/src/PaginationClient.php +++ b/src/PaginationClient.php @@ -9,6 +9,10 @@ abstract class PaginationClient extends BaseClient { public int $size = 100; + public string $sortColumn; + + public string $sortDirection = 'DESC'; + protected function generatePageUrl(int $page): string { return $this->resource . '?' . $this->buildQueryParams([ @@ -23,6 +27,11 @@ protected function buildQueryParams(array $params): string { $params['size'] = $this->size; + // contact endpoint can't be sorted but is a Pagination client + if (isset($this->sortColumn)) { + $params['sort'] = $this->sortColumn . ',' . $this->sortDirection; + } + return http_build_query($params); } diff --git a/tests/Clients/ContactTest.php b/tests/Clients/ContactTest.php index e02edee..a804ce7 100644 --- a/tests/Clients/ContactTest.php +++ b/tests/Clients/ContactTest.php @@ -18,7 +18,7 @@ public function testGetPage(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&size=100', + $api->apiUrl . '/v1/contacts?page=0&size=100', $api->request->getUri()->__toString() ); } @@ -34,7 +34,7 @@ public function testGetPageWithFilters(): void $client->getPage(0); $this->assertEquals( - $api->apiUrl . '/v1/contacts?page=0&direction=ASC&property=name&number=12345&customer=1&vendor=0&size=100', + $api->apiUrl . '/v1/contacts?page=0&number=12345&customer=1&vendor=0&size=100', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/RecurringTemplateTest.php b/tests/Clients/RecurringTemplateTest.php index 9f09410..126ee64 100644 --- a/tests/Clients/RecurringTemplateTest.php +++ b/tests/Clients/RecurringTemplateTest.php @@ -31,7 +31,7 @@ public function testGetPage(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/recurring-templates?page=0&size=100', + $api->apiUrl . '/v1/recurring-templates?page=0&size=100&sort=updatedDate%2CDESC', $api->request->getUri()->__toString() ); } diff --git a/tests/Clients/VoucherListTest.php b/tests/Clients/VoucherListTest.php index 421f993..d3b83ad 100644 --- a/tests/Clients/VoucherListTest.php +++ b/tests/Clients/VoucherListTest.php @@ -24,7 +24,7 @@ public function testGetPage(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->apiUrl . '/v1/voucherlist?page=0&voucherType=invoice&voucherStatus=open&archived=1&size=100&sort=voucherNumber%2CDESC', $api->request->getUri()->__toString() ); } @@ -48,7 +48,7 @@ public function testGetAll(): void $this->assertEquals('GET', $api->request->getMethod()); $this->assertEquals( - $api->apiUrl . '/v1/voucherlist?page=0&sort=voucherNumber%2CDESC&voucherType=invoice&voucherStatus=open&archived=1&size=100', + $api->apiUrl . '/v1/voucherlist?page=0&voucherType=invoice&voucherStatus=open&archived=1&size=100&sort=voucherNumber%2CDESC', $api->request->getUri()->__toString() ); }