Skip to content

Commit 67337ca

Browse files
authored
Merge pull request #1 from gplanchat/master
Added a fluent interface in the SyliusClientBuilder
2 parents c7a1f06 + a1c1db0 commit 67337ca

8 files changed

+351
-225
lines changed

spec/Api/AuthenticationApiSpec.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public function it_authenticates_with_the_password_grant_type(
4141

4242
$response->getBody()->willReturn($body);
4343
$responseContent = <<<'JSON'
44-
{
45-
"access_token": "foo",
46-
"expires_in": 3600,
47-
"token_type": "bearer",
48-
"scope": null,
49-
"refresh_token": "bar"
50-
}
44+
{
45+
"access_token": "foo",
46+
"expires_in": 3600,
47+
"token_type": "bearer",
48+
"scope": null,
49+
"refresh_token": "bar"
50+
}
5151
JSON;
5252
$body->getContents()->willReturn($responseContent);
5353

@@ -78,13 +78,13 @@ public function it_authenticates_with_the_refresh_token_type(
7878

7979
$response->getBody()->willReturn($body);
8080
$responseContent = <<<'JSON'
81-
{
82-
"access_token": "foo",
83-
"expires_in": 3600,
84-
"token_type": "bearer",
85-
"scope": null,
86-
"refresh_token": "baz"
87-
}
81+
{
82+
"access_token": "foo",
83+
"expires_in": 3600,
84+
"token_type": "bearer",
85+
"scope": null,
86+
"refresh_token": "baz"
87+
}
8888
JSON;
8989
$body->getContents()->willReturn($responseContent);
9090

spec/Client/ResourceClientSpec.php

+16-18
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,16 @@ public function it_is_initializable()
3535
public function it_gets_resource($httpClient, $uriGenerator, ResponseInterface $response, StreamInterface $responseBody)
3636
{
3737
$uri = 'http://diglin.com/api/rest/v1/categories/winter_collection';
38-
$resource =
39-
<<<'JSON'
40-
{
41-
"code": "winter_collection",
42-
"parent": null,
43-
"labels": {
44-
"en_US": "Winter collection",
45-
"fr_FR": "Collection hiver"
46-
}
47-
}
48-
JSON;
38+
$resource = <<<'JSON'
39+
{
40+
"code": "winter_collection",
41+
"parent": null,
42+
"labels": {
43+
"en_US": "Winter collection",
44+
"fr_FR": "Collection hiver"
45+
}
46+
}
47+
JSON;
4948

5049
$uriGenerator
5150
->generate('api/rest/v1/categories/%s', ['winter_collection'], [])
@@ -231,13 +230,12 @@ public function it_upserts_a_list_of_resources_from_an_array(
231230
->willReturn($uri)
232231
;
233232

234-
$body =
235-
<<<'JSON'
236-
{"code":"category_1"}
237-
{"code":"category_2"}
238-
{"code":"category_3"}
239-
{"code":"category_4"}
240-
JSON;
233+
$body = <<<'JSON'
234+
{"code":"category_1"}
235+
{"code":"category_2"}
236+
{"code":"category_3"}
237+
{"code":"category_4"}
238+
JSON;
241239

242240
$httpClient
243241
->sendRequest('PATCH', $uri, ['Content-Type' => 'application/vnd.akeneo.collection+json'], $body)

spec/Exception/UnprocessableEntityHttpExceptionSpec.php

+19-21
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@ public function it_exposes_the_response_errors($response, StreamInterface $body)
2525
$response->getStatusCode()->willReturn(422);
2626
$response->getBody()->willReturn($body);
2727
$body->rewind()->shouldBeCalled();
28-
$body->getContents()->willReturn(
29-
<<<'JSON'
30-
{
31-
"code": "422",
32-
"message": "The response message",
33-
"errors": [
34-
{
35-
"property": "labels",
36-
"message": "The first error"
37-
},
38-
{
39-
"property": "labels",
40-
"message": "The second error"
41-
}
42-
]
43-
}
28+
$body->getContents()->willReturn(<<<'JSON'
29+
{
30+
"code": "422",
31+
"message": "The response message",
32+
"errors": [
33+
{
34+
"property": "labels",
35+
"message": "The first error"
36+
},
37+
{
38+
"property": "labels",
39+
"message": "The second error"
40+
}
41+
]
42+
}
4443
JSON
4544
);
4645

@@ -61,11 +60,10 @@ public function it_returns_an_empty_array_when_the_response_has_no_errors($respo
6160
$response->getStatusCode()->willReturn(422);
6261
$response->getBody()->willReturn($body);
6362
$body->rewind()->shouldBeCalled();
64-
$body->getContents()->willReturn(
65-
<<<'JSON'
66-
{
67-
"code": "422",
68-
}
63+
$body->getContents()->willReturn(<<<'JSON'
64+
{
65+
"code": "422",
66+
}
6967
JSON
7068
);
7169

spec/Routing/UriGeneratorSpec.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class UriGeneratorSpec extends ObjectBehavior
88
{
9-
public const BASE_URI = 'http://akeneo-pim.local/';
9+
public const BASE_URI = 'http://sylius.local/';
1010

1111
public function let()
1212
{

spec/SyliusClientSpec.php

+173-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace spec\Diglin\Sylius\ApiClient;
44

5-
use Diglin\Sylius\ApiClient\Api\ChannelsApiInterface;
5+
use Diglin\Sylius\ApiClient\Api;
66
use Diglin\Sylius\ApiClient\Security\Authentication;
77
use Diglin\Sylius\ApiClient\SyliusClient;
88
use Diglin\Sylius\ApiClient\SyliusClientInterface;
@@ -12,11 +12,59 @@ class SyliusClientSpec extends ObjectBehavior
1212
{
1313
public function let(
1414
Authentication $authentication,
15-
ChannelsApiInterface $channelApi
15+
Api\CartsApiInterface $cartsApi,
16+
Api\ChannelsApiInterface $channelsApi,
17+
Api\CountriesApiInterface $countriesApi,
18+
Api\CurrenciesApiInterface $currenciesApi,
19+
Api\CustomersApiInterface $customersApi,
20+
Api\ExchangeRatesApiInterface $exchangeRatesApi,
21+
Api\LocalesApiInterface $localesApi,
22+
Api\OrdersApiInterface $ordersApi,
23+
Api\PaymentMethodsApiInterface $paymentMethodApi,
24+
Api\PaymentsApiInterface $paymentsApi,
25+
Api\ProductsApiInterface $productsApi,
26+
Api\ProductAttributesApiInterface $productAttributesApi,
27+
Api\ProductAssociationTypesApiInterface $productAssociationTypesApi,
28+
Api\ProductOptionsApiInterface $productOptionsApi,
29+
Api\ProductReviewsApiInterface $productReviewsApi,
30+
Api\ProductVariantsApiInterface $productVariantsApi,
31+
Api\PromotionsApiInterface $promotionsApi,
32+
Api\PromotionCouponsApiInterface $promotionCouponsApi,
33+
Api\ShipmentsApiInterface $shipmentsApi,
34+
Api\ShippingCategoriesApiInterface $shippingCategoriesApi,
35+
Api\TaxCategoriesApiInterface $taxCategoriesApi,
36+
Api\TaxRatesApiInterface $taxRatesApi,
37+
Api\TaxonsApiInterface $taxonsApi,
38+
Api\UsersApiInterface $usersApi,
39+
Api\ZonesApiInterface $zonesApi
1640
) {
1741
$this->beConstructedWith(
1842
$authentication,
19-
$channelApi
43+
$cartsApi,
44+
$channelsApi,
45+
$countriesApi,
46+
$currenciesApi,
47+
$customersApi,
48+
$exchangeRatesApi,
49+
$localesApi,
50+
$ordersApi,
51+
$paymentMethodApi,
52+
$paymentsApi,
53+
$productsApi,
54+
$productAttributesApi,
55+
$productAssociationTypesApi,
56+
$productOptionsApi,
57+
$productReviewsApi,
58+
$productVariantsApi,
59+
$promotionsApi,
60+
$promotionCouponsApi,
61+
$shipmentsApi,
62+
$shippingCategoriesApi,
63+
$taxCategoriesApi,
64+
$taxRatesApi,
65+
$taxonsApi,
66+
$usersApi,
67+
$zonesApi
2068
);
2169
}
2270

@@ -40,8 +88,128 @@ public function it_gets_refresh_token($authentication)
4088
$this->getRefreshToken()->shouldReturn('bar');
4189
}
4290

43-
public function it_gets_channel_api($channelApi)
91+
public function it_gets_cart_api()
4492
{
45-
$this->getChannelsApi()->shouldReturn($channelApi);
93+
$this->getCartsApi()->shouldReturnAnInstanceOf(Api\CartsApiInterface::class);
94+
}
95+
96+
public function it_gets_channel_api()
97+
{
98+
$this->getChannelsApi()->shouldReturnAnInstanceOf(Api\ChannelsApiInterface::class);
99+
}
100+
101+
public function it_gets_country_api()
102+
{
103+
$this->getCountriesApi()->shouldReturnAnInstanceOf(Api\CountriesApiInterface::class);
104+
}
105+
106+
public function if_gets_currencies_api()
107+
{
108+
$this->getCurrenciesApi()->shouldReturnAnInstanceOf(Api\CurrenciesApiInterface::class);
109+
}
110+
111+
public function if_gets_customers_api()
112+
{
113+
$this->getCustomersApi()->shouldReturnAnInstanceOf(Api\CustomersApiInterface::class);
114+
}
115+
116+
public function if_gets_exchangeRates_api()
117+
{
118+
$this->getExchangeRatesApi()->shouldReturnAnInstanceOf(Api\ExchangeRatesApiInterface::class);
119+
}
120+
121+
public function if_gets_locales_api()
122+
{
123+
$this->getLocalesApi()->shouldReturnAnInstanceOf(Api\LocalesApiInterface::class);
124+
}
125+
126+
public function if_gets_orders_api()
127+
{
128+
$this->getOrdersApi()->shouldReturnAnInstanceOf(Api\OrdersApiInterface::class);
129+
}
130+
131+
public function if_gets_paymentMethods_api()
132+
{
133+
$this->getPaymentMethodsApi()->shouldReturnAnInstanceOf(Api\PaymentMethodsApiInterface::class);
134+
}
135+
136+
public function if_gets_payments_api()
137+
{
138+
$this->getPaymentsApi()->shouldReturnAnInstanceOf(Api\PaymentsApiInterface::class);
139+
}
140+
141+
public function if_gets_products_api()
142+
{
143+
$this->getProductsApi()->shouldReturnAnInstanceOf(Api\ProductsApiInterface::class);
144+
}
145+
146+
public function if_gets_productAttributes_api()
147+
{
148+
$this->getProductAttributesApi()->shouldReturnAnInstanceOf(Api\ProductAttributesApiInterface::class);
149+
}
150+
151+
public function if_gets_productAssociationTypes_api()
152+
{
153+
$this->getProductAssociationTypesApi()->shouldReturnAnInstanceOf(Api\ProductAssociationTypesApiInterface::class);
154+
}
155+
156+
public function if_gets_productOptions_api()
157+
{
158+
$this->getProductOptionsApi()->shouldReturnAnInstanceOf(Api\ProductOptionsApiInterface::class);
159+
}
160+
161+
public function if_gets_productReviews_api()
162+
{
163+
$this->getProductReviewsApi()->shouldReturnAnInstanceOf(Api\ProductReviewsApiInterface::class);
164+
}
165+
166+
public function if_gets_productVariants_api()
167+
{
168+
$this->getProductVariantsApi()->shouldReturnAnInstanceOf(Api\ProductVariantsApiInterface::class);
169+
}
170+
171+
public function if_gets_promotions_api()
172+
{
173+
$this->getPromotionsApi()->shouldReturnAnInstanceOf(Api\PromotionsApiInterface::class);
174+
}
175+
176+
public function if_gets_promotionCoupons_api()
177+
{
178+
$this->getPromotionCouponsApi()->shouldReturnAnInstanceOf(Api\PromotionCouponsApiInterface::class);
179+
}
180+
181+
public function if_gets_shipments_api()
182+
{
183+
$this->getShipmentsApi()->shouldReturnAnInstanceOf(Api\ShipmentsApiInterface::class);
184+
}
185+
186+
public function if_gets_shippingCategories_api()
187+
{
188+
$this->getShippingCategoriesApi()->shouldReturnAnInstanceOf(Api\ShippingCategoriesApiInterface::class);
189+
}
190+
191+
public function if_gets_taxCategories_api()
192+
{
193+
$this->getTaxCategoriesApi()->shouldReturnAnInstanceOf(Api\TaxCategoriesApiInterface::class);
194+
}
195+
196+
public function if_gets_taxRates_api()
197+
{
198+
$this->getTaxRatesApi()->shouldReturnAnInstanceOf(Api\TaxRatesApiInterface::class);
199+
}
200+
201+
public function if_gets_taxons_api()
202+
{
203+
$this->getTaxonsApi()->shouldReturnAnInstanceOf(Api\TaxonsApiInterface::class);
204+
}
205+
206+
public function if_gets_users_api()
207+
{
208+
$this->getUsersApi()->shouldReturnAnInstanceOf(Api\UsersApiInterface::class);
209+
}
210+
211+
public function if_gets_zones_api()
212+
{
213+
$this->getZonesApi()->shouldReturnAnInstanceOf(Api\ZonesApiInterface::class);
46214
}
47215
}

0 commit comments

Comments
 (0)