Skip to content

Commit

Permalink
replace code to iri in ChangePaymentMethod and change id to code in P…
Browse files Browse the repository at this point in the history
…aymentMethod
  • Loading branch information
Tomanhez authored and arti0090 committed Apr 29, 2021
1 parent 6bb6936 commit deb2cfa
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/Sylius/Behat/Context/Api/Shop/CheckoutContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Behat\Context\Api\Shop;

use ApiPlatform\Core\Api\IriConverterInterface;
use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Client\Request;
Expand Down Expand Up @@ -64,6 +65,9 @@ final class CheckoutContext implements Context
/** @var ProductVariantResolverInterface */
private $productVariantResolver;

/** @var IriConverterInterface */
private $iriConverter;

/** @var SharedStorageInterface */
private $sharedStorage;

Expand All @@ -78,6 +82,7 @@ public function __construct(
OrderRepositoryInterface $orderRepository,
RepositoryInterface $paymentMethodRepository,
ProductVariantResolverInterface $productVariantResolver,
IriConverterInterface $iriConverter,
SharedStorageInterface $sharedStorage
) {
$this->ordersClient = $ordersClient;
Expand All @@ -87,6 +92,7 @@ public function __construct(
$this->orderRepository = $orderRepository;
$this->paymentMethodRepository = $paymentMethodRepository;
$this->productVariantResolver = $productVariantResolver;
$this->iriConverter = $iriConverter;
$this->sharedStorage = $sharedStorage;
}

Expand Down Expand Up @@ -390,7 +396,7 @@ public function iChoosePaymentMethod(PaymentMethodInterface $paymentMethod): voi
\sprintf('payments/%s', $this->getCart()['payments'][0]['id'])
);

$request->setContent(['paymentMethodCode' => $paymentMethod->getCode()]);
$request->setContent(['paymentMethod' => $this->iriConverter->getIriFromItem($paymentMethod)]);

$this->ordersClient->executeCustomRequest($request);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Context/Api/Shop/OrderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function iChangeMyPaymentMethodTo(PaymentMethodInterface $paymentMethod):
$this->client->getToken()
);

$request->setContent(['paymentMethodCode' => $paymentMethod->getCode()]);
$request->setContent(['paymentMethod' => $this->iriConverter->getIriFromItem($paymentMethod)]);

$this->client->executeCustomRequest($request);
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public function iShouldHavePaymentMethodOnMyOrder(PaymentMethodInterface $paymen
->getValue($this->client->getLastResponse(), 'payments')[0]['method']['@id']
;

Assert::same($this->iriConverter->getItemFromIri($paymentMethodIri)->getId(), $paymentMethod->getId());
Assert::same($this->iriConverter->getItemFromIri($paymentMethodIri)->getCode(), $paymentMethod->getCode());
}

private function getAdjustmentsForOrder(): array
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Setup/PaymentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct(
*/
public function storeAllowsPaying($paymentMethodName, $position = null)
{
$this->createPaymentMethod($paymentMethodName, 'PM_' . $paymentMethodName, 'Offline', 'Payment method', true, $position);
$this->createPaymentMethod($paymentMethodName, 'PM_' . StringInflector::nameToCode($paymentMethodName), 'Offline', 'Payment method', true, $position);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius.repository.payment_method" />
<argument type="service" id="sylius.product_variant_resolver.default" />
<argument type="service" id="api_platform.iri_converter" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@
<itemOperations>
<itemOperation name="admin_get">
<attribute name="method">GET</attribute>
<attribute name="path">/admin/payment-methods/{id}</attribute>
<attribute name="path">/admin/payment-methods/{code}</attribute>
<attribute name="normalization_context">
<attribute name="groups">admin:payment_method:read</attribute>
</attribute>
</itemOperation>

<itemOperation name="shop_get">
<attribute name="method">GET</attribute>
<attribute name="path">/shop/payment-methods/{id}</attribute>
<attribute name="path">/shop/payment-methods/{code}</attribute>
<attribute name="normalization_context">
<attribute name="groups">shop:payment_method:read</attribute>
</attribute>
</itemOperation>
</itemOperations>

<property name="id" identifier="true" writable="false" />
<property name="id" identifier="false" writable="false" />
<property name="code" identifier="true" writable="false" />
<property name="name" writable="true" />
</resource>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod">
<attribute name="paymentMethodCode">
<attribute name="paymentMethodCode" serialized-name="paymentMethod">
<group>shop:order:account:change_payment_method</group>
</attribute>
</class>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
>
<class name="Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod">
<attribute name="paymentMethodCode">
<attribute name="paymentMethodCode" serialized-name="paymentMethod">
<group>shop:cart:select_payment_method</group>
</attribute>
</class>
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<service id="Sylius\Bundle\ApiBundle\Map\CommandItemIriArgumentToIdentifierMap">
<argument type="collection">
<argument key="Sylius\Bundle\ApiBundle\Command\AddProductReview">product</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Checkout\ChoosePaymentMethod">paymentMethod</argument>
<argument key="Sylius\Bundle\ApiBundle\Command\Account\ChangePaymentMethod">paymentMethod</argument>
</argument>
</service>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace spec\Sylius\Bundle\ApiBundle\Map;

use PhpSpec\ObjectBehavior;
use Sylius\Bundle\ApiBundle\Map\CommandItemIriArgumentToIdentifierMap;
use Sylius\Bundle\ApiBundle\Map\CommandItemIriArgumentToIdentifierMapInterface;
use Webmozart\Assert\Assert;

final class CommandItemIriArgumentToIdentifierMapSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(['Sylius\Bundle\ApiBundle\Command\Cart\PickupCart' => 'token']);
}

function it_is_command_item_iri_argument_to_identifier_map(): void
{
$this->shouldImplement(CommandItemIriArgumentToIdentifierMapInterface::class);
}

function it_get_element(): void
{
$map = new CommandItemIriArgumentToIdentifierMap(['Sylius\Bundle\ApiBundle\Command\Cart\PickupCart' => 'token']);
Assert::same('token', $map->get('Sylius\Bundle\ApiBundle\Command\Cart\PickupCart'));
}

function it_has_element(): void
{
$map = new CommandItemIriArgumentToIdentifierMap(['Sylius\Bundle\ApiBundle\Command\Cart\PickupCart' => 'token']);
Assert::true($map->has('Sylius\Bundle\ApiBundle\Command\Cart\PickupCart'));
}

function it_has_not_element(): void
{
$map = new CommandItemIriArgumentToIdentifierMap(['Sylius\Bundle\ApiBundle\Command\Cart\PickupCart' => 'token']);
Assert::false($map->has('Sylius\Bundle\ApiBundle\Command\Cart\CreateCart'));
}
}

0 comments on commit deb2cfa

Please sign in to comment.