From 9df0bbc935e267635236d845e0de03907bf2e252 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 14 Jan 2025 14:17:36 +0100 Subject: [PATCH 1/3] fix: Deprecations for PHP 8.4 - Add tests for PHP 8.4 - fix test error for PHP 8.4 - moved the docker files to a dedicated folder - added some comments to other files Signed-off-by: Avior --- Dockerfile => .docker/Dockerfile | 4 ++-- .docker/docker-compose.yml | 9 ++++++++ .docker/php.ini | 9 ++++++++ .github/workflows/build-test.yml | 3 +-- docker-compose.yml | 9 -------- phpunit.xml | 12 +++++----- src/Endpoints/Endpoint.php | 8 ++++++- src/Model/Serie.php | 5 +++++ src/Model/Set.php | 31 +++++++++++++++++++++++--- src/Model/SubModel/Abbreviation.php | 11 +++++++++ src/Model/SubModel/CardCount.php | 12 ++++++++++ src/Model/SubModel/CardCountResume.php | 7 ++++++ src/Model/SubModel/Legal.php | 6 +++++ tests/TCGdexDeprecatedTest.php | 2 +- tests/TCGdexTest.php | 2 +- 15 files changed, 105 insertions(+), 25 deletions(-) rename Dockerfile => .docker/Dockerfile (90%) create mode 100644 .docker/docker-compose.yml create mode 100644 .docker/php.ini delete mode 100644 docker-compose.yml create mode 100644 src/Model/SubModel/Abbreviation.php diff --git a/Dockerfile b/.docker/Dockerfile similarity index 90% rename from Dockerfile rename to .docker/Dockerfile index 922c567..a2f832d 100644 --- a/Dockerfile +++ b/.docker/Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1 +FROM php:8.4 WORKDIR /usr/src/app @@ -15,7 +15,7 @@ RUN apt-get update \ # && docker-php-ext-install pdo mysqli pdo_mysql zip intl gd # Copy the PHP config -# COPY php.ini /usr/local/etc/php/php.ini +COPY php.ini /usr/local/etc/php/php.ini # Copy composer COPY --from=composer:2 /usr/bin/composer /usr/bin/composer diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 0000000..3296e2c --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,9 @@ + +# docker-compose -f .docker/docker-compose.yml run --build dev /bin/bash +services: + dev: + build: . + stdin_open: true + tty: true + volumes: + - ..:/usr/src/app diff --git a/.docker/php.ini b/.docker/php.ini new file mode 100644 index 0000000..ecccdc0 --- /dev/null +++ b/.docker/php.ini @@ -0,0 +1,9 @@ +memory_limit = -1 +post_max_size = 100M +upload_max_filesize = 20M +max_execution_time = 0 +date.timezone = "Europe/Paris" +max_input_vars = 5000 +pcre.backtrack_limit = 10000000 +display_errors = On +error_reporting = E_ALL | E_DEPRECATED | E_NOTICE diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b369872..d273c0e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -8,12 +8,11 @@ on: jobs: build: - runs-on: ubuntu-latest strategy: matrix: # follows https://www.php.net/supported-versions.php - php-versions: ['8.1', '8.2', '8.3'] + php-versions: ['8.1', '8.2', '8.3', '8.4'] phpunit-versions: ['latest'] steps: diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 8ecdd50..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,9 +0,0 @@ - -# docker-compose run --build dev /bin/bash -services: - dev: - build: . - stdin_open: true - tty: true - volumes: - - .:/usr/src/app diff --git a/phpunit.xml b/phpunit.xml index 56793b8..8d6f0e7 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -3,24 +3,22 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="true" - backupStaticAttributes="false" bootstrap="vendor/autoload.php" cacheResult="false" colors="true" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - forceCoversAnnotation="false" processIsolation="false" stopOnError="true" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerErrors="true" + displayDetailsOnTestsThatTriggerNotices="true" + displayDetailsOnTestsThatTriggerWarnings="true" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" - verbose="false" > @@ -35,5 +33,7 @@ ./tests/ + + diff --git a/src/Endpoints/Endpoint.php b/src/Endpoints/Endpoint.php index ae53b4d..b7e6bb0 100644 --- a/src/Endpoints/Endpoint.php +++ b/src/Endpoints/Endpoint.php @@ -25,11 +25,17 @@ public function __construct( } /** - * @return Item + * @return Item|null */ public function get(string|int $id) { $res = $this->tcgdex->fetch($this->endpoint, $id); + + // handle case where result is not defined or an error + if (is_null($res)) { + return null; + } + return Model::build(new $this->itemModel($this->tcgdex), $res); } diff --git a/src/Model/Serie.php b/src/Model/Serie.php index 55820d9..61ebeaf 100644 --- a/src/Model/Serie.php +++ b/src/Model/Serie.php @@ -9,6 +9,9 @@ class Serie extends SerieResume */ public array $sets = []; + public ?SetResume $firstSet = null; + public ?SetResume $lastSet = null; + protected function fill(object $data): void { foreach ($data as $key => $value) { @@ -16,6 +19,8 @@ protected function fill(object $data): void $this->sets = array_map(function ($item) { return Model::build(new SetResume($this->sdk), $item); }, $value); + } elseif ($key === 'firstSet' || $key === 'lastSet') { + $this->{$key} = Model::build(new SetResume($this->sdk), $value); } else { $this->{$key} = $value; } diff --git a/src/Model/Set.php b/src/Model/Set.php index 83f98ba..859d338 100644 --- a/src/Model/Set.php +++ b/src/Model/Set.php @@ -5,25 +5,50 @@ use TCGdex\Model\SubModel\CardCount; use TCGdex\Model\SubModel\Variants; use TCGdex\Model\SubModel\Legal; - +use TCGdex\Model\SubModel\Abbreviation; class Set extends SetResume { + /** + * the serie the set is part of + */ public SerieResume $serie; + /** + * the TCG Online ID + */ public ?string $tcgOnline = null; + /** + * @deprecated this variable is inexistant in the API + */ public ?Variants $variants = null; + /** + * the set release date as an ISO8601 string (ex: `2020-02-01`) + */ public string $releaseDate = ''; + /** + * Designate if the set is usable in tournaments + * + * Note: this is specific to the set and if a + * card is banned from the set it will still be true + */ public Legal $legal; /** + * the number of cards of the set in total & by variant * @var CardCount */ public $cardCount; /** + * The official and localized abbreviation used by TPC + */ + public Abbreviation $abbreviation; + + /** + * the list of cards of the set * @var CardResume[] */ public array $cards = []; @@ -35,8 +60,8 @@ protected function fill(object $data): void $this->cardCount = Model::build(new CardCount($this->sdk), $value); } elseif ($key === 'serie') { $this->serie = Model::build(new SerieResume($this->sdk), $value); - } elseif ($key === 'variants') { - $this->variants = Model::build(new Variants($this->sdk), $value); + } elseif ($key === 'abbreviation') { + $this->abbreviation = Model::build(new Abbreviation($this->sdk), $value); } elseif ($key === 'legal') { $this->legal = Model::build(new Legal($this->sdk), $value); } elseif ($key === 'cards') { diff --git a/src/Model/SubModel/Abbreviation.php b/src/Model/SubModel/Abbreviation.php new file mode 100644 index 0000000..e6746e7 --- /dev/null +++ b/src/Model/SubModel/Abbreviation.php @@ -0,0 +1,11 @@ +fetchCard('testCanRequest'); $this->assertNotEmpty($card); diff --git a/tests/TCGdexTest.php b/tests/TCGdexTest.php index afa8ada..c65b856 100644 --- a/tests/TCGdexTest.php +++ b/tests/TCGdexTest.php @@ -13,7 +13,7 @@ final class TCGdexTest extends TestCase public function testCanRequest(): void { - TCGdex::$client = new Psr18Mock("{\"ok\": true}"); + TCGdex::$client = new Psr18Mock("{\"id\": \"swsh1-136\"}"); $tcgdex = new TCGdex("en"); $card = $tcgdex->card->get('testCanRequest'); $this->assertNotEmpty($card); From 6f01ddc6602189a728f52aff6feb33269116e6e3 Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 14 Jan 2025 15:05:03 +0100 Subject: [PATCH 2/3] fix: codesniffer errors Signed-off-by: Avior --- src/Model/Set.php | 1 + src/Model/SubModel/CardCountResume.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Set.php b/src/Model/Set.php index 859d338..f691334 100644 --- a/src/Model/Set.php +++ b/src/Model/Set.php @@ -6,6 +6,7 @@ use TCGdex\Model\SubModel\Variants; use TCGdex\Model\SubModel\Legal; use TCGdex\Model\SubModel\Abbreviation; + class Set extends SetResume { /** diff --git a/src/Model/SubModel/CardCountResume.php b/src/Model/SubModel/CardCountResume.php index 52e81ad..82d2429 100644 --- a/src/Model/SubModel/CardCountResume.php +++ b/src/Model/SubModel/CardCountResume.php @@ -6,7 +6,6 @@ class CardCountResume extends Model { - /** * total of number of cards */ From 892a53a4406184c8da77b37a970d1cf926abaa8a Mon Sep 17 00:00:00 2001 From: Avior Date: Tue, 14 Jan 2025 15:12:20 +0100 Subject: [PATCH 3/3] chore: formatting Signed-off-by: Avior --- .docker/docker-compose.yml | 2 +- .docker/php.ini | 7 ------- phpunit.xml | 2 -- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml index 3296e2c..91cd214 100644 --- a/.docker/docker-compose.yml +++ b/.docker/docker-compose.yml @@ -1,4 +1,4 @@ - +# Command to run from the project root : # docker-compose -f .docker/docker-compose.yml run --build dev /bin/bash services: dev: diff --git a/.docker/php.ini b/.docker/php.ini index ecccdc0..dad19be 100644 --- a/.docker/php.ini +++ b/.docker/php.ini @@ -1,9 +1,2 @@ -memory_limit = -1 -post_max_size = 100M -upload_max_filesize = 20M -max_execution_time = 0 -date.timezone = "Europe/Paris" -max_input_vars = 5000 -pcre.backtrack_limit = 10000000 display_errors = On error_reporting = E_ALL | E_DEPRECATED | E_NOTICE diff --git a/phpunit.xml b/phpunit.xml index 8d6f0e7..9efad7a 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -33,7 +33,5 @@ ./tests/ - -