Skip to content

Commit

Permalink
Merge pull request #1 from gplanchat/master
Browse files Browse the repository at this point in the history
Added a fluent interface in the SyliusClientBuilder
  • Loading branch information
sylvainraye committed Feb 10, 2021
2 parents c7a1f06 + a1c1db0 commit 67337ca
Show file tree
Hide file tree
Showing 8 changed files with 351 additions and 225 deletions.
28 changes: 14 additions & 14 deletions spec/Api/AuthenticationApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public function it_authenticates_with_the_password_grant_type(

$response->getBody()->willReturn($body);
$responseContent = <<<'JSON'
{
"access_token": "foo",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "bar"
}
{
"access_token": "foo",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "bar"
}
JSON;
$body->getContents()->willReturn($responseContent);

Expand Down Expand Up @@ -78,13 +78,13 @@ public function it_authenticates_with_the_refresh_token_type(

$response->getBody()->willReturn($body);
$responseContent = <<<'JSON'
{
"access_token": "foo",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "baz"
}
{
"access_token": "foo",
"expires_in": 3600,
"token_type": "bearer",
"scope": null,
"refresh_token": "baz"
}
JSON;
$body->getContents()->willReturn($responseContent);

Expand Down
34 changes: 16 additions & 18 deletions spec/Client/ResourceClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ public function it_is_initializable()
public function it_gets_resource($httpClient, $uriGenerator, ResponseInterface $response, StreamInterface $responseBody)
{
$uri = 'http://diglin.com/api/rest/v1/categories/winter_collection';
$resource =
<<<'JSON'
{
"code": "winter_collection",
"parent": null,
"labels": {
"en_US": "Winter collection",
"fr_FR": "Collection hiver"
}
}
JSON;
$resource = <<<'JSON'
{
"code": "winter_collection",
"parent": null,
"labels": {
"en_US": "Winter collection",
"fr_FR": "Collection hiver"
}
}
JSON;

$uriGenerator
->generate('api/rest/v1/categories/%s', ['winter_collection'], [])
Expand Down Expand Up @@ -231,13 +230,12 @@ public function it_upserts_a_list_of_resources_from_an_array(
->willReturn($uri)
;

$body =
<<<'JSON'
{"code":"category_1"}
{"code":"category_2"}
{"code":"category_3"}
{"code":"category_4"}
JSON;
$body = <<<'JSON'
{"code":"category_1"}
{"code":"category_2"}
{"code":"category_3"}
{"code":"category_4"}
JSON;

$httpClient
->sendRequest('PATCH', $uri, ['Content-Type' => 'application/vnd.akeneo.collection+json'], $body)
Expand Down
40 changes: 19 additions & 21 deletions spec/Exception/UnprocessableEntityHttpExceptionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@ public function it_exposes_the_response_errors($response, StreamInterface $body)
$response->getStatusCode()->willReturn(422);
$response->getBody()->willReturn($body);
$body->rewind()->shouldBeCalled();
$body->getContents()->willReturn(
<<<'JSON'
{
"code": "422",
"message": "The response message",
"errors": [
{
"property": "labels",
"message": "The first error"
},
{
"property": "labels",
"message": "The second error"
}
]
}
$body->getContents()->willReturn(<<<'JSON'
{
"code": "422",
"message": "The response message",
"errors": [
{
"property": "labels",
"message": "The first error"
},
{
"property": "labels",
"message": "The second error"
}
]
}
JSON
);

Expand All @@ -61,11 +60,10 @@ public function it_returns_an_empty_array_when_the_response_has_no_errors($respo
$response->getStatusCode()->willReturn(422);
$response->getBody()->willReturn($body);
$body->rewind()->shouldBeCalled();
$body->getContents()->willReturn(
<<<'JSON'
{
"code": "422",
}
$body->getContents()->willReturn(<<<'JSON'
{
"code": "422",
}
JSON
);

Expand Down
2 changes: 1 addition & 1 deletion spec/Routing/UriGeneratorSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

public function let()
{
Expand Down
178 changes: 173 additions & 5 deletions spec/SyliusClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace spec\Diglin\Sylius\ApiClient;

use Diglin\Sylius\ApiClient\Api\ChannelsApiInterface;
use Diglin\Sylius\ApiClient\Api;
use Diglin\Sylius\ApiClient\Security\Authentication;
use Diglin\Sylius\ApiClient\SyliusClient;
use Diglin\Sylius\ApiClient\SyliusClientInterface;
Expand All @@ -12,11 +12,59 @@ class SyliusClientSpec extends ObjectBehavior
{
public function let(
Authentication $authentication,
ChannelsApiInterface $channelApi
Api\CartsApiInterface $cartsApi,
Api\ChannelsApiInterface $channelsApi,
Api\CountriesApiInterface $countriesApi,
Api\CurrenciesApiInterface $currenciesApi,
Api\CustomersApiInterface $customersApi,
Api\ExchangeRatesApiInterface $exchangeRatesApi,
Api\LocalesApiInterface $localesApi,
Api\OrdersApiInterface $ordersApi,
Api\PaymentMethodsApiInterface $paymentMethodApi,
Api\PaymentsApiInterface $paymentsApi,
Api\ProductsApiInterface $productsApi,
Api\ProductAttributesApiInterface $productAttributesApi,
Api\ProductAssociationTypesApiInterface $productAssociationTypesApi,
Api\ProductOptionsApiInterface $productOptionsApi,
Api\ProductReviewsApiInterface $productReviewsApi,
Api\ProductVariantsApiInterface $productVariantsApi,
Api\PromotionsApiInterface $promotionsApi,
Api\PromotionCouponsApiInterface $promotionCouponsApi,
Api\ShipmentsApiInterface $shipmentsApi,
Api\ShippingCategoriesApiInterface $shippingCategoriesApi,
Api\TaxCategoriesApiInterface $taxCategoriesApi,
Api\TaxRatesApiInterface $taxRatesApi,
Api\TaxonsApiInterface $taxonsApi,
Api\UsersApiInterface $usersApi,
Api\ZonesApiInterface $zonesApi
) {
$this->beConstructedWith(
$authentication,
$channelApi
$cartsApi,
$channelsApi,
$countriesApi,
$currenciesApi,
$customersApi,
$exchangeRatesApi,
$localesApi,
$ordersApi,
$paymentMethodApi,
$paymentsApi,
$productsApi,
$productAttributesApi,
$productAssociationTypesApi,
$productOptionsApi,
$productReviewsApi,
$productVariantsApi,
$promotionsApi,
$promotionCouponsApi,
$shipmentsApi,
$shippingCategoriesApi,
$taxCategoriesApi,
$taxRatesApi,
$taxonsApi,
$usersApi,
$zonesApi
);
}

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

public function it_gets_channel_api($channelApi)
public function it_gets_cart_api()
{
$this->getChannelsApi()->shouldReturn($channelApi);
$this->getCartsApi()->shouldReturnAnInstanceOf(Api\CartsApiInterface::class);
}

public function it_gets_channel_api()
{
$this->getChannelsApi()->shouldReturnAnInstanceOf(Api\ChannelsApiInterface::class);
}

public function it_gets_country_api()
{
$this->getCountriesApi()->shouldReturnAnInstanceOf(Api\CountriesApiInterface::class);
}

public function if_gets_currencies_api()
{
$this->getCurrenciesApi()->shouldReturnAnInstanceOf(Api\CurrenciesApiInterface::class);
}

public function if_gets_customers_api()
{
$this->getCustomersApi()->shouldReturnAnInstanceOf(Api\CustomersApiInterface::class);
}

public function if_gets_exchangeRates_api()
{
$this->getExchangeRatesApi()->shouldReturnAnInstanceOf(Api\ExchangeRatesApiInterface::class);
}

public function if_gets_locales_api()
{
$this->getLocalesApi()->shouldReturnAnInstanceOf(Api\LocalesApiInterface::class);
}

public function if_gets_orders_api()
{
$this->getOrdersApi()->shouldReturnAnInstanceOf(Api\OrdersApiInterface::class);
}

public function if_gets_paymentMethods_api()
{
$this->getPaymentMethodsApi()->shouldReturnAnInstanceOf(Api\PaymentMethodsApiInterface::class);
}

public function if_gets_payments_api()
{
$this->getPaymentsApi()->shouldReturnAnInstanceOf(Api\PaymentsApiInterface::class);
}

public function if_gets_products_api()
{
$this->getProductsApi()->shouldReturnAnInstanceOf(Api\ProductsApiInterface::class);
}

public function if_gets_productAttributes_api()
{
$this->getProductAttributesApi()->shouldReturnAnInstanceOf(Api\ProductAttributesApiInterface::class);
}

public function if_gets_productAssociationTypes_api()
{
$this->getProductAssociationTypesApi()->shouldReturnAnInstanceOf(Api\ProductAssociationTypesApiInterface::class);
}

public function if_gets_productOptions_api()
{
$this->getProductOptionsApi()->shouldReturnAnInstanceOf(Api\ProductOptionsApiInterface::class);
}

public function if_gets_productReviews_api()
{
$this->getProductReviewsApi()->shouldReturnAnInstanceOf(Api\ProductReviewsApiInterface::class);
}

public function if_gets_productVariants_api()
{
$this->getProductVariantsApi()->shouldReturnAnInstanceOf(Api\ProductVariantsApiInterface::class);
}

public function if_gets_promotions_api()
{
$this->getPromotionsApi()->shouldReturnAnInstanceOf(Api\PromotionsApiInterface::class);
}

public function if_gets_promotionCoupons_api()
{
$this->getPromotionCouponsApi()->shouldReturnAnInstanceOf(Api\PromotionCouponsApiInterface::class);
}

public function if_gets_shipments_api()
{
$this->getShipmentsApi()->shouldReturnAnInstanceOf(Api\ShipmentsApiInterface::class);
}

public function if_gets_shippingCategories_api()
{
$this->getShippingCategoriesApi()->shouldReturnAnInstanceOf(Api\ShippingCategoriesApiInterface::class);
}

public function if_gets_taxCategories_api()
{
$this->getTaxCategoriesApi()->shouldReturnAnInstanceOf(Api\TaxCategoriesApiInterface::class);
}

public function if_gets_taxRates_api()
{
$this->getTaxRatesApi()->shouldReturnAnInstanceOf(Api\TaxRatesApiInterface::class);
}

public function if_gets_taxons_api()
{
$this->getTaxonsApi()->shouldReturnAnInstanceOf(Api\TaxonsApiInterface::class);
}

public function if_gets_users_api()
{
$this->getUsersApi()->shouldReturnAnInstanceOf(Api\UsersApiInterface::class);
}

public function if_gets_zones_api()
{
$this->getZonesApi()->shouldReturnAnInstanceOf(Api\ZonesApiInterface::class);
}
}
Loading

0 comments on commit 67337ca

Please sign in to comment.