From f2b3fdc97eea50be8f7b53eb6a1b8c385150e819 Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Wed, 21 May 2025 16:20:45 +0300 Subject: [PATCH 1/3] New property combinedTo for ErrorResponse --- src/Exception/Api/NotFoundException.php | 20 ++++++++++++++++++++ src/Factory/ApiExceptionFactory.php | 2 ++ src/Model/Response/ErrorResponse.php | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 src/Exception/Api/NotFoundException.php diff --git a/src/Exception/Api/NotFoundException.php b/src/Exception/Api/NotFoundException.php new file mode 100644 index 000000000..7ad5e8d0d --- /dev/null +++ b/src/Exception/Api/NotFoundException.php @@ -0,0 +1,20 @@ +getErrorResponse()->combinedTo; + } +} diff --git a/src/Factory/ApiExceptionFactory.php b/src/Factory/ApiExceptionFactory.php index 56b056233..a8b484e55 100644 --- a/src/Factory/ApiExceptionFactory.php +++ b/src/Factory/ApiExceptionFactory.php @@ -15,6 +15,7 @@ use RetailCrm\Api\Exception\Api\InvalidCredentialsException; use RetailCrm\Api\Exception\Api\MissingCredentialsException; use RetailCrm\Api\Exception\Api\MissingParameterException; +use RetailCrm\Api\Exception\Api\NotFoundException; use RetailCrm\Api\Exception\Api\ValidationException; use RetailCrm\Api\Exception\ApiException; use RetailCrm\Api\Interfaces\ResponseInterface; @@ -37,6 +38,7 @@ class ApiExceptionFactory 'Account does not exist.' => AccountDoesNotExistException::class, 'Errors in the entity format' => ValidationException::class, 'Validation error' => ValidationException::class, + 'Not found' => NotFoundException::class, ]; /** diff --git a/src/Model/Response/ErrorResponse.php b/src/Model/Response/ErrorResponse.php index bc0a18f5c..9bfd9c2a2 100644 --- a/src/Model/Response/ErrorResponse.php +++ b/src/Model/Response/ErrorResponse.php @@ -42,4 +42,12 @@ public function __construct() * @JMS\SerializedName("errorMsg") */ public $errorMsg; + + /** + * @var \RetailCrm\Api\Model\Entity\Customers\Customer + * + * @JMS\Type("RetailCrm\Api\Model\Entity\Customers\Customer") + * @JMS\SerializedName("combinedTo") + */ + public $combinedTo; } From b32e520671e01d6175e4257b8014182e6afe8a7c Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Wed, 21 May 2025 16:32:39 +0300 Subject: [PATCH 2/3] added test --- tests/src/Factory/ApiExceptionFactoryTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/src/Factory/ApiExceptionFactoryTest.php b/tests/src/Factory/ApiExceptionFactoryTest.php index e0481d8db..4634a70de 100644 --- a/tests/src/Factory/ApiExceptionFactoryTest.php +++ b/tests/src/Factory/ApiExceptionFactoryTest.php @@ -13,6 +13,7 @@ use RetailCrm\Api\Exception\Api\ApiErrorException; use RetailCrm\Api\Exception\Api\MissingCredentialsException; use RetailCrm\Api\Exception\Api\MissingParameterException; +use RetailCrm\Api\Exception\Api\NotFoundException; use RetailCrm\Api\Exception\Api\ValidationException; use RetailCrm\Api\Factory\ApiExceptionFactory; use RetailCrm\Api\Model\Response\ErrorResponse; @@ -126,4 +127,20 @@ public function testValidationError(): void self::assertFalse($exception->getErrorResponse()->success); self::assertStringContainsString($exception->getMessage(), (string) $exception); } + + public function testNotFoundError(): void + { + $response = new ErrorResponse(); + $response->errorMsg = "Not found"; + $response->errors = []; + + $exception = $this->factory->createException($response, 400); + + self::assertInstanceOf(NotFoundException::class, $exception); + self::assertEquals(400, $exception->getCode()); + self::assertEquals(400, $exception->getStatusCode()); + self::assertEquals($response->errorMsg, $exception->getErrorResponse()->errorMsg); + self::assertFalse($exception->getErrorResponse()->success); + self::assertStringContainsString($exception->getMessage(), (string) $exception); + } } From 26d3f70a4704025b940e40754a89535366024d8a Mon Sep 17 00:00:00 2001 From: Vladimir Kolchin Date: Wed, 21 May 2025 16:37:19 +0300 Subject: [PATCH 3/3] improved test --- tests/src/Factory/ApiExceptionFactoryTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/src/Factory/ApiExceptionFactoryTest.php b/tests/src/Factory/ApiExceptionFactoryTest.php index 4634a70de..de55477b7 100644 --- a/tests/src/Factory/ApiExceptionFactoryTest.php +++ b/tests/src/Factory/ApiExceptionFactoryTest.php @@ -16,6 +16,7 @@ use RetailCrm\Api\Exception\Api\NotFoundException; use RetailCrm\Api\Exception\Api\ValidationException; use RetailCrm\Api\Factory\ApiExceptionFactory; +use RetailCrm\Api\Model\Entity\Customers\Customer; use RetailCrm\Api\Model\Response\ErrorResponse; use RetailCrm\Api\Model\Response\SuccessResponse; use RetailCrm\TestUtils\TestCase\AbstractApiResourceGroupTestCase; @@ -133,6 +134,8 @@ public function testNotFoundError(): void $response = new ErrorResponse(); $response->errorMsg = "Not found"; $response->errors = []; + $response->combinedTo = new Customer(); + $response->combinedTo->id = 1; $exception = $this->factory->createException($response, 400); @@ -142,5 +145,7 @@ public function testNotFoundError(): void self::assertEquals($response->errorMsg, $exception->getErrorResponse()->errorMsg); self::assertFalse($exception->getErrorResponse()->success); self::assertStringContainsString($exception->getMessage(), (string) $exception); + self::assertInstanceOf(Customer::class, $exception->getCombinedTo()); + self::assertEquals(1, $exception->getCombinedTo()->id); } }