From 1135c918bc388390e2f450b81acf55dcf47f059f Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Fri, 9 Feb 2024 15:26:08 +0100 Subject: [PATCH 01/11] add category level attribute api support --- README.md | 3 +- src/Endpoint/CategoryEndpoint.php | 24 +++++++++++++ src/Factory/CategoryFactory.php | 40 +++++++++++++++++++-- src/Model/CategoryAttribute.php | 2 +- src/Model/CategoryLevelAttribute.php | 14 ++++++++ src/Model/CategoryLevelAttributeRequest.php | 27 ++++++++++++++ src/Model/CategoryLevelAttributeValue.php | 12 +++++++ tests/Endpoint/CategoryEndpointTest.php | 28 +++++++++++++++ 8 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 src/Model/CategoryLevelAttribute.php create mode 100644 src/Model/CategoryLevelAttributeRequest.php create mode 100644 src/Model/CategoryLevelAttributeValue.php diff --git a/README.md b/README.md index bffc6dd..575670f 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,8 @@ facade │ └─ new - Obtain new session token ├─ category/ - Category endpoint │ ├─ get - Get product listing category -│ └─ getAttributes - Get system-defined attributes based on category ID +│ ├─ getAttributes - Get system-defined attributes based on category ID +│ └─ getLevelAttribute - Get next-level attribute based on category, attribute and value ID (e.g. car_model values) └─ product/ - Product endpoint └─ getGroup - Get product group ``` diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 37216ad..4def8db 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -8,6 +8,8 @@ use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; +use Kyto\Alibaba\Model\CategoryLevelAttribute; +use Kyto\Alibaba\Model\CategoryLevelAttributeRequest; class CategoryEndpoint { @@ -68,4 +70,26 @@ public function getAttributes(string $categoryId): array return $result; } + + /** + * Get next-level attribute based on category, attribute and optionally level attribute value ID. + * @link https://developer.alibaba.com/en/doc.htm?spm=a2728.12183079.k2mwm9fd.1.4b3630901WuQWY#?docType=2&docId=48659 + * + * @param ?string $valueId provide null to fetch first level + */ + public function getLevelAttribute(string $categoryId, string $attributeId, ?string $valueId = null): CategoryLevelAttribute + { + $attributeValueRequest = new CategoryLevelAttributeRequest(); + $attributeValueRequest->categoryId = $categoryId; + $attributeValueRequest->attributeId = $attributeId; + $attributeValueRequest->valueId = $valueId ?? '0'; + + $data = $this->client->request([ + 'method' => 'alibaba.icbu.category.level.attr.get', + 'attribute_value_request' => json_encode($attributeValueRequest) + ]); + + $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list']; + return $this->categoryFactory->createLevelAttribute($attribute); + } } diff --git a/src/Factory/CategoryFactory.php b/src/Factory/CategoryFactory.php index 37a3161..e8c001c 100644 --- a/src/Factory/CategoryFactory.php +++ b/src/Factory/CategoryFactory.php @@ -4,6 +4,8 @@ namespace Kyto\Alibaba\Factory; +use Kyto\Alibaba\Model\CategoryLevelAttribute; +use Kyto\Alibaba\Model\CategoryLevelAttributeValue; use Kyto\Alibaba\Util\Formatter; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; @@ -15,7 +17,7 @@ class CategoryFactory { /** - * @param mixed[] $data + * @param array $data */ public function createCategory(array $data): Category { @@ -34,7 +36,7 @@ public function createCategory(array $data): Category } /** - * @param mixed[] $data + * @param array $data */ public function createAttribute(array $data): CategoryAttribute { @@ -64,7 +66,7 @@ public function createAttribute(array $data): CategoryAttribute } /** - * @param mixed[] $data + * @param array $data */ public function createAttributeValue(array $data): CategoryAttributeValue { @@ -77,4 +79,36 @@ public function createAttributeValue(array $data): CategoryAttributeValue return $model; } + + /** + * @param array $data + */ + public function createLevelAttribute(array $data): CategoryLevelAttribute + { + $model = new CategoryLevelAttribute(); + + $model->id = (string) $data['property_id']; + $model->name = (string) $data['property_en_name']; + + $model->values = []; + $decodedValues = json_decode($data['values'], true); + foreach ($decodedValues as $value) { + $model->values[] = $this->createLevelAttributeValue($value); + } + + return $model; + } + + /** + * @param array $data + */ + public function createLevelAttributeValue(array $data): CategoryLevelAttributeValue + { + $model = new CategoryLevelAttributeValue(); + $model->name = (string) $data['name']; + $model->id = (string) $data['id']; + $model->isLeaf = isset($data['leaf']); + + return $model; + } } diff --git a/src/Model/CategoryAttribute.php b/src/Model/CategoryAttribute.php index d0153ec..f79e2c7 100644 --- a/src/Model/CategoryAttribute.php +++ b/src/Model/CategoryAttribute.php @@ -12,7 +12,7 @@ class CategoryAttribute // TODO: change to enums once all values would be known public string $inputType; // Known values: single_select, multi_select, input - public string $showType; // Known values: list_box (single_select), check_box (multi_select), input (input) + public string $showType; // Known values: list_box (single_select), check_box (multi_select), input (input), group_table (single_select) public string $valueType; // Known values: string, number public bool $isSku; diff --git a/src/Model/CategoryLevelAttribute.php b/src/Model/CategoryLevelAttribute.php new file mode 100644 index 0000000..b497f16 --- /dev/null +++ b/src/Model/CategoryLevelAttribute.php @@ -0,0 +1,14 @@ + + */ + public function jsonSerialize(): array + { + return [ + 'cat_id' => $this->categoryId, + 'attr_id' => $this->attributeId, + 'value_id' => $this->valueId + ]; + } +} diff --git a/src/Model/CategoryLevelAttributeValue.php b/src/Model/CategoryLevelAttributeValue.php new file mode 100644 index 0000000..b2e5b11 --- /dev/null +++ b/src/Model/CategoryLevelAttributeValue.php @@ -0,0 +1,12 @@ +categoryEndpoint->getAttributes($id); self::assertSame($result, $actual); } + + public function testGetLevelAttributes(): void + { + $attributeValueRequestBody = '{"cat_id":"1","attr_id":"1","value_id":"0"}'; + $levelAttribute = ['LevelAttribute']; + $data = ['alibaba_icbu_category_level_attr_get_response' => ['result_list' => $levelAttribute]]; + + $this->client + ->expects(self::once()) + ->method('request') + ->with([ + 'method' => 'alibaba.icbu.category.level.attr.get', + 'attribute_value_request' => $attributeValueRequestBody, + ]) + ->willReturn($data); + + $result = new CategoryLevelAttribute(); + + $this->categoryFactory + ->expects(self::once()) + ->method('createLevelAttribute') + ->willReturn($result); + + $actual = $this->categoryEndpoint->getLevelAttribute('1', '1', null); + self::assertSame($result, $actual); + } } From 6ad7ef899bbd4c933b6f040ca96e571ff42fde90 Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Fri, 9 Feb 2024 15:45:48 +0100 Subject: [PATCH 02/11] make alibaba exception accept nullable subMessage and subCode --- src/Endpoint/CategoryEndpoint.php | 7 +++++-- src/Exception/AlibabaException.php | 4 ++-- src/Factory/CategoryFactory.php | 2 +- src/Model/CategoryAttribute.php | 4 +++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 4def8db..5531dd1 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -77,8 +77,11 @@ public function getAttributes(string $categoryId): array * * @param ?string $valueId provide null to fetch first level */ - public function getLevelAttribute(string $categoryId, string $attributeId, ?string $valueId = null): CategoryLevelAttribute - { + public function getLevelAttribute( + string $categoryId, + string $attributeId, + ?string $valueId = null + ): CategoryLevelAttribute { $attributeValueRequest = new CategoryLevelAttributeRequest(); $attributeValueRequest->categoryId = $categoryId; $attributeValueRequest->attributeId = $attributeId; diff --git a/src/Exception/AlibabaException.php b/src/Exception/AlibabaException.php index b72068a..d2025fd 100644 --- a/src/Exception/AlibabaException.php +++ b/src/Exception/AlibabaException.php @@ -12,8 +12,8 @@ class AlibabaException extends \RuntimeException public function __construct( string $message, int $code, - private string $subMessage, - private string $subCode, + private ?string $subMessage, + private ?string $subCode, ?\Throwable $previous = null ) { $message = sprintf('%s. Sub-code: "%s". Sub-message: "%s".', $message, $this->subCode, $this->subMessage); diff --git a/src/Factory/CategoryFactory.php b/src/Factory/CategoryFactory.php index e8c001c..8aec703 100644 --- a/src/Factory/CategoryFactory.php +++ b/src/Factory/CategoryFactory.php @@ -81,7 +81,7 @@ public function createAttributeValue(array $data): CategoryAttributeValue } /** - * @param array $data + * @param $data */ public function createLevelAttribute(array $data): CategoryLevelAttribute { diff --git a/src/Model/CategoryAttribute.php b/src/Model/CategoryAttribute.php index f79e2c7..7f67611 100644 --- a/src/Model/CategoryAttribute.php +++ b/src/Model/CategoryAttribute.php @@ -12,7 +12,9 @@ class CategoryAttribute // TODO: change to enums once all values would be known public string $inputType; // Known values: single_select, multi_select, input - public string $showType; // Known values: list_box (single_select), check_box (multi_select), input (input), group_table (single_select) + + // Known values: list_box (single_select), check_box (multi_select), input (input), group_table (single_select) + public string $showType; public string $valueType; // Known values: string, number public bool $isSku; From 892d33bcc2e176f5b0a5cf603eff9e5a4a4a72ac Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Fri, 9 Feb 2024 15:50:56 +0100 Subject: [PATCH 03/11] fix alibaba exception method return types, fix docblock for param in categoryFactory --- src/Exception/AlibabaException.php | 4 ++-- src/Factory/CategoryFactory.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Exception/AlibabaException.php b/src/Exception/AlibabaException.php index d2025fd..9cd9abe 100644 --- a/src/Exception/AlibabaException.php +++ b/src/Exception/AlibabaException.php @@ -20,12 +20,12 @@ public function __construct( parent::__construct($message, $code, $previous); } - public function getSubMessage(): string + public function getSubMessage(): ?string { return $this->subMessage; } - public function getSubCode(): string + public function getSubCode(): ?string { return $this->subCode; } diff --git a/src/Factory/CategoryFactory.php b/src/Factory/CategoryFactory.php index 8aec703..e8c001c 100644 --- a/src/Factory/CategoryFactory.php +++ b/src/Factory/CategoryFactory.php @@ -81,7 +81,7 @@ public function createAttributeValue(array $data): CategoryAttributeValue } /** - * @param $data + * @param array $data */ public function createLevelAttribute(array $data): CategoryLevelAttribute { From c69f344a64f7b7e3277893cee9f166e964fe062f Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Fri, 16 Feb 2024 15:17:35 +0100 Subject: [PATCH 04/11] update to php 8.1, use enums, add tests, remove category level request class, adjust alibaba exception --- composer.json | 2 +- src/Client.php | 7 +- src/Endpoint/CategoryEndpoint.php | 10 +- src/Enum/InputType.php | 12 +++ src/Enum/ShowType.php | 13 +++ src/Enum/ValueType.php | 11 +++ src/Exception/AlibabaException.php | 5 +- src/Factory/CategoryFactory.php | 9 +- src/Model/CategoryAttribute.php | 13 +-- src/Model/CategoryLevelAttributeRequest.php | 27 ----- tests/Endpoint/CategoryEndpointTest.php | 1 - tests/Factory/CategoryFactoryTest.php | 104 ++++++++++++++++++-- 12 files changed, 162 insertions(+), 52 deletions(-) create mode 100644 src/Enum/InputType.php create mode 100644 src/Enum/ShowType.php create mode 100644 src/Enum/ValueType.php delete mode 100644 src/Model/CategoryLevelAttributeRequest.php diff --git a/composer.json b/composer.json index 587c72c..93f2303 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8", + "php": "^8.1", "ext-json": "*", "ext-mbstring": "*", "symfony/http-client": "^5.4 || ^6" diff --git a/src/Client.php b/src/Client.php index 3e897dc..080c9df 100644 --- a/src/Client.php +++ b/src/Client.php @@ -96,11 +96,14 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { + $subMessage = $errorResponse['sub_msg'] ?? null; + $subCode = $errorResponse['sub_code'] ?? null; + throw new AlibabaException( $errorResponse['msg'], (int) $errorResponse['code'], - $errorResponse['sub_msg'], - $errorResponse['sub_code'], + $subMessage, + $subCode, ); } } diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 5531dd1..c920dae 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -9,7 +9,6 @@ use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; use Kyto\Alibaba\Model\CategoryLevelAttribute; -use Kyto\Alibaba\Model\CategoryLevelAttributeRequest; class CategoryEndpoint { @@ -82,10 +81,11 @@ public function getLevelAttribute( string $attributeId, ?string $valueId = null ): CategoryLevelAttribute { - $attributeValueRequest = new CategoryLevelAttributeRequest(); - $attributeValueRequest->categoryId = $categoryId; - $attributeValueRequest->attributeId = $attributeId; - $attributeValueRequest->valueId = $valueId ?? '0'; + $attributeValueRequest = [ + 'cat_id' => $categoryId, + 'attr_id' => $attributeId, + 'value_id' => $valueId ?? '0' + ]; $data = $this->client->request([ 'method' => 'alibaba.icbu.category.level.attr.get', diff --git a/src/Enum/InputType.php b/src/Enum/InputType.php new file mode 100644 index 0000000..5c3ca3e --- /dev/null +++ b/src/Enum/InputType.php @@ -0,0 +1,12 @@ +subCode, $this->subMessage); + $subCodePart = $this->subCode !== null ? sprintf(' Sub-code: "%s".', $this->subCode) : null; + $subMessagePart = $this->subMessage !== null ? sprintf(' Sub-message: "%s".', $this->subMessage) : null; + $message = sprintf('%s.%s%s', $message, $subCodePart, $subMessagePart); + parent::__construct($message, $code, $previous); } diff --git a/src/Factory/CategoryFactory.php b/src/Factory/CategoryFactory.php index e8c001c..1764804 100644 --- a/src/Factory/CategoryFactory.php +++ b/src/Factory/CategoryFactory.php @@ -4,6 +4,9 @@ namespace Kyto\Alibaba\Factory; +use Kyto\Alibaba\Enum\InputType; +use Kyto\Alibaba\Enum\ShowType; +use Kyto\Alibaba\Enum\ValueType; use Kyto\Alibaba\Model\CategoryLevelAttribute; use Kyto\Alibaba\Model\CategoryLevelAttributeValue; use Kyto\Alibaba\Util\Formatter; @@ -46,9 +49,9 @@ public function createAttribute(array $data): CategoryAttribute $model->name = (string) $data['en_name']; $model->isRequired = (bool) $data['required']; - $model->inputType = (string) $data['input_type']; - $model->showType = (string) $data['show_type']; - $model->valueType = (string) $data['value_type']; + $model->inputType = InputType::from($data['input_type']); + $model->showType = ShowType::from($data['show_type']); + $model->valueType = ValueType::from($data['value_type']); $model->isSku = (bool) $data['sku_attribute']; $model->hasCustomizeImage = (bool) $data['customize_image']; diff --git a/src/Model/CategoryAttribute.php b/src/Model/CategoryAttribute.php index 7f67611..3b79432 100644 --- a/src/Model/CategoryAttribute.php +++ b/src/Model/CategoryAttribute.php @@ -4,18 +4,19 @@ namespace Kyto\Alibaba\Model; +use Kyto\Alibaba\Enum\InputType; +use Kyto\Alibaba\Enum\ShowType; +use Kyto\Alibaba\Enum\ValueType; + class CategoryAttribute { public string $id; public string $name; public bool $isRequired; - // TODO: change to enums once all values would be known - public string $inputType; // Known values: single_select, multi_select, input - - // Known values: list_box (single_select), check_box (multi_select), input (input), group_table (single_select) - public string $showType; - public string $valueType; // Known values: string, number + public InputType $inputType; + public ShowType $showType; + public ValueType $valueType; public bool $isSku; public bool $hasCustomizeImage; diff --git a/src/Model/CategoryLevelAttributeRequest.php b/src/Model/CategoryLevelAttributeRequest.php deleted file mode 100644 index b26588f..0000000 --- a/src/Model/CategoryLevelAttributeRequest.php +++ /dev/null @@ -1,27 +0,0 @@ - - */ - public function jsonSerialize(): array - { - return [ - 'cat_id' => $this->categoryId, - 'attr_id' => $this->attributeId, - 'value_id' => $this->valueId - ]; - } -} diff --git a/tests/Endpoint/CategoryEndpointTest.php b/tests/Endpoint/CategoryEndpointTest.php index a65077f..2cbf359 100644 --- a/tests/Endpoint/CategoryEndpointTest.php +++ b/tests/Endpoint/CategoryEndpointTest.php @@ -10,7 +10,6 @@ use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; use Kyto\Alibaba\Model\CategoryLevelAttribute; -use Kyto\Alibaba\Model\CategoryLevelAttributeRequest; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Factory/CategoryFactoryTest.php b/tests/Factory/CategoryFactoryTest.php index fd63659..46bf5f0 100644 --- a/tests/Factory/CategoryFactoryTest.php +++ b/tests/Factory/CategoryFactoryTest.php @@ -4,10 +4,15 @@ namespace Kyto\Alibaba\Tests\Factory; +use Kyto\Alibaba\Enum\InputType; +use Kyto\Alibaba\Enum\ShowType; +use Kyto\Alibaba\Enum\ValueType; use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; use Kyto\Alibaba\Model\CategoryAttributeValue; +use Kyto\Alibaba\Model\CategoryLevelAttribute; +use Kyto\Alibaba\Model\CategoryLevelAttributeValue; use PHPUnit\Framework\TestCase; class CategoryFactoryTest extends TestCase @@ -145,9 +150,9 @@ public function createAttributeDataProvider(): array $model->id = '1'; $model->name = 'Example'; $model->isRequired = true; - $model->inputType = 'single_select'; - $model->showType = 'list_box'; - $model->valueType = 'string'; + $model->inputType = InputType::SINGLE_SELECT; + $model->showType = ShowType::LIST_BOX; + $model->valueType = ValueType::STRING; $model->isSku = false; $model->hasCustomizeImage = false; $model->hasCustomizeValue = false; @@ -188,9 +193,9 @@ public function createAttributeDataProvider(): array $model->id = '1'; $model->name = 'Example'; $model->isRequired = true; - $model->inputType = 'input'; - $model->showType = 'input'; - $model->valueType = 'number'; + $model->inputType = InputType::INPUT; + $model->showType = ShowType::INPUT; + $model->valueType = ValueType::NUMBER; $model->isSku = false; $model->hasCustomizeImage = false; $model->hasCustomizeValue = false; @@ -253,4 +258,91 @@ public function createAttributeValueDataProvider(): array return $cases; } + + /** + * @dataProvider createLevelAttributeDataProvider + * @param mixed[] $data + */ + public function testCreateLevelAttribute(array $data, CategoryLevelAttribute $expected): void + { + $actual = $this->categoryFactory->createLevelAttribute($data); + self::assertEquals($expected, $actual); + } + + public function createLevelAttributeDataProvider(): \Generator + { + $data = [ + 'property_id' => '123', + 'property_en_name' => 'someName', + 'values' => '{}' + ]; + + $expected = new CategoryLevelAttribute(); + $expected->id = '123'; + $expected->name = 'someName'; + $expected->values = []; + + yield ['no values' => $data, $expected]; + + $data = [ + 'property_id' => '123', + 'property_en_name' => 'someName', + 'values' => '[{"id":"1","name":"valueNoLeaf"},{"id":2,"name":"valueIsLeaf","leaf":true}]' + ]; + + $levelValueNoLeaf = new CategoryLevelAttributeValue(); + $levelValueNoLeaf->id = '1'; + $levelValueNoLeaf->name = 'valueNoLeaf'; + $levelValueNoLeaf->isLeaf = false; + + $levelValueIsLeaf = new CategoryLevelAttributeValue(); + $levelValueIsLeaf->id = '2'; + $levelValueIsLeaf->name = 'valueIsLeaf'; + $levelValueIsLeaf->isLeaf = true; + + $expected = new CategoryLevelAttribute(); + $expected->id = '123'; + $expected->name = 'someName'; + $expected->values = [$levelValueNoLeaf, $levelValueIsLeaf]; + + yield ['with values' => $data, $expected]; + } + + /** + * @dataProvider createLevelAttributeValueDataProvider + * @param mixed[] $data + */ + public function testCreateLevelAttributeValue(array $data, CategoryLevelAttributeValue $expected): void + { + $actual = $this->categoryFactory->createLevelAttributeValue($data); + self::assertEquals($expected, $actual); + } + + public function createLevelAttributeValueDataProvider(): \Generator + { + $data = [ + "id" => "1", + "name" => "valueNoLeaf" + ]; + + $expected = new CategoryLevelAttributeValue(); + $expected->name = 'valueNoLeaf'; + $expected->id = '1'; + $expected->isLeaf = false; + + yield ['no leaf' => $data, $expected]; + + $data = [ + "id" => "1", + "name" => "valueIsLeaf", + "leaf" => true + ]; + + $expected = new CategoryLevelAttributeValue(); + $expected->name = 'valueIsLeaf'; + $expected->id = '1'; + $expected->isLeaf = true; + + yield ['is leaf' => $data, $expected]; + } } From 4e8ea27c3ee8c86637fc3c7090923a6ca4831316 Mon Sep 17 00:00:00 2001 From: Dominik Czulak <79507763+Dominik-Czulak@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:43:46 +0100 Subject: [PATCH 05/11] Update build.yml remove build for php 8.0, add build for php 8.3 --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3b90553..86439ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.0', '8.1', '8.2'] + php: ['8.1', '8.2', '8.3'] composer: ['--prefer-lowest', ''] steps: - name: Setup PHP From d816625607f10b011d09e7586a4db1755a3404bb Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Mon, 19 Feb 2024 09:49:24 +0100 Subject: [PATCH 06/11] add interval value for showtype enum --- src/Enum/ShowType.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Enum/ShowType.php b/src/Enum/ShowType.php index 0a6a6bc..04a5eaf 100644 --- a/src/Enum/ShowType.php +++ b/src/Enum/ShowType.php @@ -8,6 +8,7 @@ enum ShowType: string { case CHECK_BOX = 'check_box'; // multi_select case GROUP_TABLE = 'group_table'; // single_select - case INPUT = 'input'; // input (text) + case INPUT = 'input'; // input (string) + case INTERVAL = 'interval'; // input (number) case LIST_BOX = 'list_box'; // single_select } From 0fd792afb1e2681f50314b90f08ea98296a97b79 Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Mon, 19 Feb 2024 15:04:06 +0100 Subject: [PATCH 07/11] add model numbers to showtype --- src/Enum/ShowType.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Enum/ShowType.php b/src/Enum/ShowType.php index 04a5eaf..470d022 100644 --- a/src/Enum/ShowType.php +++ b/src/Enum/ShowType.php @@ -11,4 +11,5 @@ enum ShowType: string case INPUT = 'input'; // input (string) case INTERVAL = 'interval'; // input (number) case LIST_BOX = 'list_box'; // single_select + case MODEL_NUMBERS = 'model_numbers'; // input (string) } From 12fcfdb721ef4ac943ec1d5c3b0358ac0da2ae53 Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Tue, 20 Feb 2024 13:24:11 +0100 Subject: [PATCH 08/11] handle empty result, revert alibaba nullable error codes --- src/Client.php | 7 ++----- src/Endpoint/CategoryEndpoint.php | 11 ++++++++++- src/Exception/AlibabaException.php | 13 +++++-------- tests/Factory/CategoryFactoryTest.php | 8 ++++---- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/Client.php b/src/Client.php index 080c9df..3e897dc 100644 --- a/src/Client.php +++ b/src/Client.php @@ -96,14 +96,11 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { - $subMessage = $errorResponse['sub_msg'] ?? null; - $subCode = $errorResponse['sub_code'] ?? null; - throw new AlibabaException( $errorResponse['msg'], (int) $errorResponse['code'], - $subMessage, - $subCode, + $errorResponse['sub_msg'], + $errorResponse['sub_code'], ); } } diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index c920dae..cf3f032 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -92,7 +92,16 @@ public function getLevelAttribute( 'attribute_value_request' => json_encode($attributeValueRequest) ]); - $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list']; + $errorMessage = sprintf( + 'Result list for category id: "%s", attribute id: "%s", value id: "%s" is empty.', + $categoryId, + $attributeId, + $valueId + ); + + $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list'] + ?? throw new \RuntimeException($errorMessage); + return $this->categoryFactory->createLevelAttribute($attribute); } } diff --git a/src/Exception/AlibabaException.php b/src/Exception/AlibabaException.php index de6d2f6..b72068a 100644 --- a/src/Exception/AlibabaException.php +++ b/src/Exception/AlibabaException.php @@ -12,23 +12,20 @@ class AlibabaException extends \RuntimeException public function __construct( string $message, int $code, - private ?string $subMessage, - private ?string $subCode, + private string $subMessage, + private string $subCode, ?\Throwable $previous = null ) { - $subCodePart = $this->subCode !== null ? sprintf(' Sub-code: "%s".', $this->subCode) : null; - $subMessagePart = $this->subMessage !== null ? sprintf(' Sub-message: "%s".', $this->subMessage) : null; - $message = sprintf('%s.%s%s', $message, $subCodePart, $subMessagePart); - + $message = sprintf('%s. Sub-code: "%s". Sub-message: "%s".', $message, $this->subCode, $this->subMessage); parent::__construct($message, $code, $previous); } - public function getSubMessage(): ?string + public function getSubMessage(): string { return $this->subMessage; } - public function getSubCode(): ?string + public function getSubCode(): string { return $this->subCode; } diff --git a/tests/Factory/CategoryFactoryTest.php b/tests/Factory/CategoryFactoryTest.php index 46bf5f0..8e8d04f 100644 --- a/tests/Factory/CategoryFactoryTest.php +++ b/tests/Factory/CategoryFactoryTest.php @@ -282,7 +282,7 @@ public function createLevelAttributeDataProvider(): \Generator $expected->name = 'someName'; $expected->values = []; - yield ['no values' => $data, $expected]; + yield 'no values' => [$data, $expected]; $data = [ 'property_id' => '123', @@ -305,7 +305,7 @@ public function createLevelAttributeDataProvider(): \Generator $expected->name = 'someName'; $expected->values = [$levelValueNoLeaf, $levelValueIsLeaf]; - yield ['with values' => $data, $expected]; + yield 'with values' => [$data, $expected]; } /** @@ -330,7 +330,7 @@ public function createLevelAttributeValueDataProvider(): \Generator $expected->id = '1'; $expected->isLeaf = false; - yield ['no leaf' => $data, $expected]; + yield 'no leaf' => [$data, $expected]; $data = [ "id" => "1", @@ -343,6 +343,6 @@ public function createLevelAttributeValueDataProvider(): \Generator $expected->id = '1'; $expected->isLeaf = true; - yield ['is leaf' => $data, $expected]; + yield 'is leaf' => [$data, $expected]; } } From a80b62c33e29e60782cf0da662d2a4b8a3a25264 Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Thu, 22 Feb 2024 11:11:47 +0100 Subject: [PATCH 09/11] refactor alibaba exception --- src/Client.php | 4 +-- src/Endpoint/CategoryEndpoint.php | 3 +- src/Exception/AlibabaApiError.php | 32 +++++++++++++++++++ src/Exception/AlibabaException.php | 25 +-------------- .../UnexpectedApiResultException.php | 19 +++++++++++ tests/ClientTest.php | 4 +-- ...eptionTest.php => AlibabaApiErrorTest.php} | 6 ++-- .../UnexpectedApiResultExceptionTest.php | 24 ++++++++++++++ 8 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 src/Exception/AlibabaApiError.php create mode 100644 src/Exception/UnexpectedApiResultException.php rename tests/Exception/{AlibabaExceptionTest.php => AlibabaApiErrorTest.php} (79%) create mode 100644 tests/Exception/UnexpectedApiResultExceptionTest.php diff --git a/src/Client.php b/src/Client.php index 3e897dc..f183bc6 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba; -use Kyto\Alibaba\Exception\AlibabaException; +use Kyto\Alibaba\Exception\AlibabaApiError; use Kyto\Alibaba\Util\Clock; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -96,7 +96,7 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { - throw new AlibabaException( + throw new AlibabaApiError( $errorResponse['msg'], (int) $errorResponse['code'], $errorResponse['sub_msg'], diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index cf3f032..5e9d2a7 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -5,6 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; +use Kyto\Alibaba\Exception\UnexpectedApiResultException; use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; @@ -100,7 +101,7 @@ public function getLevelAttribute( ); $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list'] - ?? throw new \RuntimeException($errorMessage); + ?? throw new UnexpectedApiResultException($errorMessage); return $this->categoryFactory->createLevelAttribute($attribute); } diff --git a/src/Exception/AlibabaApiError.php b/src/Exception/AlibabaApiError.php new file mode 100644 index 0000000..e538eb7 --- /dev/null +++ b/src/Exception/AlibabaApiError.php @@ -0,0 +1,32 @@ +subCode, $this->subMessage); + parent::__construct($message, $code, $previous); + } + + public function getSubMessage(): string + { + return $this->subMessage; + } + + public function getSubCode(): string + { + return $this->subCode; + } +} diff --git a/src/Exception/AlibabaException.php b/src/Exception/AlibabaException.php index b72068a..24758b2 100644 --- a/src/Exception/AlibabaException.php +++ b/src/Exception/AlibabaException.php @@ -4,29 +4,6 @@ namespace Kyto\Alibaba\Exception; -class AlibabaException extends \RuntimeException +abstract class AlibabaException extends \RuntimeException { - /** - * @internal - */ - public function __construct( - string $message, - int $code, - private string $subMessage, - private string $subCode, - ?\Throwable $previous = null - ) { - $message = sprintf('%s. Sub-code: "%s". Sub-message: "%s".', $message, $this->subCode, $this->subMessage); - parent::__construct($message, $code, $previous); - } - - public function getSubMessage(): string - { - return $this->subMessage; - } - - public function getSubCode(): string - { - return $this->subCode; - } } diff --git a/src/Exception/UnexpectedApiResultException.php b/src/Exception/UnexpectedApiResultException.php new file mode 100644 index 0000000..eef1345 --- /dev/null +++ b/src/Exception/UnexpectedApiResultException.php @@ -0,0 +1,19 @@ +willReturn($response); if (!$isSuccess) { - $this->expectException(AlibabaException::class); + $this->expectException(AlibabaApiError::class); } $actual = $this->client->request(['hello' => 'world', 'test' => 'data']); diff --git a/tests/Exception/AlibabaExceptionTest.php b/tests/Exception/AlibabaApiErrorTest.php similarity index 79% rename from tests/Exception/AlibabaExceptionTest.php rename to tests/Exception/AlibabaApiErrorTest.php index 3af1f40..5cde34b 100644 --- a/tests/Exception/AlibabaExceptionTest.php +++ b/tests/Exception/AlibabaApiErrorTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\AlibabaException; +use Kyto\Alibaba\Exception\AlibabaApiError; use PHPUnit\Framework\TestCase; -class AlibabaExceptionTest extends TestCase +class AlibabaApiErrorTest extends TestCase { public function testConstruct(): void { @@ -17,7 +17,7 @@ public function testConstruct(): void $subCode = 'sub.code'; $previous = new \RuntimeException('Previous'); - $exception = new AlibabaException($message, $code, $subMessage, $subCode, $previous); + $exception = new AlibabaApiError($message, $code, $subMessage, $subCode, $previous); self::assertSame('Message. Sub-code: "sub.code". Sub-message: "Sub-message".', $exception->getMessage()); self::assertSame($code, $exception->getCode()); diff --git a/tests/Exception/UnexpectedApiResultExceptionTest.php b/tests/Exception/UnexpectedApiResultExceptionTest.php new file mode 100644 index 0000000..cb81635 --- /dev/null +++ b/tests/Exception/UnexpectedApiResultExceptionTest.php @@ -0,0 +1,24 @@ +getMessage()); + self::assertSame($code, $exception->getCode()); + self::assertSame($previous, $exception->getPrevious()); + } +} From b2a0378755e1e93df43b326fd23d2e6de55d6b0a Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Fri, 23 Feb 2024 10:58:56 +0100 Subject: [PATCH 10/11] rename error to exception, add throws tags for public endpoint functions --- src/Client.php | 4 ++-- src/Endpoint/CategoryEndpoint.php | 6 +++++- src/Endpoint/ProductEndpoint.php | 2 ++ src/Endpoint/TokenEndpoint.php | 3 +++ .../{AlibabaApiError.php => AlibabaApiException.php} | 2 +- tests/ClientTest.php | 4 ++-- ...{AlibabaApiErrorTest.php => AlibabaApiExceptionTest.php} | 6 +++--- 7 files changed, 18 insertions(+), 9 deletions(-) rename src/Exception/{AlibabaApiError.php => AlibabaApiException.php} (92%) rename tests/Exception/{AlibabaApiErrorTest.php => AlibabaApiExceptionTest.php} (78%) diff --git a/src/Client.php b/src/Client.php index f183bc6..9ce2112 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba; -use Kyto\Alibaba\Exception\AlibabaApiError; +use Kyto\Alibaba\Exception\AlibabaApiException; use Kyto\Alibaba\Util\Clock; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -96,7 +96,7 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { - throw new AlibabaApiError( + throw new AlibabaApiException( $errorResponse['msg'], (int) $errorResponse['code'], $errorResponse['sub_msg'], diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 5e9d2a7..3970b5e 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -5,6 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; +use Kyto\Alibaba\Exception\AlibabaApiException; use Kyto\Alibaba\Exception\UnexpectedApiResultException; use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; @@ -35,6 +36,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=50064 * * @param ?string $id Provide `null` to fetch root categories + * @throws AlibabaApiException */ public function get(?string $id = null): Category { @@ -53,6 +55,7 @@ public function get(?string $id = null): Category * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25348 * * @return CategoryAttribute[] + * @throws AlibabaApiException */ public function getAttributes(string $categoryId): array { @@ -75,7 +78,8 @@ public function getAttributes(string $categoryId): array * Get next-level attribute based on category, attribute and optionally level attribute value ID. * @link https://developer.alibaba.com/en/doc.htm?spm=a2728.12183079.k2mwm9fd.1.4b3630901WuQWY#?docType=2&docId=48659 * - * @param ?string $valueId provide null to fetch first level + * @param ?string $valueId provide null to fetch root level + * @throws AlibabaApiException | UnexpectedApiResultException */ public function getLevelAttribute( string $categoryId, diff --git a/src/Endpoint/ProductEndpoint.php b/src/Endpoint/ProductEndpoint.php index 19b2684..4c41459 100644 --- a/src/Endpoint/ProductEndpoint.php +++ b/src/Endpoint/ProductEndpoint.php @@ -5,6 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; +use Kyto\Alibaba\Exception\AlibabaApiException; use Kyto\Alibaba\Factory\ProductFactory; use Kyto\Alibaba\Model\ProductGroup; use Kyto\Alibaba\Model\Token; @@ -33,6 +34,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25299 * * @param ?string $id Provide `null` to fetch root groups + * @throws AlibabaApiException */ public function getGroup(Token $token, ?string $id = null): ProductGroup { diff --git a/src/Endpoint/TokenEndpoint.php b/src/Endpoint/TokenEndpoint.php index ec713bd..03e5f80 100644 --- a/src/Endpoint/TokenEndpoint.php +++ b/src/Endpoint/TokenEndpoint.php @@ -5,6 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; +use Kyto\Alibaba\Exception\AlibabaApiException; use Kyto\Alibaba\Factory\TokenFactory; use Kyto\Alibaba\Model\Token; @@ -31,6 +32,8 @@ public function __construct( * To obtain authorization code see corresponding facade method. * @link https://open.taobao.com/api.htm?spm=a219a.7386653.0.0.41449b714zR8KI&docId=25388&docType=2&source=search * @see \Kyto\Alibaba\Facade::getAuthorizationUrl + * + * @throws AlibabaApiException|\JsonException */ public function new(string $authorizationCode): Token { diff --git a/src/Exception/AlibabaApiError.php b/src/Exception/AlibabaApiException.php similarity index 92% rename from src/Exception/AlibabaApiError.php rename to src/Exception/AlibabaApiException.php index e538eb7..c081e13 100644 --- a/src/Exception/AlibabaApiError.php +++ b/src/Exception/AlibabaApiException.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba\Exception; -class AlibabaApiError extends AlibabaException +class AlibabaApiException extends AlibabaException { /** * @internal diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 4478208..6d63079 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Tests; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiError; +use Kyto\Alibaba\Exception\AlibabaApiException; use Kyto\Alibaba\Util\Clock; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -81,7 +81,7 @@ public function testRequest(bool $isSuccess, array $responseData): void ->willReturn($response); if (!$isSuccess) { - $this->expectException(AlibabaApiError::class); + $this->expectException(AlibabaApiException::class); } $actual = $this->client->request(['hello' => 'world', 'test' => 'data']); diff --git a/tests/Exception/AlibabaApiErrorTest.php b/tests/Exception/AlibabaApiExceptionTest.php similarity index 78% rename from tests/Exception/AlibabaApiErrorTest.php rename to tests/Exception/AlibabaApiExceptionTest.php index 5cde34b..e2d6949 100644 --- a/tests/Exception/AlibabaApiErrorTest.php +++ b/tests/Exception/AlibabaApiExceptionTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\AlibabaApiError; +use Kyto\Alibaba\Exception\AlibabaApiException; use PHPUnit\Framework\TestCase; -class AlibabaApiErrorTest extends TestCase +class AlibabaApiExceptionTest extends TestCase { public function testConstruct(): void { @@ -17,7 +17,7 @@ public function testConstruct(): void $subCode = 'sub.code'; $previous = new \RuntimeException('Previous'); - $exception = new AlibabaApiError($message, $code, $subMessage, $subCode, $previous); + $exception = new AlibabaApiException($message, $code, $subMessage, $subCode, $previous); self::assertSame('Message. Sub-code: "sub.code". Sub-message: "Sub-message".', $exception->getMessage()); self::assertSame($code, $exception->getCode()); From 5bef79679b460cf210a78a35bc79c81ecc4f35fc Mon Sep 17 00:00:00 2001 From: Dominik Czulak Date: Mon, 26 Feb 2024 13:50:02 +0100 Subject: [PATCH 11/11] rename exceptions --- src/Client.php | 4 ++-- src/Endpoint/CategoryEndpoint.php | 12 ++++++------ src/Endpoint/ProductEndpoint.php | 4 ++-- src/Endpoint/TokenEndpoint.php | 4 ++-- ...AlibabaApiException.php => ResponseException.php} | 2 +- ...ltException.php => UnexpectedResultException.php} | 2 +- tests/ClientTest.php | 4 ++-- ...piExceptionTest.php => ResponseExceptionTest.php} | 6 +++--- ...ionTest.php => UnexpectedResultExceptionTest.php} | 6 +++--- 9 files changed, 22 insertions(+), 22 deletions(-) rename src/Exception/{AlibabaApiException.php => ResponseException.php} (92%) rename src/Exception/{UnexpectedApiResultException.php => UnexpectedResultException.php} (83%) rename tests/Exception/{AlibabaApiExceptionTest.php => ResponseExceptionTest.php} (78%) rename tests/Exception/{UnexpectedApiResultExceptionTest.php => UnexpectedResultExceptionTest.php} (69%) diff --git a/src/Client.php b/src/Client.php index 9ce2112..c9048a7 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Util\Clock; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -96,7 +96,7 @@ private function throwOnError(array $data): void $errorResponse = $data['error_response'] ?? null; if ($errorResponse !== null) { - throw new AlibabaApiException( + throw new ResponseException( $errorResponse['msg'], (int) $errorResponse['code'], $errorResponse['sub_msg'], diff --git a/src/Endpoint/CategoryEndpoint.php b/src/Endpoint/CategoryEndpoint.php index 3970b5e..09b33d2 100644 --- a/src/Endpoint/CategoryEndpoint.php +++ b/src/Endpoint/CategoryEndpoint.php @@ -5,8 +5,8 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; -use Kyto\Alibaba\Exception\UnexpectedApiResultException; +use Kyto\Alibaba\Exception\ResponseException; +use Kyto\Alibaba\Exception\UnexpectedResultException; use Kyto\Alibaba\Factory\CategoryFactory; use Kyto\Alibaba\Model\Category; use Kyto\Alibaba\Model\CategoryAttribute; @@ -36,7 +36,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=50064 * * @param ?string $id Provide `null` to fetch root categories - * @throws AlibabaApiException + * @throws ResponseException */ public function get(?string $id = null): Category { @@ -55,7 +55,7 @@ public function get(?string $id = null): Category * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25348 * * @return CategoryAttribute[] - * @throws AlibabaApiException + * @throws ResponseException */ public function getAttributes(string $categoryId): array { @@ -79,7 +79,7 @@ public function getAttributes(string $categoryId): array * @link https://developer.alibaba.com/en/doc.htm?spm=a2728.12183079.k2mwm9fd.1.4b3630901WuQWY#?docType=2&docId=48659 * * @param ?string $valueId provide null to fetch root level - * @throws AlibabaApiException | UnexpectedApiResultException + * @throws ResponseException|UnexpectedResultException */ public function getLevelAttribute( string $categoryId, @@ -105,7 +105,7 @@ public function getLevelAttribute( ); $attribute = $data['alibaba_icbu_category_level_attr_get_response']['result_list'] - ?? throw new UnexpectedApiResultException($errorMessage); + ?? throw new UnexpectedResultException($errorMessage); return $this->categoryFactory->createLevelAttribute($attribute); } diff --git a/src/Endpoint/ProductEndpoint.php b/src/Endpoint/ProductEndpoint.php index 4c41459..e654c32 100644 --- a/src/Endpoint/ProductEndpoint.php +++ b/src/Endpoint/ProductEndpoint.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Factory\ProductFactory; use Kyto\Alibaba\Model\ProductGroup; use Kyto\Alibaba\Model\Token; @@ -34,7 +34,7 @@ public function __construct( * @link https://developer.alibaba.com/en/doc.htm?spm=a219a.7629140.0.0.188675fe5JPvEa#?docType=2&docId=25299 * * @param ?string $id Provide `null` to fetch root groups - * @throws AlibabaApiException + * @throws ResponseException */ public function getGroup(Token $token, ?string $id = null): ProductGroup { diff --git a/src/Endpoint/TokenEndpoint.php b/src/Endpoint/TokenEndpoint.php index 03e5f80..04be7e1 100644 --- a/src/Endpoint/TokenEndpoint.php +++ b/src/Endpoint/TokenEndpoint.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Endpoint; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Factory\TokenFactory; use Kyto\Alibaba\Model\Token; @@ -33,7 +33,7 @@ public function __construct( * @link https://open.taobao.com/api.htm?spm=a219a.7386653.0.0.41449b714zR8KI&docId=25388&docType=2&source=search * @see \Kyto\Alibaba\Facade::getAuthorizationUrl * - * @throws AlibabaApiException|\JsonException + * @throws ResponseException|\JsonException */ public function new(string $authorizationCode): Token { diff --git a/src/Exception/AlibabaApiException.php b/src/Exception/ResponseException.php similarity index 92% rename from src/Exception/AlibabaApiException.php rename to src/Exception/ResponseException.php index c081e13..b1351c7 100644 --- a/src/Exception/AlibabaApiException.php +++ b/src/Exception/ResponseException.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba\Exception; -class AlibabaApiException extends AlibabaException +class ResponseException extends AlibabaException { /** * @internal diff --git a/src/Exception/UnexpectedApiResultException.php b/src/Exception/UnexpectedResultException.php similarity index 83% rename from src/Exception/UnexpectedApiResultException.php rename to src/Exception/UnexpectedResultException.php index eef1345..4cfb418 100644 --- a/src/Exception/UnexpectedApiResultException.php +++ b/src/Exception/UnexpectedResultException.php @@ -4,7 +4,7 @@ namespace Kyto\Alibaba\Exception; -class UnexpectedApiResultException extends AlibabaException +class UnexpectedResultException extends AlibabaException { /** * @internal diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 6d63079..8ed76d1 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -5,7 +5,7 @@ namespace Kyto\Alibaba\Tests; use Kyto\Alibaba\Client; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use Kyto\Alibaba\Util\Clock; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -81,7 +81,7 @@ public function testRequest(bool $isSuccess, array $responseData): void ->willReturn($response); if (!$isSuccess) { - $this->expectException(AlibabaApiException::class); + $this->expectException(ResponseException::class); } $actual = $this->client->request(['hello' => 'world', 'test' => 'data']); diff --git a/tests/Exception/AlibabaApiExceptionTest.php b/tests/Exception/ResponseExceptionTest.php similarity index 78% rename from tests/Exception/AlibabaApiExceptionTest.php rename to tests/Exception/ResponseExceptionTest.php index e2d6949..21f98ec 100644 --- a/tests/Exception/AlibabaApiExceptionTest.php +++ b/tests/Exception/ResponseExceptionTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\AlibabaApiException; +use Kyto\Alibaba\Exception\ResponseException; use PHPUnit\Framework\TestCase; -class AlibabaApiExceptionTest extends TestCase +class ResponseExceptionTest extends TestCase { public function testConstruct(): void { @@ -17,7 +17,7 @@ public function testConstruct(): void $subCode = 'sub.code'; $previous = new \RuntimeException('Previous'); - $exception = new AlibabaApiException($message, $code, $subMessage, $subCode, $previous); + $exception = new ResponseException($message, $code, $subMessage, $subCode, $previous); self::assertSame('Message. Sub-code: "sub.code". Sub-message: "Sub-message".', $exception->getMessage()); self::assertSame($code, $exception->getCode()); diff --git a/tests/Exception/UnexpectedApiResultExceptionTest.php b/tests/Exception/UnexpectedResultExceptionTest.php similarity index 69% rename from tests/Exception/UnexpectedApiResultExceptionTest.php rename to tests/Exception/UnexpectedResultExceptionTest.php index cb81635..e3d39d8 100644 --- a/tests/Exception/UnexpectedApiResultExceptionTest.php +++ b/tests/Exception/UnexpectedResultExceptionTest.php @@ -4,10 +4,10 @@ namespace Kyto\Alibaba\Tests\Exception; -use Kyto\Alibaba\Exception\UnexpectedApiResultException; +use Kyto\Alibaba\Exception\UnexpectedResultException; use PHPUnit\Framework\TestCase; -class UnexpectedApiResultExceptionTest extends TestCase +class UnexpectedResultExceptionTest extends TestCase { public function testConstruct(): void { @@ -15,7 +15,7 @@ public function testConstruct(): void $code = 1; $previous = new \RuntimeException('Previous'); - $exception = new UnexpectedApiResultException($message, $code, $previous); + $exception = new UnexpectedResultException($message, $code, $previous); self::assertSame('Message', $exception->getMessage()); self::assertSame($code, $exception->getCode());