From 929490d10eaf2849f55c73a69a3632138d2d060f Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Mon, 16 Oct 2023 11:10:51 +0200 Subject: [PATCH 01/32] Prepare update + change dockerfile --- README.md | 15 +++++++++------ composer.json | 4 ++-- docker/php/Dockerfile | 2 +- rector.php | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 336418fd..64e82bd7 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ * [Authors](#authors) * [Licence](#licence) -Version 2.5.2 +Version 2.6.0 ## Requirements -* PHP 8.1 min or superior (oldest versions are no longer supported) +* PHP 8.2 min or superior (oldest versions are no longer supported) * API Key and API Secret from [Astrobin](https://www.astrobin.com/api/request-key/) ## Introduction @@ -53,17 +53,20 @@ You can install this package in 2 different ways. Update to the newest version : > `composer update hamhamfonfon/astrobin-ws` -* If you just want to make some issues, make some simple tests etc, juste clone the repository - -> `git clone git@github.com:HamHamFonFon/Astrobin-Webservices.git` If you're using old PHP versions: +- PHP 8.1 +> `composer require hamhamfonfon/astrobin-ws:2.5` - PHP 7.4 | 8.0 > `composer require hamhamfonfon/astrobin-ws:2.4` - PHP 7.3 > `composer require hamhamfonfon/astrobin-ws:2.3` -Caution, these versions are not maintained anymore. Only 2.5.* will be maintained and will have new features. +Caution, these versions are not maintained anymore. Only 2.6.* will be maintained and will have new features. + +* If you just want to make some issues, make some simple tests etc, juste clone the repository + +> `git clone git@github.com:HamHamFonFon/Astrobin-Webservices.git` ### Usage diff --git a/composer.json b/composer.json index 1bbc4afb..8fb487ab 100644 --- a/composer.json +++ b/composer.json @@ -15,11 +15,11 @@ }, "config": { "platform": { - "php": "8.1" + "php": "8.2" } }, "require" : { - "php": ">=8.1.0", + "php": ">=8.2.0", "guzzlehttp/guzzle": "^7.5", "ext-ctype": "*", "ext-json": "*" diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index c3478858..1cc58a31 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1.0-fpm +FROM php:8.2.0-fpm ARG USERNAME=site ARG USER_UID diff --git a/rector.php b/rector.php index 5e053836..bbaa9f11 100644 --- a/rector.php +++ b/rector.php @@ -16,7 +16,7 @@ // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); - $rectorConfig->sets([LevelSetList::UP_TO_PHP_81]); + $rectorConfig->sets([LevelSetList::UP_TO_PHP_82]); $rectorConfig->sets([SetList::CODE_QUALITY]); // $rectorConfig->sets([SetList::CODING_STYLE]); }; From c8828387a941256b17a9b549ddfa17c35297ffec Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Mon, 16 Oct 2023 11:14:14 +0200 Subject: [PATCH 02/32] Update CI github side --- .github/workflows/php.yml | 4 ++-- .travis.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2b28495b..dd4e82f0 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -16,10 +16,10 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up php 8.1 + - name: Set up php 8.2 uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' - name: Validate composer.json and composer.lock run: composer validate --strict diff --git a/.travis.yml b/.travis.yml index 330ec4ed..45adb10d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ dist: trusty language: php php: - - '8.1' + - '8.2' - nightly before_script: composer install script: From 277ecbefb28a1cfe91ad4ad9554485e627334ef8 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Mon, 16 Oct 2023 11:37:45 +0200 Subject: [PATCH 03/32] Update coding style + php 8.2 compliants --- src/AbstractWebService.php | 11 +++++-- src/Exceptions/WsException.php | 31 +++++++++++++++++-- src/GuzzleSingleton.php | 21 +++++++++++++ src/Response/DTO/AstrobinError.php | 7 ++--- .../DTO/Collection/ListCollection.php | 2 +- src/Response/DTO/Collection/ListImages.php | 1 + src/Response/DTO/Collection/ListToday.php | 1 + src/Response/DTO/Item/Collection.php | 6 ++++ src/Response/DTO/Item/Image.php | 16 ++++++++++ src/Response/DTO/Item/Today.php | 3 +- src/Response/DTO/Item/User.php | 9 ++++++ src/Response/EntityFactory.php | 1 + src/Services/GetCollection.php | 5 +++ src/Services/GetImage.php | 3 ++ src/Services/GetTodayImage.php | 3 ++ src/Services/GetUser.php | 3 ++ src/Services/WsAstrobinTrait.php | 2 ++ 17 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/AbstractWebService.php b/src/AbstractWebService.php index cee8226a..9273b63f 100644 --- a/src/AbstractWebService.php +++ b/src/AbstractWebService.php @@ -22,7 +22,14 @@ */ abstract class AbstractWebService { + /** + * @var int + */ final public const LIMIT_MAX = 20; + + /** + * @var int + */ final public const TIMEOUT = 30; protected int $timeout = self::TIMEOUT; @@ -130,7 +137,8 @@ private function buildRequest( $options['body'] = $body; } - $guzzleResponse = $msgErr = null; + $guzzleResponse = null; + $msgErr = null; try { $guzzleResponse = $this->client->request($method, $endPoint, $options); } catch (GuzzleException $guzzleException) { @@ -144,7 +152,6 @@ private function buildRequest( throw new WsException($msgErr, 500, null); } - /** * Check response and jsondecode object * @throws WsException|JsonException diff --git a/src/Exceptions/WsException.php b/src/Exceptions/WsException.php index e3fce975..1f36d4f2 100644 --- a/src/Exceptions/WsException.php +++ b/src/Exceptions/WsException.php @@ -11,22 +11,49 @@ */ class WsException extends \Exception implements \Stringable { + /** + * @var string + */ public const KEYS_ERROR = 'API key or API secret are null'; + /** + * @var string + */ public const GUZZLE_RESPONSE = 'Error response Guzzle: %s'; + /** + * @var string + */ public const ERR_READABLE = 'Response not readable'; + /** + * @var string + */ public const ERR_EMPTY = 'Empty response from endPoint "%s"'; + /** + * @var string + */ public const ERR_JSON = 'Not a JSON valid format :\n %s'; - public const RESP_EMPTY = 'Astrobin doesn\'t find any objects, check your params'; + /** + * @var string + */ + public const RESP_EMPTY = "Astrobin doesn't find any objects, check your params"; + /** + * @var string + */ public const EMPTY_ID = '%s is not a correct value, alphanumeric expected'; + /** + * @var string + */ public const ERR_DATE_FORMAT = 'Format "%s" is not a correct format for a date, please use YYYY-mm-dd instead'; + /** + * @var string + */ public const ERR_DATE = 'Error date format : \n'; /** @@ -42,6 +69,6 @@ public function __construct(string $message, int $code, ?\Exception $previous) */ public function __toString(): string { - return self::class . "[{$this->getCode()}]: {$this->getMessage()}\n"; + return self::class . sprintf('[%d]: %s%s', $this->getCode(), $this->getMessage(), PHP_EOL); } } diff --git a/src/GuzzleSingleton.php b/src/GuzzleSingleton.php index 69fbdabc..56b6c3e0 100644 --- a/src/GuzzleSingleton.php +++ b/src/GuzzleSingleton.php @@ -13,13 +13,34 @@ */ class GuzzleSingleton { + /** + * @var string + */ final public const ASTROBIN_URL = 'https://www.astrobin.com'; + + /** + * @var string + */ final public const TIMEOUT = '0'; + /** + * @var string + */ final public const APPLICATION_JSON = 'application/json'; + /** + * @var string + */ final public const METHOD_GET = 'GET'; + + /** + * @var string + */ final public const METHOD_POST = 'POST'; + + /** + * @var string + */ final public const METHOD_PUT = 'PUT'; private static ?Client $_instance = null; diff --git a/src/Response/DTO/AstrobinError.php b/src/Response/DTO/AstrobinError.php index 945ddd56..acafdd58 100644 --- a/src/Response/DTO/AstrobinError.php +++ b/src/Response/DTO/AstrobinError.php @@ -8,12 +8,9 @@ * Class AstrobinError * @package AstrobinWs\Response */ -final class AstrobinError implements AstrobinResponse +final readonly class AstrobinError implements AstrobinResponse { - /** - * AstrobinError constructor. - */ - public function __construct(private readonly ?string $message) + public function __construct(private ?string $message) { } diff --git a/src/Response/DTO/Collection/ListCollection.php b/src/Response/DTO/Collection/ListCollection.php index fe0b8ecf..46e81091 100644 --- a/src/Response/DTO/Collection/ListCollection.php +++ b/src/Response/DTO/Collection/ListCollection.php @@ -17,7 +17,7 @@ final class ListCollection extends AbstractResponse implements \IteratorAggregat public array $listCollection; /** - * @return CollectionIterator|\Traversable + * @return CollectionIterator */ public function getIterator(): CollectionIterator { diff --git a/src/Response/DTO/Collection/ListImages.php b/src/Response/DTO/Collection/ListImages.php index 5e72b17a..585d7003 100644 --- a/src/Response/DTO/Collection/ListImages.php +++ b/src/Response/DTO/Collection/ListImages.php @@ -15,6 +15,7 @@ final class ListImages implements \IteratorAggregate, AstrobinResponse { public array $listImages = []; + public int $count = 0; public function getIterator(): ImageIterator diff --git a/src/Response/DTO/Collection/ListToday.php b/src/Response/DTO/Collection/ListToday.php index 83baba47..30dac144 100644 --- a/src/Response/DTO/Collection/ListToday.php +++ b/src/Response/DTO/Collection/ListToday.php @@ -15,6 +15,7 @@ class ListToday extends AbstractResponse implements \IteratorAggregate, AstrobinResponse { public array $listToday; + public int $count = 0; /** diff --git a/src/Response/DTO/Item/Collection.php b/src/Response/DTO/Item/Collection.php index 26246754..c9462f9b 100644 --- a/src/Response/DTO/Item/Collection.php +++ b/src/Response/DTO/Item/Collection.php @@ -16,12 +16,18 @@ final class Collection extends AbstractResponse implements AstrobinResponse { public int $id; + public string $name; + public ?string $description = null; + public string $user; + public string|\DateTime $date_created; + public string|\DateTime $date_updated; + public ListImages|array|null $images = null; public function setDateCreated(string $dateCreated): self diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index 7ab423f7..3d6a5dfb 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -14,26 +14,42 @@ final class Image extends AbstractResponse implements AstrobinResponse { public ?string $title = null; + public ?array $subjects; + public ?string $description = null; + public string|null $uploaded = null; + public ?string $url_gallery = null; + public ?string $url_thumb = null; + public ?string $url_regular = null; + public ?string $url_hd = null; + public ?string $url_solution = null; + public ?string $user = null; + public ?string $url_histogram = null; + public ?string $url_skyplot = null; + public ?string $url_advanced_skyplot_small = null; + public ?int $views = 0; + public ?int $likes = 0; + public function getUploaded(): ?\DateTime { if (is_null($this->uploaded)) { return null; } + try { return \DateTime::createFromFormat('Y-m-d\T H:i:s.u', $this->uploaded) ?: null; } catch (\Exception) { diff --git a/src/Response/DTO/Item/Today.php b/src/Response/DTO/Item/Today.php index 2dd7e8d4..94b0742a 100644 --- a/src/Response/DTO/Item/Today.php +++ b/src/Response/DTO/Item/Today.php @@ -14,10 +14,11 @@ final class Today extends AbstractResponse implements AstrobinResponse { public string $date; + /** * Path of image, not Image instance */ public string|Image|null $image = null; - public string $resource_uri; + public string $resource_uri; } diff --git a/src/Response/DTO/Item/User.php b/src/Response/DTO/Item/User.php index 75165b88..cc6bb1d0 100644 --- a/src/Response/DTO/Item/User.php +++ b/src/Response/DTO/Item/User.php @@ -14,12 +14,21 @@ final class User extends AbstractResponse implements AstrobinResponse { public int $id; + public string $username; + public ?string $about = null; + public ?string $avatar = null; + public ?int $image_count = null; + public ?string $job = null; + public ?string $hobbies = null; + public ?string $language = null; + public ?string $website = null; + } diff --git a/src/Response/EntityFactory.php b/src/Response/EntityFactory.php index 20d01126..d456a1ef 100644 --- a/src/Response/EntityFactory.php +++ b/src/Response/EntityFactory.php @@ -9,6 +9,7 @@ final class EntityFactory private readonly mixed $rawResponse; private ?string $entity = null; + private ?string $collectionEntity = null; /** diff --git a/src/Services/GetCollection.php b/src/Services/GetCollection.php index 5276cde3..51925e84 100644 --- a/src/Services/GetCollection.php +++ b/src/Services/GetCollection.php @@ -21,6 +21,9 @@ class GetCollection extends AbstractWebService implements WsInterface { use WsAstrobinTrait; + /** + * @var string + */ final public const END_POINT = 'collection'; /** @@ -61,6 +64,7 @@ public function getById(?string $id): ?AstrobinResponse if (is_null($id)) { throw new WsException(sprintf(WsException::EMPTY_ID, $id), 500, null); } + $collection = $this->sendRequestAndBuildResponse($id, null); return $this->getImagesFromResource($collection); } @@ -79,6 +83,7 @@ public function getListCollectionByUser( if (parent::LIMIT_MAX < $limit) { return null; } + $params = [CollectionFilters::USER_FILTER->value => $username, QueryFilters::LIMIT->value => $limit]; return $this->sendRequestAndBuildResponse(null, $params); } diff --git a/src/Services/GetImage.php b/src/Services/GetImage.php index 145d5667..8a79371a 100644 --- a/src/Services/GetImage.php +++ b/src/Services/GetImage.php @@ -23,6 +23,9 @@ class GetImage extends AbstractWebService implements WsInterface { use WsAstrobinTrait; + /** + * @var string + */ final public const END_POINT = 'image'; protected function getEndPoint(): string diff --git a/src/Services/GetTodayImage.php b/src/Services/GetTodayImage.php index eb4ce337..923be7a2 100644 --- a/src/Services/GetTodayImage.php +++ b/src/Services/GetTodayImage.php @@ -18,6 +18,9 @@ class GetTodayImage extends AbstractWebService implements WsInterface { use WsAstrobinTrait; + /** + * @var string + */ final public const END_POINT = 'imageoftheday'; protected function getEndPoint(): string diff --git a/src/Services/GetUser.php b/src/Services/GetUser.php index 4413dc6f..bd350b98 100644 --- a/src/Services/GetUser.php +++ b/src/Services/GetUser.php @@ -18,6 +18,9 @@ class GetUser extends AbstractWebService implements WsInterface { use WsAstrobinTrait; + /** + * @var string + */ final public const END_POINT = 'userprofile'; /** diff --git a/src/Services/WsAstrobinTrait.php b/src/Services/WsAstrobinTrait.php index ead22ebd..34bcb3c2 100644 --- a/src/Services/WsAstrobinTrait.php +++ b/src/Services/WsAstrobinTrait.php @@ -37,6 +37,7 @@ protected function getImagesFromResource(AstrobinResponse $entity): ?AstrobinRes $listImages->add($astrobinImage); } } + $entity->images = $listImages; } @@ -64,6 +65,7 @@ protected function sendRequestAndBuildResponse(?string $id, ?array $params): ?As if (is_null($response)) { return new AstrobinError(WsException::ERR_EMPTY); } + $AstrobinResponse = $this->buildResponse($response); } catch (WsException | JsonException $e) { $AstrobinResponse = new AstrobinError($e->getMessage()); From e6314b116ecf84a1b5085e5796089172e0ce8278 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Mon, 16 Oct 2023 12:02:52 +0200 Subject: [PATCH 04/32] Rector rules --- rector.php | 16 ++++++++++++---- src/AbstractWebService.php | 22 +++++++++++----------- src/Exceptions/WsException.php | 3 --- src/Services/GetCollection.php | 11 ----------- src/Services/GetImage.php | 3 ++- src/Services/GetUser.php | 6 +++++- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/rector.php b/rector.php index bbaa9f11..08f422dc 100644 --- a/rector.php +++ b/rector.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; +use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector; use Rector\Config\RectorConfig; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -14,9 +15,16 @@ ]); // register a single rule - $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); + $rectorConfig->rule(InlineArrayReturnAssignRector::class); - $rectorConfig->sets([LevelSetList::UP_TO_PHP_82]); - $rectorConfig->sets([SetList::CODE_QUALITY]); -// $rectorConfig->sets([SetList::CODING_STYLE]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_82, + SetList::CODE_QUALITY, + SetList::CODING_STYLE, + SetList::TYPE_DECLARATION, +// SetList::DEAD_CODE, + SetList::EARLY_RETURN, + ]); }; diff --git a/src/AbstractWebService.php b/src/AbstractWebService.php index 9273b63f..c5c27ac4 100644 --- a/src/AbstractWebService.php +++ b/src/AbstractWebService.php @@ -39,9 +39,6 @@ abstract class AbstractWebService 'Content-Type' => GuzzleSingleton::APPLICATION_JSON ]; - /** - * @var Client - */ private Client $client; /** @@ -181,17 +178,20 @@ public function checkGuzzleResponse(ResponseInterface $response): string throw new WsResponseException(WsException::RESP_EMPTY, 500, null); } - if ( - property_exists($jsonContent, "objects") - && property_exists($jsonContent, "meta") - && 0 === $jsonContent->meta->total_count - ) { - throw new WsResponseException(WsException::RESP_EMPTY, 500, null); + if (!property_exists($jsonContent, "objects")) { + return $contents; } - return $contents; - } + if (!property_exists($jsonContent, "meta")) { + return $contents; + } + + if (0 !== $jsonContent->meta->total_count) { + return $contents; + } + throw new WsResponseException(WsException::RESP_EMPTY, 500, null); + } /** * @throws JsonException diff --git a/src/Exceptions/WsException.php b/src/Exceptions/WsException.php index 1f36d4f2..d81f4031 100644 --- a/src/Exceptions/WsException.php +++ b/src/Exceptions/WsException.php @@ -64,9 +64,6 @@ public function __construct(string $message, int $code, ?\Exception $previous) parent::__construct(...func_get_args()); } - /** - * @return string - */ public function __toString(): string { return self::class . sprintf('[%d]: %s%s', $this->getCode(), $this->getMessage(), PHP_EOL); diff --git a/src/Services/GetCollection.php b/src/Services/GetCollection.php index 51925e84..8dbb92f8 100644 --- a/src/Services/GetCollection.php +++ b/src/Services/GetCollection.php @@ -26,25 +26,16 @@ class GetCollection extends AbstractWebService implements WsInterface */ final public const END_POINT = 'collection'; - /** - * @return string - */ protected function getEndPoint(): string { return self::END_POINT; } - /** - * @return string - */ protected function getObjectEntity(): string { return Collection::class; } - /** - * @return string - */ protected function getCollectionEntity(): string { return ListCollection::class; @@ -52,8 +43,6 @@ protected function getCollectionEntity(): string /** - * @param string|null $id - * @return AstrobinResponse|null * @throws WsException * @throws WsResponseException * @throws \JsonException diff --git a/src/Services/GetImage.php b/src/Services/GetImage.php index 8a79371a..53bab726 100644 --- a/src/Services/GetImage.php +++ b/src/Services/GetImage.php @@ -128,6 +128,7 @@ public function getImagesByUser(string $userName, int $limit): ?AstrobinResponse * Get image filtered by range date * @throws JsonException * @throws WsException + * @throws \Exception */ public function getImagesByRangeDate( ?string $dateFromStr, @@ -167,7 +168,7 @@ public function getImageBy(array $filters, int $limit): ?AstrobinResponse return null; } - $params = array_filter($filters, static fn($key) => in_array($key, array_column(ImageFilters::cases(), 'value'), true), ARRAY_FILTER_USE_KEY); + $params = array_filter($filters, static fn($key): bool => in_array($key, array_column(ImageFilters::cases(), 'value'), true), ARRAY_FILTER_USE_KEY); $params = [...$params, QueryFilters::LIMIT->value => $limit]; return $this->sendRequestAndBuildResponse(null, $params); diff --git a/src/Services/GetUser.php b/src/Services/GetUser.php index bd350b98..ef044cc7 100644 --- a/src/Services/GetUser.php +++ b/src/Services/GetUser.php @@ -67,7 +67,11 @@ public function getById(?string $id): ?AstrobinResponse */ public function getByUsername(string $username, int $limit): ?AstrobinResponse { - if (empty($username) || (parent::LIMIT_MAX < $limit)) { + if (empty($username)) { + return null; + } + + if (parent::LIMIT_MAX < $limit) { return null; } From 0cc4e8c23dfc0e16ba0c2dd15360c056267ee57d Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Wed, 8 Nov 2023 16:26:19 +0100 Subject: [PATCH 05/32] Add properties for image --- src/Response/DTO/Item/Image.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index 3d6a5dfb..cac301f7 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -30,6 +30,7 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_hd = null; public ?string $url_solution = null; + public ?string $url_advanced_solution = null; public ?string $user = null; @@ -37,6 +38,7 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_skyplot = null; + public ?string $url_advanced_skyplot = null; public ?string $url_advanced_skyplot_small = null; public ?int $views = 0; From 04dc640ff92f70d76c6277d031e5d5543a8eac9e Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Wed, 8 Nov 2023 16:28:54 +0100 Subject: [PATCH 06/32] Fix TU Image properties --- tests/Response/DTO/Item/ImageTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Response/DTO/Item/ImageTest.php b/tests/Response/DTO/Item/ImageTest.php index 5e5c9049..d6c91878 100644 --- a/tests/Response/DTO/Item/ImageTest.php +++ b/tests/Response/DTO/Item/ImageTest.php @@ -14,6 +14,7 @@ class ImageTest extends TestCase 'subjects', 'title', 'uploaded', + 'url_advanced_skyplot', 'url_advanced_skyplot_small', 'url_gallery', 'url_hd', @@ -21,6 +22,7 @@ class ImageTest extends TestCase 'url_regular', 'url_skyplot', 'url_solution', + 'url_advanced_solution', 'url_thumb', 'user', 'views' From a1fd801b43c30ea345efe521a3530319b9d53ce3 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Wed, 8 Nov 2023 16:39:12 +0100 Subject: [PATCH 07/32] Fix TU --- src/Response/DTO/Item/Image.php | 3 +-- tests/Response/DTO/Item/ImageTest.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index cac301f7..9eeffe9c 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -32,8 +32,6 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_solution = null; public ?string $url_advanced_solution = null; - public ?string $user = null; - public ?string $url_histogram = null; public ?string $url_skyplot = null; @@ -41,6 +39,7 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_advanced_skyplot = null; public ?string $url_advanced_skyplot_small = null; + public ?string $user = null; public ?int $views = 0; public ?int $likes = 0; diff --git a/tests/Response/DTO/Item/ImageTest.php b/tests/Response/DTO/Item/ImageTest.php index d6c91878..80129061 100644 --- a/tests/Response/DTO/Item/ImageTest.php +++ b/tests/Response/DTO/Item/ImageTest.php @@ -16,13 +16,13 @@ class ImageTest extends TestCase 'uploaded', 'url_advanced_skyplot', 'url_advanced_skyplot_small', + 'url_advanced_solution', 'url_gallery', 'url_hd', 'url_histogram', 'url_regular', 'url_skyplot', 'url_solution', - 'url_advanced_solution', 'url_thumb', 'user', 'views' From ab2a9ae0ff479ae3467c03d18bd3a9631a2aa77d Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 08:45:28 +0100 Subject: [PATCH 08/32] TU property uploaded --- tests/Response/DTO/Item/ImageTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/Response/DTO/Item/ImageTest.php b/tests/Response/DTO/Item/ImageTest.php index 80129061..ab23cfb4 100644 --- a/tests/Response/DTO/Item/ImageTest.php +++ b/tests/Response/DTO/Item/ImageTest.php @@ -40,5 +40,12 @@ public function testPropertiesExist(): void sort($props); $this->assertEquals(self::$expectedProperties, $props); } + + public function testUploadedProperty(): void + { + $image = new Image(); + $image->uploaded = '2022-09-22T11:20:22.584072'; + $this->assertInstanceOf(\DateTime::class, $image->getUploaded()); + } } From 81c3738e07a57b940514e261ad010e99e198708f Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 08:54:51 +0100 Subject: [PATCH 09/32] TU Image --- src/Response/DTO/Item/Image.php | 2 +- tests/Response/DTO/Item/ImageTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index 9eeffe9c..f423ee52 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -54,7 +54,7 @@ public function getUploaded(): ?\DateTime try { return \DateTime::createFromFormat('Y-m-d\T H:i:s.u', $this->uploaded) ?: null; } catch (\Exception) { - return new \DateTime('now'); + return null; } } } diff --git a/tests/Response/DTO/Item/ImageTest.php b/tests/Response/DTO/Item/ImageTest.php index ab23cfb4..9d56ddd5 100644 --- a/tests/Response/DTO/Item/ImageTest.php +++ b/tests/Response/DTO/Item/ImageTest.php @@ -41,11 +41,24 @@ public function testPropertiesExist(): void $this->assertEquals(self::$expectedProperties, $props); } + public function testUploadedPropertyIsNull(): void + { + $image = new Image(); + $this->assertNull($image->getUploaded()); + } + public function testUploadedProperty(): void { $image = new Image(); $image->uploaded = '2022-09-22T11:20:22.584072'; $this->assertInstanceOf(\DateTime::class, $image->getUploaded()); } + + public function testBadUploadedProperty(): void + { + $image = new Image(); + $image->uploaded = '20aa-9-22T11:22.584072'; + $this->assertNull($image->getUploaded()); + } } From 6da29c19a54ea9b3b6239170d420507fe73b9bd1 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:08:01 +0100 Subject: [PATCH 10/32] Add TU Item Collection --- src/Response/DTO/Item/Collection.php | 12 ++++---- tests/Response/DTO/Item/CollectionTest.php | 32 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 tests/Response/DTO/Item/CollectionTest.php diff --git a/src/Response/DTO/Item/Collection.php b/src/Response/DTO/Item/Collection.php index c9462f9b..b2bd3109 100644 --- a/src/Response/DTO/Item/Collection.php +++ b/src/Response/DTO/Item/Collection.php @@ -24,21 +24,21 @@ final class Collection extends AbstractResponse implements AstrobinResponse public string $user; - public string|\DateTime $date_created; + public string|null|\DateTime $date_created = null; - public string|\DateTime $date_updated; + public string|null|\DateTime $date_updated = null; public ListImages|array|null $images = null; - public function setDateCreated(string $dateCreated): self + public function setDateCreated(?string $dateCreated): self { - $this->date_created = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateCreated); + $this->date_created = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateCreated) ?: null; return $this; } - public function setDateUpdated(string $dateUpdated): self + public function setDateUpdated(?string $dateUpdated): self { - $this->date_updated = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateUpdated); + $this->date_updated = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateUpdated) ?: null; return $this; } } diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php new file mode 100644 index 00000000..be441d0b --- /dev/null +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -0,0 +1,32 @@ +setDateUpdated(null); + $this->assertNull($collection->date_created); + + $collection->setDateCreated('aaaa-bb-ccccc'); + $this->assertNull($collection->date_created); + + $collection->setDateCreated('2022-09-22T11:20:22.584072'); + $this->assertInstanceOf(\DateTime::class, $collection->date_created); + + $collection->setDateCreated('2022-09-22'); + $this->assertInstanceOf(\DateTime::class, $collection->date_created); + } +} From 1b507456ef8ecc697d29de2d83a34bba0cf96497 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:10:29 +0100 Subject: [PATCH 11/32] Fix TU Item Collection --- tests/Response/DTO/Item/CollectionTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php index be441d0b..2173410e 100644 --- a/tests/Response/DTO/Item/CollectionTest.php +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -2,7 +2,7 @@ namespace Response\DTO\Item; -use Collection; +use AstrobinWs\Response\DTO\Item\Collection; use DG\BypassFinals; use PHPUnit\Framework\TestCase; @@ -15,9 +15,9 @@ protected function setUp(): void public function testDateCreatedProperty(): void { - $collection = new \AstrobinWs\Response\DTO\Item\Collection(); + $collection = new Collection(); - $collection->setDateUpdated(null); + $collection->setDateCreated(null); $this->assertNull($collection->date_created); $collection->setDateCreated('aaaa-bb-ccccc'); From e080960aaea76c62e1b9ded75b11efc8e2eba1b0 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:13:34 +0100 Subject: [PATCH 12/32] Add TU for Item Collection date_updated --- src/Response/DTO/Item/User.php | 1 - tests/Response/DTO/Item/CollectionTest.php | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Response/DTO/Item/User.php b/src/Response/DTO/Item/User.php index cc6bb1d0..8e1352b6 100644 --- a/src/Response/DTO/Item/User.php +++ b/src/Response/DTO/Item/User.php @@ -30,5 +30,4 @@ final class User extends AbstractResponse implements AstrobinResponse public ?string $language = null; public ?string $website = null; - } diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php index 2173410e..ec181700 100644 --- a/tests/Response/DTO/Item/CollectionTest.php +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -29,4 +29,21 @@ public function testDateCreatedProperty(): void $collection->setDateCreated('2022-09-22'); $this->assertInstanceOf(\DateTime::class, $collection->date_created); } + + public function testDateUpdatedProperty(): void + { + $collection = new Collection(); + + $collection->setDateUpdated(null); + $this->assertNull($collection->date_updated); + + $collection->setDateUpdated('aaaa-bb-ccccc'); + $this->assertNull($collection->date_updated); + + $collection->setDateUpdated('2022-09-22T11:20:22.584072'); + $this->assertInstanceOf(\DateTime::class, $collection->date_updated); + + $collection->setDateUpdated('2022-09-22'); + $this->assertInstanceOf(\DateTime::class, $collection->date_updated); + } } From e833ec32253903ea713a656897ff9c40dcf2fa4d Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:18:06 +0100 Subject: [PATCH 13/32] Fix setters for DTO Collection --- src/Response/DTO/Item/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Response/DTO/Item/Collection.php b/src/Response/DTO/Item/Collection.php index b2bd3109..01425c42 100644 --- a/src/Response/DTO/Item/Collection.php +++ b/src/Response/DTO/Item/Collection.php @@ -32,13 +32,13 @@ final class Collection extends AbstractResponse implements AstrobinResponse public function setDateCreated(?string $dateCreated): self { - $this->date_created = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateCreated) ?: null; + $this->date_created = ((is_null($dateCreated)) ? null : \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateCreated)) ?: null; return $this; } public function setDateUpdated(?string $dateUpdated): self { - $this->date_updated = \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateUpdated) ?: null; + $this->date_updated = ((is_null($dateUpdated)) ? null : \DateTime::createFromFormat(QueryFilters::DATE_FORMAT->value, $dateUpdated)) ?: null; return $this; } } From 1697fd5ac258b0c1e2fd945ad8e8437e6312e623 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:20:48 +0100 Subject: [PATCH 14/32] Change assert --- tests/Response/DTO/Item/CollectionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php index ec181700..31fbe4ce 100644 --- a/tests/Response/DTO/Item/CollectionTest.php +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -24,7 +24,7 @@ public function testDateCreatedProperty(): void $this->assertNull($collection->date_created); $collection->setDateCreated('2022-09-22T11:20:22.584072'); - $this->assertInstanceOf(\DateTime::class, $collection->date_created); + $this->assertNull($collection->date_created); $collection->setDateCreated('2022-09-22'); $this->assertInstanceOf(\DateTime::class, $collection->date_created); @@ -41,7 +41,7 @@ public function testDateUpdatedProperty(): void $this->assertNull($collection->date_updated); $collection->setDateUpdated('2022-09-22T11:20:22.584072'); - $this->assertInstanceOf(\DateTime::class, $collection->date_updated); + $this->assertNull(\DateTime::class, $collection->date_updated); $collection->setDateUpdated('2022-09-22'); $this->assertInstanceOf(\DateTime::class, $collection->date_updated); From abc3a5742855dfabfddfb9d39ead6e7162e9e32b Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:22:32 +0100 Subject: [PATCH 15/32] Fix TU syntax --- tests/Response/DTO/Item/CollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php index 31fbe4ce..a03ffdbe 100644 --- a/tests/Response/DTO/Item/CollectionTest.php +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -41,7 +41,7 @@ public function testDateUpdatedProperty(): void $this->assertNull($collection->date_updated); $collection->setDateUpdated('2022-09-22T11:20:22.584072'); - $this->assertNull(\DateTime::class, $collection->date_updated); + $this->assertNull(\DateTime::class); $collection->setDateUpdated('2022-09-22'); $this->assertInstanceOf(\DateTime::class, $collection->date_updated); From 3e598869a52797260b7286047832ce251f850e0b Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:24:09 +0100 Subject: [PATCH 16/32] im so dumb -_- --- tests/Response/DTO/Item/CollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Response/DTO/Item/CollectionTest.php b/tests/Response/DTO/Item/CollectionTest.php index a03ffdbe..f60f8c98 100644 --- a/tests/Response/DTO/Item/CollectionTest.php +++ b/tests/Response/DTO/Item/CollectionTest.php @@ -41,7 +41,7 @@ public function testDateUpdatedProperty(): void $this->assertNull($collection->date_updated); $collection->setDateUpdated('2022-09-22T11:20:22.584072'); - $this->assertNull(\DateTime::class); + $this->assertNull($collection->date_updated); $collection->setDateUpdated('2022-09-22'); $this->assertInstanceOf(\DateTime::class, $collection->date_updated); From bf381c1cff3156e24074c98b818274ba154daaa9 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:48:12 +0100 Subject: [PATCH 17/32] Add Rector in CI --- .github/workflows/php.yml | 2 ++ src/Response/DTO/Item/Image.php | 3 +++ src/Services/WsAstrobinTrait.php | 2 -- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index dd4e82f0..4b42909f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -37,6 +37,8 @@ jobs: # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" # Docs: https://getcomposer.org/doc/articles/scripts.md + - name: RectorPHP Refactoring + run: vendor/bin/rector process src - name: Run test suite env: diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index f423ee52..ddff8d16 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -30,6 +30,7 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_hd = null; public ?string $url_solution = null; + public ?string $url_advanced_solution = null; public ?string $url_histogram = null; @@ -37,9 +38,11 @@ final class Image extends AbstractResponse implements AstrobinResponse public ?string $url_skyplot = null; public ?string $url_advanced_skyplot = null; + public ?string $url_advanced_skyplot_small = null; public ?string $user = null; + public ?int $views = 0; public ?int $likes = 0; diff --git a/src/Services/WsAstrobinTrait.php b/src/Services/WsAstrobinTrait.php index 34bcb3c2..1d626e0b 100644 --- a/src/Services/WsAstrobinTrait.php +++ b/src/Services/WsAstrobinTrait.php @@ -19,7 +19,6 @@ trait WsAstrobinTrait * @throws WsException * @throws WsResponseException * @throws \JsonException - * @throws \ReflectionException */ protected function getImagesFromResource(AstrobinResponse $entity): ?AstrobinResponse { @@ -48,7 +47,6 @@ protected function getImagesFromResource(AstrobinResponse $entity): ?AstrobinRes * @throws WsException * @throws WsResponseException * @throws \JsonException - * @throws \ReflectionException */ private function getWsImage(string $imageId): ?AstrobinResponse { From ca83bad9f117f634ce1c7d407986e8fb0c31b9fb Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:53:21 +0100 Subject: [PATCH 18/32] Apply Rector on TU --- tests/Response/DTO/Item/ImageTest.php | 2 +- tests/Response/DTO/Item/TodayTest.php | 2 +- tests/Response/DTO/Item/UserTest.php | 3 ++- tests/Services/GetCollectionTest.php | 7 +++++-- tests/Services/GetImageTest.php | 27 +++++++++++++++++---------- tests/Services/GetTodayImageTest.php | 11 +++++++---- tests/Services/GetUserTest.php | 10 ++++++---- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/tests/Response/DTO/Item/ImageTest.php b/tests/Response/DTO/Item/ImageTest.php index 9d56ddd5..6631cd18 100644 --- a/tests/Response/DTO/Item/ImageTest.php +++ b/tests/Response/DTO/Item/ImageTest.php @@ -36,7 +36,7 @@ protected function setUp(): void public function testPropertiesExist(): void { $reflexion = new \ReflectionClass((new Image())); - $props = array_map(static fn(\ReflectionProperty $prop) => $prop->getName(), $reflexion->getProperties()); + $props = array_map(static fn(\ReflectionProperty $prop): string => $prop->getName(), $reflexion->getProperties()); sort($props); $this->assertEquals(self::$expectedProperties, $props); } diff --git a/tests/Response/DTO/Item/TodayTest.php b/tests/Response/DTO/Item/TodayTest.php index 51fdeebe..3804e01c 100644 --- a/tests/Response/DTO/Item/TodayTest.php +++ b/tests/Response/DTO/Item/TodayTest.php @@ -23,7 +23,7 @@ protected function setUp(): void public function testPropertiesExist(): void { $reflexion = new \ReflectionClass((new Today())); - $props = array_map(static fn(\ReflectionProperty $prop) => $prop->getName(), $reflexion->getProperties()); + $props = array_map(static fn(\ReflectionProperty $prop): string => $prop->getName(), $reflexion->getProperties()); sort($props); $this->assertEquals(self::$expectedProperties, $props); } diff --git a/tests/Response/DTO/Item/UserTest.php b/tests/Response/DTO/Item/UserTest.php index 407f2f6c..763d4c9d 100644 --- a/tests/Response/DTO/Item/UserTest.php +++ b/tests/Response/DTO/Item/UserTest.php @@ -19,6 +19,7 @@ class UserTest extends TestCase 'username', 'website' ]; + protected function setUp(): void { BypassFinals::enable(); @@ -27,7 +28,7 @@ protected function setUp(): void public function testPropertiesExist(): void { $reflexion = new \ReflectionClass((new User())); - $props = array_map(static fn(\ReflectionProperty $prop) => $prop->getName(), $reflexion->getProperties()); + $props = array_map(static fn(\ReflectionProperty $prop): string => $prop->getName(), $reflexion->getProperties()); sort($props); $this->assertEquals(self::$expectedProperties, $props); } diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index d34393ce..2e6c8e21 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -17,7 +17,7 @@ class GetCollectionTest extends TestCase public ?GetCollection $badAstrobinWs = null; - public function setUp(): void + protected function setUp(): void { $this->badAstrobinWs = new GetCollection(null, null); $astrobinKey = getenv('ASTROBIN_API_KEY'); @@ -33,6 +33,7 @@ public function testGetEndPoint(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getEndPoint'); $method->setAccessible(true); + $endPoint = $method->invoke($this->astrobinWs); $this->assertEquals(GetCollection::END_POINT, $endPoint); } @@ -42,6 +43,7 @@ public function testGetObjectEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getObjectEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(Collection::class, $response); } @@ -54,6 +56,7 @@ public function testGetCollectionEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getCollectionEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(ListCollection::class, $response); } @@ -107,7 +110,7 @@ public function testGetListCollectionByUser(): void } - public function tearDown(): void + protected function tearDown(): void { $this->astrobinWs = null; $this->badAstrobinWs = null; diff --git a/tests/Services/GetImageTest.php b/tests/Services/GetImageTest.php index a7d10fe3..de4e711f 100644 --- a/tests/Services/GetImageTest.php +++ b/tests/Services/GetImageTest.php @@ -16,12 +16,13 @@ class GetImageTest extends TestCase { public ?GetImage $astrobinWs = null; + public ?GetImage $badAstrobinWs = null; /** * @return void */ - public function setUp(): void + protected function setUp(): void { $this->badAstrobinWs = new GetImage(null, null); $astrobinKey = getenv('ASTROBIN_API_KEY'); @@ -42,7 +43,6 @@ public function testNullableKeys(): void } /** - * @return void * @throws \ReflectionException */ public function testGetEndPoint(): void @@ -50,12 +50,12 @@ public function testGetEndPoint(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getEndPoint'); $method->setAccessible(true); + $endPoint = $method->invoke($this->astrobinWs); $this->assertEquals(GetImage::END_POINT, $endPoint); } /** - * @return void * @throws \ReflectionException */ public function testGetObjectEntity(): void @@ -63,6 +63,7 @@ public function testGetObjectEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getObjectEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(Image::class, $response); } @@ -80,6 +81,12 @@ public function testGetById(): void $this->expectExceptionCode(500); $response = $this->astrobinWs->getById(null); + /** + * Test empty id and response empty + */ + $imageId = ''; + $emptyResponse = $this->astrobinWs->getById($imageId); + /** * Test with bad id */ @@ -113,7 +120,7 @@ public function testGetById(): void public function testGetImagesByUser(): void { $username = 'FalseUser'; - $badLimit = 9999999999; + $badLimit = 9_999_999_999; /** * Tests limits @@ -151,7 +158,7 @@ public function testGetImagesByDescription(): void * test bad limit */ $description = "Andromeda galaxy"; - $badLimit = 9999999; + $badLimit = 9_999_999; $badLimitResponse = $this->astrobinWs->getImagesByDescription($description, $badLimit); $this->assertNull($badLimitResponse); @@ -178,7 +185,7 @@ public function testGetImagesByTitle(): void /** * Bad limit */ - $badLimite = 9999999999; + $badLimite = 9_999_999_999; $subject = 'm42'; $nullResponse = $this->astrobinWs->getImagesByTitle($subject, $badLimite); $this->assertNull($nullResponse); @@ -202,7 +209,7 @@ public function testGetImagesByTitle(): void $subject = 'medusa'; $response = $this->astrobinWs->getImagesByTitle($subject, 1); - $this->assertStringContainsString($subject, strtolower($response->title)); + $this->assertStringContainsString($subject, strtolower((string) $response->title)); } /** @@ -221,7 +228,7 @@ public function testGetImagesByRangeDate(): void $this->assertInstanceOf(ListImages::class, $response); $this->assertLessThanOrEqual(AbstractWebService::LIMIT_MAX, $response->count); - $overLimit = AbstractWebService::LIMIT_MAX+1000000; + $overLimit = AbstractWebService::LIMIT_MAX+1_000_000; $response = $this->astrobinWs->getImagesByRangeDate($dateFromStr, $dateToStr, $overLimit); $this->assertNull($response); @@ -271,7 +278,7 @@ public function testGetImagesBySubject(): void /** * Test limit too big */ - $badLimite = 9999999999; + $badLimite = 9_999_999_999; $subject = 'm42'; $nullResponse = $this->astrobinWs->getImagesBySubject($subject, $badLimite); $this->assertNull($nullResponse); @@ -302,7 +309,7 @@ public function testGetImageBy(): void $this->assertCount(5, $response); } - public function tearDown(): void + protected function tearDown(): void { $this->astrobinWs = null; $this->badAstrobinWs = null; diff --git a/tests/Services/GetTodayImageTest.php b/tests/Services/GetTodayImageTest.php index 7ae77b28..8de4b66e 100644 --- a/tests/Services/GetTodayImageTest.php +++ b/tests/Services/GetTodayImageTest.php @@ -18,9 +18,10 @@ class GetTodayImageTest extends TestCase { public ?GetTodayImage $astrobinWs = null; + public ?GetTodayImage $badAstrobinWs = null; - public function setUp(): void + protected function setUp(): void { $this->badAstrobinWs = new GetTodayImage(null, null); $astrobinKey = getenv('ASTROBIN_API_KEY'); @@ -36,6 +37,7 @@ public function testGetEndPoint(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getEndPoint'); $method->setAccessible(true); + $endPoint = $method->invoke($this->astrobinWs); $this->assertEquals(GetTodayImage::END_POINT, $endPoint); } @@ -49,6 +51,7 @@ public function testGetObjectEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getObjectEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(Today::class, $response); } @@ -61,6 +64,7 @@ public function testGetCollectionEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getCollectionEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(ListToday::class, $response); } @@ -94,11 +98,10 @@ public function testGetDayImage(): void $now = new \DateTime('now'); $startDay = clone $now; $startDay = $startDay->sub(New \DateInterval(sprintf('P%sD', $limit-1))); + $interval = new \DateInterval('P1D'); - $listDates = array_map(static function(\DateTime $date) { - return $date->format('Y-m-d'); - }, iterator_to_array((new \DatePeriod($startDay, $interval, $limit-1))->getIterator())); + $listDates = array_map(static fn(\DateTime $date): string => $date->format('Y-m-d'), iterator_to_array((new \DatePeriod($startDay, $interval, $limit-1))->getIterator())); $response = $this->astrobinWs->getDayImage(0, $limit); $this->assertInstanceOf(ListToday::class, $response); diff --git a/tests/Services/GetUserTest.php b/tests/Services/GetUserTest.php index 19ded2c8..dd219d55 100644 --- a/tests/Services/GetUserTest.php +++ b/tests/Services/GetUserTest.php @@ -15,9 +15,10 @@ class GetUserTest extends TestCase { public ?GetUser $astrobinWs = null; + public ?GetUser $badAstrobinWs = null; - public function setUp(): void + protected function setUp(): void { $this->badAstrobinWs = new GetUser(null, null); $astrobinKey = getenv('ASTROBIN_API_KEY'); @@ -30,12 +31,12 @@ public function testGetEndPoint(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getEndPoint'); $method->setAccessible(true); + $endPoint = $method->invoke($this->astrobinWs); $this->assertEquals(GetUser::END_POINT, $endPoint); } /** - * @return void * @throws \ReflectionException */ public function testGetObjectEntity(): void @@ -43,6 +44,7 @@ public function testGetObjectEntity(): void $reflection = new \ReflectionClass($this->astrobinWs); $method = $reflection->getMethod('getObjectEntity'); $method->setAccessible(true); + $response = $method->invoke($this->astrobinWs); $this->assertEquals(User::class, $response); } @@ -94,7 +96,7 @@ public function testGetByUsername(): void * Test with limit too high */ $user = 'siovene'; - $response = $this->astrobinWs->getByUsername($user, 999999999); + $response = $this->astrobinWs->getByUsername($user, 999_999_999); $this->assertNull($response); /** @@ -106,7 +108,7 @@ public function testGetByUsername(): void $this->assertEquals($user, $response->username); } - public function tearDown(): void + protected function tearDown(): void { $this->astrobinWs = null; $this->badAstrobinWs = null; From 2f8c343170cc3109d873295f9a2e4df990bec6da Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 09:56:54 +0100 Subject: [PATCH 19/32] TU if empty response from Image --- tests/Services/GetImageTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Services/GetImageTest.php b/tests/Services/GetImageTest.php index de4e711f..ab9c01d5 100644 --- a/tests/Services/GetImageTest.php +++ b/tests/Services/GetImageTest.php @@ -86,7 +86,7 @@ public function testGetById(): void */ $imageId = ''; $emptyResponse = $this->astrobinWs->getById($imageId); - + $this->assertInstanceOf(AstrobinResponse::class, $emptyResponse, WsException::ERR_EMPTY); /** * Test with bad id */ From f0bf22bdfa3f7c1b21bbdec5922db02b983dd803 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:11:40 +0100 Subject: [PATCH 20/32] Remove comment --- src/Services/GetCollection.php | 1 - src/Services/GetImage.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Services/GetCollection.php b/src/Services/GetCollection.php index 8dbb92f8..9808a501 100644 --- a/src/Services/GetCollection.php +++ b/src/Services/GetCollection.php @@ -46,7 +46,6 @@ protected function getCollectionEntity(): string * @throws WsException * @throws WsResponseException * @throws \JsonException - * @throws \ReflectionException */ public function getById(?string $id): ?AstrobinResponse { diff --git a/src/Services/GetImage.php b/src/Services/GetImage.php index 53bab726..ec2ab8aa 100644 --- a/src/Services/GetImage.php +++ b/src/Services/GetImage.php @@ -12,7 +12,6 @@ use AstrobinWs\Response\DTO\Item\Image; use DateTime; use JsonException; -use ReflectionException; /** * Class GetImage From 513578c02773b0bc1fb8553faf8374210d75f7f4 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:12:14 +0100 Subject: [PATCH 21/32] Typo --- tests/Services/GetImageTest.php | 7 +++++-- tests/Services/GetTodayImageTest.php | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Services/GetImageTest.php b/tests/Services/GetImageTest.php index ab9c01d5..7c94fb3e 100644 --- a/tests/Services/GetImageTest.php +++ b/tests/Services/GetImageTest.php @@ -87,6 +87,7 @@ public function testGetById(): void $imageId = ''; $emptyResponse = $this->astrobinWs->getById($imageId); $this->assertInstanceOf(AstrobinResponse::class, $emptyResponse, WsException::ERR_EMPTY); + /** * Test with bad id */ @@ -152,6 +153,9 @@ public function testGetImagesByUser(): void } } + /** + * @throws \JsonException + */ public function testGetImagesByDescription(): void { /** @@ -202,7 +206,6 @@ public function testGetImagesByTitle(): void /** * Test good parameters */ - $subject = 'm51'; $response = $this->astrobinWs->getImagesByTitle($subject, 1); $this->assertInstanceOf(Image::class, $response); $this->assertStringContainsString($subject, strtolower($response->title)); @@ -213,9 +216,9 @@ public function testGetImagesByTitle(): void } /** - * @throws \ReflectionException * @throws WsResponseException * @throws WsException + * @throws \JsonException */ public function testGetImagesByRangeDate(): void { diff --git a/tests/Services/GetTodayImageTest.php b/tests/Services/GetTodayImageTest.php index 8de4b66e..bfe09597 100644 --- a/tests/Services/GetTodayImageTest.php +++ b/tests/Services/GetTodayImageTest.php @@ -106,6 +106,8 @@ public function testGetDayImage(): void $response = $this->astrobinWs->getDayImage(0, $limit); $this->assertInstanceOf(ListToday::class, $response); $this->assertCount($limit, $response->listToday); + + /** @var Today $today // $listToday = $response->getIterator(); // while ($listToday->valid()) { From 1c93f78e4b8a76e3c56f563fbe4a09c34073ca7e Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:12:40 +0100 Subject: [PATCH 22/32] Test property images in Collection instance --- tests/Services/GetCollectionTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 2e6c8e21..5cf8e219 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -8,6 +8,7 @@ use AstrobinWs\Response\DTO\Collection\ListCollection; use AstrobinWs\Response\DTO\Collection\ListImages; use AstrobinWs\Response\DTO\Item\Collection; +use AstrobinWs\Response\DTO\Item\Image; use AstrobinWs\Services\GetCollection; use PHPUnit\Framework\TestCase; @@ -93,6 +94,9 @@ public function testGetById(): void $this->assertInstanceOf(Collection::class, $reponse); $this->assertEquals($id, $response->id); $this->assertInstanceOf(ListImages::class, $response->images); + foreach ($response->images as $image) { + $this->assertInstanceOf(Image::class, $image); + } } /** From 7ae99e4e0bf401b26144cede5b4f82d4f9478c6e Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:27:35 +0100 Subject: [PATCH 23/32] Add TU images of Collection --- tests/Services/GetCollectionTest.php | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 5cf8e219..16b5cdb7 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -10,10 +10,13 @@ use AstrobinWs\Response\DTO\Item\Collection; use AstrobinWs\Response\DTO\Item\Image; use AstrobinWs\Services\GetCollection; +use AstrobinWs\Services\WsAstrobinTrait; use PHPUnit\Framework\TestCase; class GetCollectionTest extends TestCase { + use WsAstrobinTrait; + public ?GetCollection $astrobinWs = null; public ?GetCollection $badAstrobinWs = null; @@ -97,6 +100,7 @@ public function testGetById(): void foreach ($response->images as $image) { $this->assertInstanceOf(Image::class, $image); } + $this->assertIsInt($response->images->count); } /** @@ -111,7 +115,35 @@ public function testGetListCollectionByUser(): void $response = $this->astrobinWs->getListCollectionByUser('siovene', 2); $this->assertInstanceOf(AstrobinError::class, $response); + } + /** + * @throws WsException + * @throws WsResponseException + * @throws \JsonException + */ + public function testAddImagesInCollection(): void + { + $collection = new Collection(); + $collection->images = [ + "/api/v1/image/131428", + "/api/v1/image/108615", + "/api/v1/image/64901", + "/api/v1/image/63984", + "/api/v1/image/51197", + "/api/v1/image/50888", + "/api/v1/image/48807", + "/api/v1/image/48433", + "/api/v1/image/46870", + "/api/v1/image/28489", + ]; + $nbItems = count($collection->images); + + $collection = $this->getImagesFromResource($collection); + $this->assertCount($nbItems, $collection->images->count); + foreach ($collection->images as $image) { + $this->assertInstanceOf(Image::class, $image); + } } protected function tearDown(): void From 0790f6b3c2982e5b323faa04f5c62a1023ac9e9b Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:32:36 +0100 Subject: [PATCH 24/32] TU Collection --- tests/Services/GetCollectionTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 16b5cdb7..cd6f04f8 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -67,7 +67,6 @@ public function testGetCollectionEntity(): void /** * @throws WsResponseException - * @throws \ReflectionException * @throws WsException * @throws \JsonException */ @@ -79,7 +78,6 @@ public function testNullableKeys(): void } /** - * @throws \ReflectionException * @throws \JsonException * @throws WsResponseException */ @@ -104,7 +102,6 @@ public function testGetById(): void } /** - * @throws WsException * @throws \JsonException */ public function testGetListCollectionByUser(): void @@ -124,7 +121,8 @@ public function testGetListCollectionByUser(): void */ public function testAddImagesInCollection(): void { - $collection = new Collection(); + $collection = $this->astrobinWs->getById('25'); + // Override $collection->images = [ "/api/v1/image/131428", "/api/v1/image/108615", From f5d21b252905d96c0393645b16e51d9eb8b04d31 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:35:34 +0100 Subject: [PATCH 25/32] TU add images in Collection --- tests/Services/GetCollectionTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index cd6f04f8..c5c6c864 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -15,8 +15,6 @@ class GetCollectionTest extends TestCase { - use WsAstrobinTrait; - public ?GetCollection $astrobinWs = null; public ?GetCollection $badAstrobinWs = null; @@ -137,7 +135,7 @@ public function testAddImagesInCollection(): void ]; $nbItems = count($collection->images); - $collection = $this->getImagesFromResource($collection); + $collection = $this->astrobinWs->getImagesFromResource($collection); $this->assertCount($nbItems, $collection->images->count); foreach ($collection->images as $image) { $this->assertInstanceOf(Image::class, $image); From 25d34e50da40f5be60e517ab71d2e4c487a453d7 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 10:53:19 +0100 Subject: [PATCH 26/32] Test access to protected method --- tests/Services/GetCollectionTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index c5c6c864..db92a0b8 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -12,6 +12,7 @@ use AstrobinWs\Services\GetCollection; use AstrobinWs\Services\WsAstrobinTrait; use PHPUnit\Framework\TestCase; +use ReflectionMethod; class GetCollectionTest extends TestCase { @@ -116,10 +117,13 @@ public function testGetListCollectionByUser(): void * @throws WsException * @throws WsResponseException * @throws \JsonException + * @throws \ReflectionException */ public function testAddImagesInCollection(): void { $collection = $this->astrobinWs->getById('25'); + $method = new ReflectionMethod("GetCollection", "getImagesFromResource"); + $method->setAccessible(true); // Override $collection->images = [ "/api/v1/image/131428", @@ -135,7 +139,7 @@ public function testAddImagesInCollection(): void ]; $nbItems = count($collection->images); - $collection = $this->astrobinWs->getImagesFromResource($collection); + $collection = $method->invoke($collection); // $this->astrobinWs->getImagesFromResource($collection); $this->assertCount($nbItems, $collection->images->count); foreach ($collection->images as $image) { $this->assertInstanceOf(Image::class, $image); From c58b61d522ff194a26c916be1327f6014cc55d4c Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:04:23 +0100 Subject: [PATCH 27/32] Test Reflection --- tests/Services/GetCollectionTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index db92a0b8..85bfec10 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -12,6 +12,7 @@ use AstrobinWs\Services\GetCollection; use AstrobinWs\Services\WsAstrobinTrait; use PHPUnit\Framework\TestCase; +use ReflectionClass; use ReflectionMethod; class GetCollectionTest extends TestCase @@ -122,8 +123,10 @@ public function testGetListCollectionByUser(): void public function testAddImagesInCollection(): void { $collection = $this->astrobinWs->getById('25'); - $method = new ReflectionMethod("GetCollection", "getImagesFromResource"); - $method->setAccessible(true); + $reflectionClass = new ReflectionClass($collection::class); + $reflectionMethod = $reflectionClass->getMethod('getImagesFromResource'); + $reflectionMethod->setAccessible(true); + // Override $collection->images = [ "/api/v1/image/131428", @@ -139,7 +142,7 @@ public function testAddImagesInCollection(): void ]; $nbItems = count($collection->images); - $collection = $method->invoke($collection); // $this->astrobinWs->getImagesFromResource($collection); + $collection = $reflectionMethod->invoke($collection); // $this->astrobinWs->getImagesFromResource($collection); $this->assertCount($nbItems, $collection->images->count); foreach ($collection->images as $image) { $this->assertInstanceOf(Image::class, $image); From 8f1228e3907a64603f293b9e6cd49de999af51bb Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:09:18 +0100 Subject: [PATCH 28/32] Fix $reflectionMethod --- tests/Services/GetCollectionTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 85bfec10..7e1a403d 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -123,7 +123,7 @@ public function testGetListCollectionByUser(): void public function testAddImagesInCollection(): void { $collection = $this->astrobinWs->getById('25'); - $reflectionClass = new ReflectionClass($collection::class); + $reflectionClass = new ReflectionClass(GetCollection::class); $reflectionMethod = $reflectionClass->getMethod('getImagesFromResource'); $reflectionMethod->setAccessible(true); @@ -142,7 +142,7 @@ public function testAddImagesInCollection(): void ]; $nbItems = count($collection->images); - $collection = $reflectionMethod->invoke($collection); // $this->astrobinWs->getImagesFromResource($collection); + $collection = $reflectionMethod->invoke($this->astrobinWs, $collection); // $this->astrobinWs->getImagesFromResource($collection); $this->assertCount($nbItems, $collection->images->count); foreach ($collection->images as $image) { $this->assertInstanceOf(Image::class, $image); From 2b4322c10227c1973905203d6167c4b923ec3fd7 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:12:06 +0100 Subject: [PATCH 29/32] Fix assert count images of collection --- tests/Services/GetCollectionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 7e1a403d..fe6c446c 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -143,7 +143,7 @@ public function testAddImagesInCollection(): void $nbItems = count($collection->images); $collection = $reflectionMethod->invoke($this->astrobinWs, $collection); // $this->astrobinWs->getImagesFromResource($collection); - $this->assertCount($nbItems, $collection->images->count); + $this->assertCount($nbItems, $collection->images); foreach ($collection->images as $image) { $this->assertInstanceOf(Image::class, $image); } From c83e98a44230eda0f8c8cdeffd7c91bdc423bfc5 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:48:27 +0100 Subject: [PATCH 30/32] Fix TU test uploaded property --- src/Filters/CollectionFilters.php | 2 +- src/Response/DTO/Item/Image.php | 9 ++------- src/Services/GetCollection.php | 1 - src/test.php | 5 +++-- tests/Filters/CollectionFiltersTest.php | 3 ++- tests/Services/GetCollectionTest.php | 1 + tests/Services/GetImageTest.php | 1 + 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Filters/CollectionFilters.php b/src/Filters/CollectionFilters.php index 23e834f9..11c58d67 100644 --- a/src/Filters/CollectionFilters.php +++ b/src/Filters/CollectionFilters.php @@ -12,5 +12,5 @@ enum CollectionFilters: string { use EnumToArray; - case USER_FILTER = 'user'; + case USER_FILTER = 'username'; } diff --git a/src/Response/DTO/Item/Image.php b/src/Response/DTO/Item/Image.php index ddff8d16..36c94bbb 100644 --- a/src/Response/DTO/Item/Image.php +++ b/src/Response/DTO/Item/Image.php @@ -50,14 +50,9 @@ final class Image extends AbstractResponse implements AstrobinResponse public function getUploaded(): ?\DateTime { - if (is_null($this->uploaded)) { - return null; - } - - try { - return \DateTime::createFromFormat('Y-m-d\T H:i:s.u', $this->uploaded) ?: null; - } catch (\Exception) { + if (!is_string($this->uploaded)) { return null; } + return \DateTime::createFromFormat('Y-m-d\T H:i:s.u', $this->uploaded) ?: null; } } diff --git a/src/Services/GetCollection.php b/src/Services/GetCollection.php index 9808a501..14609de2 100644 --- a/src/Services/GetCollection.php +++ b/src/Services/GetCollection.php @@ -58,7 +58,6 @@ public function getById(?string $id): ?AstrobinResponse } /** - * @deprecated * Request by "user" attribute is not allowed anymore * @return ListCollection|null * @throws \JsonException diff --git a/src/test.php b/src/test.php index 1bfea0a3..c38266f7 100644 --- a/src/test.php +++ b/src/test.php @@ -30,8 +30,9 @@ $astrobinWs = new \AstrobinWs\Services\GetCollection($astrobinApiKey, $astrobinApiSecret); try { - $response = $astrobinWs->getListCollectionByUser('siovene', 1); - var_dump($response); + $response = $astrobinWs->getById('25'); + + var_dump($response->images->count); } catch (\AstrobinWs\Exceptions\WsException|JsonException) { } diff --git a/tests/Filters/CollectionFiltersTest.php b/tests/Filters/CollectionFiltersTest.php index 6915ae33..0c38cb07 100644 --- a/tests/Filters/CollectionFiltersTest.php +++ b/tests/Filters/CollectionFiltersTest.php @@ -16,12 +16,13 @@ public function testEnumsAsArray(): void $randomString = bin2hex(random_bytes(10)); $enumValues = CollectionFilters::toArray(); $this->assertNotContains($randomString, $enumValues); + $this->assertNotContains('user', $enumValues); $this->assertNotContains('users', $enumValues); $this->assertNotContains('u', $enumValues); } public function testEnumValues(): void { - $this->assertEquals('user', CollectionFilters::USER_FILTER->value); + $this->assertEquals('username', CollectionFilters::USER_FILTER->value); } } diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index fe6c446c..5937c42e 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -149,6 +149,7 @@ public function testAddImagesInCollection(): void } } + protected function tearDown(): void { $this->astrobinWs = null; diff --git a/tests/Services/GetImageTest.php b/tests/Services/GetImageTest.php index 7c94fb3e..8d617eb8 100644 --- a/tests/Services/GetImageTest.php +++ b/tests/Services/GetImageTest.php @@ -117,6 +117,7 @@ public function testGetById(): void } /** + * @throws \JsonException */ public function testGetImagesByUser(): void { From 5d320dff861567c830e394a2f61ed8ce6c2b7f57 Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:51:09 +0100 Subject: [PATCH 31/32] Fix TU --- tests/Services/GetCollectionTest.php | 3 ++- tests/Services/GetImageTest.php | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 5937c42e..08fe1fad 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -102,6 +102,7 @@ public function testGetById(): void } /** + * NB : filter on field "user" is not longer supported * @throws \JsonException */ public function testGetListCollectionByUser(): void @@ -111,7 +112,7 @@ public function testGetListCollectionByUser(): void $this->assertNull($response); $response = $this->astrobinWs->getListCollectionByUser('siovene', 2); - $this->assertInstanceOf(AstrobinError::class, $response); + $this->assertInstanceOf(ListCollection::class, $response); } /** diff --git a/tests/Services/GetImageTest.php b/tests/Services/GetImageTest.php index 8d617eb8..e037a5d6 100644 --- a/tests/Services/GetImageTest.php +++ b/tests/Services/GetImageTest.php @@ -304,6 +304,9 @@ public function testGetImagesBySubject(): void $this->assertInstanceOf(Image::class, $goodResponse); } + /** + * @throws \JsonException + */ public function testGetImageBy(): void { $response = $this->astrobinWs->getImageBy([], 9999); From 5b3f1dcff72e1f34cbfd1b985700160bcd45e7ce Mon Sep 17 00:00:00 2001 From: Stephane MEAUDRE Date: Thu, 9 Nov 2023 11:57:54 +0100 Subject: [PATCH 32/32] Add coverage in ListCollection --- tests/Services/GetCollectionTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Services/GetCollectionTest.php b/tests/Services/GetCollectionTest.php index 08fe1fad..3a807ba9 100644 --- a/tests/Services/GetCollectionTest.php +++ b/tests/Services/GetCollectionTest.php @@ -9,6 +9,7 @@ use AstrobinWs\Response\DTO\Collection\ListImages; use AstrobinWs\Response\DTO\Item\Collection; use AstrobinWs\Response\DTO\Item\Image; +use AstrobinWs\Response\Iterators\CollectionIterator; use AstrobinWs\Services\GetCollection; use AstrobinWs\Services\WsAstrobinTrait; use PHPUnit\Framework\TestCase; @@ -113,6 +114,9 @@ public function testGetListCollectionByUser(): void $response = $this->astrobinWs->getListCollectionByUser('siovene', 2); $this->assertInstanceOf(ListCollection::class, $response); + $this->assertIsIterable($response->listCollection); + $this->assertInstanceOf(CollectionIterator::class, $response->getIterator()); + } /**