Skip to content

Commit c57e9b8

Browse files
committed
refact: Merge EE client into this project
1 parent cf65304 commit c57e9b8

File tree

98 files changed

+6412
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6412
-29
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<testsuite name="Integration">
1414
<directory>tests/</directory>
15+
<directory suffix="Integration.php">tests/</directory>
1516
</testsuite>
1617

1718
<filter>

spec/AkeneoPimClientSpec.php

Lines changed: 140 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@
44

55
use Akeneo\Pim\ApiClient\AkeneoPimClient;
66
use Akeneo\Pim\ApiClient\AkeneoPimClientInterface;
7+
use Akeneo\Pim\ApiClient\Api\AssetApiInterface;
8+
use Akeneo\Pim\ApiClient\Api\AssetCategoryApiInterface;
9+
use Akeneo\Pim\ApiClient\Api\AssetManager\AssetApiInterface as AssetManagerApiInterface;
10+
use Akeneo\Pim\ApiClient\Api\AssetManager\AssetAttributeApiInterface;
11+
use Akeneo\Pim\ApiClient\Api\AssetManager\AssetAttributeOptionApiInterface;
12+
use Akeneo\Pim\ApiClient\Api\AssetManager\AssetFamilyApiInterface;
13+
use Akeneo\Pim\ApiClient\Api\AssetManager\AssetMediaFileApiInterface;
14+
use Akeneo\Pim\ApiClient\Api\AssetReferenceFileApiInterface;
15+
use Akeneo\Pim\ApiClient\Api\AssetTagApiInterface;
16+
use Akeneo\Pim\ApiClient\Api\AssetVariationFileApiInterface;
717
use Akeneo\Pim\ApiClient\Api\AssociationTypeApiInterface;
818
use Akeneo\Pim\ApiClient\Api\AttributeApiInterface;
9-
use Akeneo\Pim\ApiClient\Api\AttributeGroupApi;
19+
use Akeneo\Pim\ApiClient\Api\AttributeGroupApiInterface;
1020
use Akeneo\Pim\ApiClient\Api\AttributeOptionApiInterface;
1121
use Akeneo\Pim\ApiClient\Api\CategoryApiInterface;
1222
use Akeneo\Pim\ApiClient\Api\ChannelApiInterface;
@@ -18,7 +28,15 @@
1828
use Akeneo\Pim\ApiClient\Api\MeasurementFamilyApiInterface;
1929
use Akeneo\Pim\ApiClient\Api\MediaFileApiInterface;
2030
use Akeneo\Pim\ApiClient\Api\ProductApiInterface;
31+
use Akeneo\Pim\ApiClient\Api\ProductDraftApiInterface;
2132
use Akeneo\Pim\ApiClient\Api\ProductModelApiInterface;
33+
use Akeneo\Pim\ApiClient\Api\ProductModelDraftApiInterface;
34+
use Akeneo\Pim\ApiClient\Api\PublishedProductApiInterface;
35+
use Akeneo\Pim\ApiClient\Api\ReferenceEntityApiInterface;
36+
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeApiInterface;
37+
use Akeneo\Pim\ApiClient\Api\ReferenceEntityAttributeOptionApiInterface;
38+
use Akeneo\Pim\ApiClient\Api\ReferenceEntityMediaFileApiInterface;
39+
use Akeneo\Pim\ApiClient\Api\ReferenceEntityRecordApiInterface;
2240
use Akeneo\Pim\ApiClient\Security\Authentication;
2341
use PhpSpec\ObjectBehavior;
2442

@@ -30,7 +48,7 @@ function let(
3048
CategoryApiInterface $categoryApi,
3149
AttributeApiInterface $attributeApi,
3250
AttributeOptionApiInterface $attributeOptionApi,
33-
AttributeGroupApi $attributeGroupApi,
51+
AttributeGroupApiInterface $attributeGroupApi,
3452
FamilyApiInterface $familyApi,
3553
MediaFileApiInterface $productMediaFileApi,
3654
LocaleApiInterface $localeApi,
@@ -40,15 +58,34 @@ function let(
4058
MeasurementFamilyApiInterface $measurementFamilyApi,
4159
AssociationTypeApiInterface $associationTypeApi,
4260
FamilyVariantApiInterface $familyVariantApi,
43-
ProductModelApiInterface $productModelApi
61+
ProductModelApiInterface $productModelApi,
62+
ProductModelDraftApiInterface $productModelDraftApi,
63+
PublishedProductApiInterface $publishedProductApi,
64+
ProductDraftApiInterface $productDraftApi,
65+
AssetApiInterface $assetApi,
66+
AssetCategoryApiInterface $assetCategoryApi,
67+
AssetTagApiInterface $assetTagApi,
68+
AssetReferenceFileApiInterface $assetReferenceFileApi,
69+
AssetVariationFileApiInterface $assetVariationFileApi,
70+
ReferenceEntityRecordApiInterface $referenceEntityRecordApi,
71+
ReferenceEntityMediaFileApiInterface $referenceEntityMediaFileApi,
72+
ReferenceEntityAttributeApiInterface $referenceEntityAttributeApi,
73+
ReferenceEntityAttributeOptionApiInterface $referenceEntityAttributeOptionApi,
74+
ReferenceEntityApiInterface $referenceEntityApi,
75+
AssetManagerApiInterface $assetManagerApi,
76+
AssetFamilyApiInterface $assetFamilyApi,
77+
AssetAttributeApiInterface $assetAttributeApi,
78+
AssetAttributeOptionApiInterface $assetAttributeOptionApi,
79+
AssetMediaFileApiInterface $assetMediaFileApi
4480
) {
4581
$this->beConstructedWith(
4682
$authentication,
4783
$productApi,
4884
$categoryApi,
4985
$attributeApi,
5086
$attributeOptionApi,
51-
$attributeGroupApi, $familyApi,
87+
$attributeGroupApi,
88+
$familyApi,
5289
$productMediaFileApi,
5390
$localeApi,
5491
$channelApi,
@@ -57,7 +94,25 @@ function let(
5794
$measurementFamilyApi,
5895
$associationTypeApi,
5996
$familyVariantApi,
60-
$productModelApi
97+
$productModelApi,
98+
$productModelDraftApi,
99+
$publishedProductApi,
100+
$productDraftApi,
101+
$assetApi,
102+
$assetCategoryApi,
103+
$assetTagApi,
104+
$assetReferenceFileApi,
105+
$assetVariationFileApi,
106+
$referenceEntityRecordApi,
107+
$referenceEntityMediaFileApi,
108+
$referenceEntityAttributeApi,
109+
$referenceEntityAttributeOptionApi,
110+
$referenceEntityApi,
111+
$assetManagerApi,
112+
$assetFamilyApi,
113+
$assetAttributeApi,
114+
$assetAttributeOptionApi,
115+
$assetMediaFileApi
61116
);
62117
}
63118

@@ -150,4 +205,84 @@ function it_gets_product_model_api($productModelApi)
150205
{
151206
$this->getProductModelApi()->shouldReturn($productModelApi);
152207
}
208+
209+
function it_gets_published_product_api($publishedProductApi)
210+
{
211+
$this->getPublishedProductApi()->shouldReturn($publishedProductApi);
212+
}
213+
214+
function it_gets_draft_product_api($productDraftApi)
215+
{
216+
$this->getProductDraftApi()->shouldReturn($productDraftApi);
217+
}
218+
219+
function it_gets_draft_product_model_api($productModelDraftApi)
220+
{
221+
$this->getProductModelDraftApi()->shouldReturn($productModelDraftApi);
222+
}
223+
224+
function it_gets_asset_api($assetApi)
225+
{
226+
$this->getAssetApi()->shouldReturn($assetApi);
227+
}
228+
229+
function it_gets_asset_category_api($assetCategoryApi)
230+
{
231+
$this->getAssetCategoryApi()->shouldReturn($assetCategoryApi);
232+
}
233+
234+
function it_gets_asset_tags_api($assetTagApi)
235+
{
236+
$this->getAssetTagApi()->shouldReturn($assetTagApi);
237+
}
238+
239+
function it_gets_asset_reference_file_api($assetReferenceFileApi)
240+
{
241+
$this->getAssetReferenceFileApi()->shouldReturn($assetReferenceFileApi);
242+
}
243+
244+
function it_gets_reference_entity_record_api($referenceEntityRecordApi)
245+
{
246+
$this->getReferenceEntityRecordApi()->shouldReturn($referenceEntityRecordApi);
247+
}
248+
249+
function it_gets_reference_entity_media_file_api($referenceEntityMediaFileApi)
250+
{
251+
$this->getReferenceEntityMediaFileApi()->shouldReturn($referenceEntityMediaFileApi);
252+
}
253+
254+
function it_gets_reference_entity_attribute_api($referenceEntityAttributeApi)
255+
{
256+
$this->getReferenceEntityAttributeApi()->shouldReturn($referenceEntityAttributeApi);
257+
}
258+
259+
function it_gets_reference_entity_api($referenceEntityApi)
260+
{
261+
$this->getReferenceEntityApi()->shouldReturn($referenceEntityApi);
262+
}
263+
264+
function it_gets_asset_manager_api($assetManagerApi)
265+
{
266+
$this->getAssetManagerApi()->shouldReturn($assetManagerApi);
267+
}
268+
269+
function it_gets_asset_family_api($assetFamilyApi)
270+
{
271+
$this->getAssetFamilyApi()->shouldReturn($assetFamilyApi);
272+
}
273+
274+
function it_gets_asset_attribute_api($assetAttributeApi)
275+
{
276+
$this->getAssetAttributeApi()->shouldReturn($assetAttributeApi);
277+
}
278+
279+
function it_gets_asset_attribute_option_api($assetAttributeOptionApi)
280+
{
281+
$this->getAssetAttributeOptionApi()->shouldReturn($assetAttributeOptionApi);
282+
}
283+
284+
function it_gets_asset_media_file_api($assetMediaFileApi)
285+
{
286+
$this->getAssetMediaFileApi()->shouldReturn($assetMediaFileApi);
287+
}
153288
}

spec/Api/AssetApiSpec.php

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
3+
namespace spec\Akeneo\Pim\ApiClient\Api;
4+
5+
use Akeneo\Pim\ApiClient\Api\AssetApi;
6+
use Akeneo\Pim\ApiClient\Client\ResourceClientInterface;
7+
use Akeneo\Pim\ApiClient\Exception\InvalidArgumentException;
8+
use Akeneo\Pim\ApiClient\Pagination\PageFactoryInterface;
9+
use Akeneo\Pim\ApiClient\Pagination\PageInterface;
10+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorFactoryInterface;
11+
use Akeneo\Pim\ApiClient\Pagination\ResourceCursorInterface;
12+
use Akeneo\Pim\ApiClient\Stream\UpsertResourceListResponse;
13+
use PhpSpec\ObjectBehavior;
14+
15+
class AssetApiSpec extends ObjectBehavior
16+
{
17+
function let(
18+
ResourceClientInterface $resourceClient,
19+
PageFactoryInterface $pageFactory,
20+
ResourceCursorFactoryInterface $cursorFactory
21+
) {
22+
$this->beConstructedWith($resourceClient, $pageFactory, $cursorFactory);
23+
}
24+
25+
function it_is_initializable()
26+
{
27+
$this->shouldHaveType(AssetApi::class);
28+
}
29+
30+
function it_gets_an_asset($resourceClient)
31+
{
32+
$asset = [
33+
'code' => 'akeneo_logo',
34+
'localized' => false,
35+
'description' => 'Akeneo logo',
36+
'end_of_use' => null,
37+
'tags' => [],
38+
'categories' => ['asset_main_catalog'],
39+
'variation_files' => [],
40+
'reference_files' => [],
41+
];
42+
43+
$resourceClient->getResource(AssetApi::ASSET_URI, ['akeneo_logo'])->willReturn($asset);
44+
45+
$this->get('akeneo_logo')->shouldReturn($asset);
46+
}
47+
48+
function it_returns_a_list_of_assets_with_default_parameters(
49+
$resourceClient,
50+
$pageFactory,
51+
PageInterface $page
52+
) {
53+
$resourceClient
54+
->getResources(AssetApi::ASSETS_URI, [], 10, false, [])
55+
->willReturn([]);
56+
$pageFactory->createPage([])->willReturn($page);
57+
$this->listPerPage()->shouldReturn($page);
58+
}
59+
60+
function it_returns_a_list_of_assets_with_limit_and_count(
61+
$resourceClient,
62+
$pageFactory,
63+
PageInterface $page
64+
) {
65+
$resourceClient
66+
->getResources(AssetApi::ASSETS_URI, [], 10, true, [])
67+
->willReturn([]);
68+
$pageFactory->createPage([])->willReturn($page);
69+
$this->listPerPage(10, true)->shouldReturn($page);
70+
}
71+
72+
function it_returns_a_cursor_on_the_list_of_assets(
73+
$resourceClient,
74+
$pageFactory,
75+
$cursorFactory,
76+
PageInterface $page,
77+
ResourceCursorInterface $cursor
78+
) {
79+
$resourceClient
80+
->getResources(
81+
AssetApi::ASSETS_URI,
82+
[],
83+
10,
84+
false,
85+
['pagination_type' => 'search_after']
86+
)
87+
->willReturn([]);
88+
$pageFactory->createPage([])->willReturn($page);
89+
$cursorFactory->createCursor(10, $page)->willReturn($cursor);
90+
$this->all(10, [])->shouldReturn($cursor);
91+
}
92+
93+
function it_returns_a_list_of_assets_with_additional_query_parameters(
94+
$resourceClient,
95+
$pageFactory,
96+
PageInterface $page
97+
) {
98+
$resourceClient
99+
->getResources(AssetApi::ASSETS_URI, [], 10, true, ['foo' => 'bar'])
100+
->willReturn([]);
101+
$pageFactory->createPage([])->willReturn($page);
102+
$this->listPerPage(10, true, ['foo' => 'bar'])->shouldReturn($page);
103+
}
104+
105+
function it_creates_an_asset($resourceClient)
106+
{
107+
$resourceClient->createResource(AssetApi::ASSETS_URI, [], [
108+
'code' => 'unicorn',
109+
'localized' => false,
110+
'description' => 'The wonderful unicorn',
111+
'end_of_use' => null,
112+
'tags' => [],
113+
'categories' => ['asset_main_catalog'],
114+
'variation_files' => [],
115+
'reference_files' => [],
116+
])->willReturn(201);
117+
118+
$this->create('unicorn', [
119+
'localized' => false,
120+
'description' => 'The wonderful unicorn',
121+
'end_of_use' => null,
122+
'tags' => [],
123+
'categories' => ['asset_main_catalog'],
124+
'variation_files' => [],
125+
'reference_files' => [],
126+
])->shouldReturn(201);
127+
}
128+
129+
function it_throws_an_exception_if_code_is_provided_in_data_when_creating_an_asset()
130+
{
131+
$this
132+
->shouldThrow(new InvalidArgumentException('The parameter "code" should not be defined in the data parameter'))
133+
->during('create', ['unicorn', ['code' => 'unicorn', 'localized' => false]]);
134+
}
135+
136+
function it_upserts_an_asset($resourceClient)
137+
{
138+
$resourceClient
139+
->upsertResource(AssetApi::ASSET_URI, ['akeneo_logo'], [
140+
'localized' => false,
141+
'description' => 'Akeneo logo updated',
142+
'categories' => ['asset_main_catalog'],
143+
])
144+
->willReturn(204);
145+
146+
$this->upsert('akeneo_logo', [
147+
'localized' => false,
148+
'description' => 'Akeneo logo updated',
149+
'categories' => ['asset_main_catalog'],
150+
])->shouldReturn(204);
151+
}
152+
153+
function it_upserts_a_list_of_assets($resourceClient, UpsertResourceListResponse $response)
154+
{
155+
$resourceClient->upsertStreamResourceList(AssetApi::ASSETS_URI, [], [
156+
[
157+
'code' => 'akeneo_logo',
158+
'description' => 'Akeneo logo updated',
159+
],
160+
[
161+
'code' => 'unicorn',
162+
'description' => 'Created asset',
163+
]
164+
])->willReturn($response);
165+
166+
$this->upsertList([
167+
[
168+
'code' => 'akeneo_logo',
169+
'description' => 'Akeneo logo updated',
170+
],
171+
[
172+
'code' => 'unicorn',
173+
'description' => 'Created asset',
174+
]
175+
])->shouldReturn($response);
176+
}
177+
}

0 commit comments

Comments
 (0)