From fa071489221f5d9b6ec3873fb05a6f31a98545c6 Mon Sep 17 00:00:00 2001 From: constant-bouquet Date: Tue, 7 Nov 2023 13:20:26 +0100 Subject: [PATCH 1/2] Implement SystemInformationApi for the endpoint GET /api/rest/v1/system-information --- src/AkeneoPimClient.php | 17 ++++++++++++--- src/AkeneoPimClientBuilder.php | 4 +++- src/AkeneoPimClientInterface.php | 7 ++++-- src/Api/SystemInformationApi.php | 26 +++++++++++++++++++++++ src/Api/SystemInformationApiInterface.php | 21 ++++++++++++++++++ 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 src/Api/SystemInformationApi.php create mode 100644 src/Api/SystemInformationApiInterface.php diff --git a/src/AkeneoPimClient.php b/src/AkeneoPimClient.php index c9caa221..609a4041 100644 --- a/src/AkeneoPimClient.php +++ b/src/AkeneoPimClient.php @@ -41,6 +41,8 @@ use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface; +use Akeneo\Pim\ApiClient\Api\SystemInformationApi; +use Akeneo\Pim\ApiClient\Api\SystemInformationApiInterface; use Akeneo\Pim\ApiClient\Security\Authentication; /** @@ -91,7 +93,8 @@ public function __construct( private ProductUuidApiInterface $productUuidApi, private ProductDraftUuidApiInterface $productDraftUuidApi, private AppCatalogApiInterface $appCatalogApi, - private AppCatalogProductApiInterface $appCatalogProductApi + private AppCatalogProductApiInterface $appCatalogProductApi, + private SystemInformationApiInterface $systemInformationApi ) { } @@ -265,7 +268,7 @@ public function getProductDraftApi(): ProductDraftApiInterface /** * @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0. - * @see getAssetManagerApi instead. + * @see getAssetManagerApi instead. */ public function getAssetApi(): AssetApiInterface { @@ -274,7 +277,7 @@ public function getAssetApi(): AssetApiInterface /** * @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0. - * @see getAssetFamilyApi instead. + * @see getAssetFamilyApi instead. */ public function getAssetCategoryApi(): AssetCategoryApiInterface { @@ -416,4 +419,12 @@ public function getAppCatalogProductApi(): AppCatalogProductApiInterface { return $this->appCatalogProductApi; } + + /** + * {@inheritDoc} + */ + public function getSystemInformationApi(): SystemInformationApi + { + return $this->systemInformationApi; + } } diff --git a/src/AkeneoPimClientBuilder.php b/src/AkeneoPimClientBuilder.php index 375af807..2f8e4a62 100644 --- a/src/AkeneoPimClientBuilder.php +++ b/src/AkeneoPimClientBuilder.php @@ -41,6 +41,7 @@ use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApi; use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApi; use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApi; +use Akeneo\Pim\ApiClient\Api\SystemInformationApi; use Akeneo\Pim\ApiClient\Cache\LRUCache; use Akeneo\Pim\ApiClient\Client\AuthenticatedHttpClient; use Akeneo\Pim\ApiClient\Client\CachedResourceClient; @@ -249,7 +250,8 @@ protected function buildAuthenticatedClient(Authentication $authentication): Ake new ProductUuidApi($resourceClient, $pageFactory, $cursorFactory), new ProductDraftUuidApi($resourceClient, $pageFactory, $cursorFactory), new AppCatalogApi($resourceClient, $pageFactory, $cursorFactory), - new AppCatalogProductApi($resourceClient, $pageFactory, $cursorFactory) + new AppCatalogProductApi($resourceClient, $pageFactory, $cursorFactory), + new SystemInformationApi($resourceClient) ); } diff --git a/src/AkeneoPimClientInterface.php b/src/AkeneoPimClientInterface.php index 3350fbfb..7a94d707 100644 --- a/src/AkeneoPimClientInterface.php +++ b/src/AkeneoPimClientInterface.php @@ -40,6 +40,7 @@ use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface; +use Akeneo\Pim\ApiClient\Api\SystemInformationApi; /** * Client to use the Akeneo PIM API. @@ -94,13 +95,13 @@ public function getProductDraftApi(): ProductDraftApiInterface; /** * @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0. - * @see getAssetManagerApi instead. + * @see getAssetManagerApi instead. */ public function getAssetApi(): AssetApiInterface; /** * @deprecated Route unavailable in latest PIM versions. Will be removed in v12.0.0. - * @see getAssetFamilyApi instead. + * @see getAssetFamilyApi instead. */ public function getAssetCategoryApi(): AssetCategoryApiInterface; @@ -146,4 +147,6 @@ public function getProductDraftUuidApi(): ProductDraftUuidApiInterface; public function getAppCatalogApi(): AppCatalogApiInterface; public function getAppCatalogProductApi(): AppCatalogProductApiInterface; + + public function getSystemInformationApi(): SystemInformationApi; } diff --git a/src/Api/SystemInformationApi.php b/src/Api/SystemInformationApi.php new file mode 100644 index 00000000..50eb0a6b --- /dev/null +++ b/src/Api/SystemInformationApi.php @@ -0,0 +1,26 @@ +resourceClient->getResource(static::SYSTEM_INFORMATION_URI); + } +} diff --git a/src/Api/SystemInformationApiInterface.php b/src/Api/SystemInformationApiInterface.php new file mode 100644 index 00000000..28d6f267 --- /dev/null +++ b/src/Api/SystemInformationApiInterface.php @@ -0,0 +1,21 @@ + Date: Thu, 21 Mar 2024 23:21:25 +0100 Subject: [PATCH 2/2] Add and fix spec tests --- spec/AkeneoPimClientSpec.php | 7 +++-- spec/Api/SystemInformationApiSpec.php | 45 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 spec/Api/SystemInformationApiSpec.php diff --git a/spec/AkeneoPimClientSpec.php b/spec/AkeneoPimClientSpec.php index 80dc47ec..7b2d8c56 100644 --- a/spec/AkeneoPimClientSpec.php +++ b/spec/AkeneoPimClientSpec.php @@ -42,6 +42,7 @@ use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface; use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface; +use Akeneo\Pim\ApiClient\Api\SystemInformationApiInterface; use Akeneo\Pim\ApiClient\Security\Authentication; use PhpSpec\ObjectBehavior; @@ -86,7 +87,8 @@ function let( ProductUuidApiInterface $productUuidApi, ProductDraftUuidApiInterface $productDraftUuidApi, AppCatalogApiInterface $appCatalogApi, - AppCatalogProductApiInterface $appCatalogProductApi + AppCatalogProductApiInterface $appCatalogProductApi, + SystemInformationApiInterface $systemInformationApi, ) { $this->beConstructedWith( $authentication, @@ -127,7 +129,8 @@ function let( $productUuidApi, $productDraftUuidApi, $appCatalogApi, - $appCatalogProductApi + $appCatalogProductApi, + $systemInformationApi ); } diff --git a/spec/Api/SystemInformationApiSpec.php b/spec/Api/SystemInformationApiSpec.php new file mode 100644 index 00000000..2522a91c --- /dev/null +++ b/spec/Api/SystemInformationApiSpec.php @@ -0,0 +1,45 @@ +beConstructedWith($resourceClient, $pageFactory, $cursorFactory); + } + + function it_is_initializable() + { + $this->shouldHaveType(SystemInformationApi::class); + $this->shouldImplement(SystemInformationApiInterface::class); + } + + function it_returns_system_information($resourceClient) + { + $systemInformation = [ + 'code' => 'foo', + 'attributes' => ['sku'], + 'sort_order' => 1, + 'labels' => [ + 'en_US' => 'Foo', + ], + ]; + + $resourceClient + ->getResource(SystemInformationApi::SYSTEM_INFORMATION_URI) + ->willReturn($systemInformation); + + $this->get()->shouldReturn($systemInformation); + } +}