From 4de6a3b798428142e78527dbf4a5df9b2b3f46a6 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Mon, 11 Mar 2024 18:18:01 +0300 Subject: [PATCH] fix contracts support --- .../Serializer/ArraySupportDecorator.php | 7 +++---- tests/bootstrap.php | 5 ++++- tests/src/ResourceGroup/CustomersTest.php | 17 +++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Component/Serializer/ArraySupportDecorator.php b/src/Component/Serializer/ArraySupportDecorator.php index 0e97d0e..e94de20 100644 --- a/src/Component/Serializer/ArraySupportDecorator.php +++ b/src/Component/Serializer/ArraySupportDecorator.php @@ -24,8 +24,7 @@ use Pnz\JsonException\Json; */ class ArraySupportDecorator implements SerializerInterface { - /** @var \Liip\Serializer\SerializerInterface */ - private $serializer; + private SerializerInterface $serializer; /** * ArraySupportDecorator constructor. @@ -69,7 +68,7 @@ class ArraySupportDecorator implements SerializerInterface /** * @inheritDoc */ - public function deserialize(string $data, string $type, string $format, ?Context $context = null) + public function deserialize(string $data, string $type, string $format, ?Context $context = null): mixed { if ('json' !== $format) { throw new UnsupportedFormatException('Liip serializer only supports JSON for now'); @@ -109,7 +108,7 @@ class ArraySupportDecorator implements SerializerInterface * * @return array|object */ - public function fromArray(array $data, string $type, ?Context $context = null) + public function fromArray(array $data, string $type, ?Context $context = null): mixed { if (static::isArrayType($type)) { return $this->decodeArray($data, $type, $context); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 771a104..e2fe6ef 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -18,7 +18,10 @@ if (!is_file($autoloadFile = __DIR__ . '/../vendor/autoload.php')) { $loader = require $autoloadFile; $loader->add('RetailCrm\\TestUtils', __DIR__ . '/tests/utils'); $loader->add('RetailCrm\\Tests', __DIR__ . '/src'); -AnnotationRegistry::registerLoader('class_exists'); + +if (method_exists(AnnotationRegistry::class, 'registerLoader')) { + AnnotationRegistry::registerLoader('class_exists'); +} if (file_exists(__DIR__ . '/../.env')) { $dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/..'); diff --git a/tests/src/ResourceGroup/CustomersTest.php b/tests/src/ResourceGroup/CustomersTest.php index 3b99ed9..bf1691e 100644 --- a/tests/src/ResourceGroup/CustomersTest.php +++ b/tests/src/ResourceGroup/CustomersTest.php @@ -2698,14 +2698,15 @@ EOF; $response = $client->customers->get(4770, $request); self::assertModelsCallback($json, $response, static function ($expected, $actual) { - $actualTags = $actual['customer']['tags']; - $actual['customer']['tags'] = array_filter( - array_map(static function ($tag) use ($actualTags) { - if (in_array($tag['name'], $actualTags, true)) { - return $tag; - } - }, $expected['customer']['tags']) - ); + // TODO: Check if it's really necessary to do tag conversion here. Maybe underlying serializer is broken. +// $actualTags = $actual['customer']['tags']; +// $actual['customer']['tags'] = array_filter( +// array_map(static function ($tag) use ($actualTags) { +// if (in_array($tag['name'], $actualTags, true)) { +// return $tag; +// } +// }, $expected['customer']['tags']) +// ); $expected['customer']['marginSumm'] = (float)$expected['customer']['marginSumm']; $expected['customer']['totalSumm'] = (float)$expected['customer']['totalSumm'];