Skip to content

Commit

Permalink
refactor Sylius#14860 [Behat][API] Common saving within contexts (Raf…
Browse files Browse the repository at this point in the history
…ikooo)

This PR was merged into the 1.13 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.13 <!-- see the comment below -->                  |
| Bug fix?        | no                                                       |
| New feature?    | yes                                                       |
| BC breaks?      | no                                                      |
| Deprecations?   | no<!-- don't forget to update the UPGRADE-*.md file --> |
| License         | MIT                                                          |

<!--
 - Bug fixes must be submitted against the 1.12 branch
 - Features and deprecations must be submitted against the 1.13 branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->

This PR introduces a single method for saving resources (API only), which eliminates the name conflict of saving methods when using multiple contexts within a single suite


Commits
-------

95b04c2 [ECS] Apply ecs fixes
2bdcad0 [Behat] Remove iSaveMyChanges methods from all API contexts
0d73b2d [Behat][API] Introduce common SaveContext service
a2cbfd7 [Behat][API] Use SaveContext within suites
  • Loading branch information
GSadee authored Mar 16, 2023
2 parents f1271f9 + a2cbfd7 commit 2974757
Show file tree
Hide file tree
Showing 38 changed files with 82 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,6 @@ public function iAddIt(): void
$this->client->create();
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$response = $this->client->update();
$this->responseChecker->isUpdateSuccessful($response);
}

/**
* @When I delete administrator with email :adminUser
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,6 @@ public function iMakeCatalogPromotionOperateFrom(string $startDate): void
$this->client->updateRequestData(['startDate' => $startDate]);
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I browse catalog promotions
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,6 @@ public function iWantToModifyThisChannel(ChannelInterface $channel): void
$this->client->buildUpdateRequest(Resources::CHANNELS, $channel->getCode());
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @Then I should be notified that it has been successfully created
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,6 @@ public function iDisableIt(): void
$this->client->addRequestData('enabled', false);
}

/**
* @When I save my changes
* @When I try to save changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I name the province :provinceName
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ public function iWantToEditThisCustomerGroup(CustomerGroupInterface $customerGro
$this->client->buildUpdateRequest(Resources::CUSTOMER_GROUPS, $customerGroup->getCode());
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I browse customer groups
* @When I want to browse customer groups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ public function iChangeRatioTo(string $ratio): void
$this->client->updateRequestData(['ratio' => $ratio]);
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When /^I delete the (exchange rate between "[^"]+" and "[^"]+")$/
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ public function iRenameItToIn(string $name, string $language): void
$this->client->updateRequestData(['translations' => [$language => ['name' => $name, 'locale' => $language]]]);
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @Then I should be notified that it has been successfully edited
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ public function iAddIt(): void
$this->client->create();
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @Then I should see :count product options in the list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ public function iChangeItsCommentTo(?string $comment = ''): void
$this->client->updateRequestData(['comment' => $comment]);
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I choose :rating as its rating
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@ public function iChooseMainTaxon(TaxonInterface $taxon): void
$this->client->updateRequestData(['mainTaxon' => $this->iriConverter->getIriFromItem($taxon)]);
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I filter them by :taxon taxon
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ public function iSpecifyItsDescriptionAs(string $description): void
$this->client->addRequestData('description', $description);
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @Then I should be notified that shipping category with this code already exists
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,6 @@ public function iWantToModifyShippingMethod(ShippingMethodInterface $shippingMet
$this->client->buildUpdateRequest(Resources::SHIPPING_METHODS, $shippingMethod->getCode());
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I sort the shipping methods :sortType by code
* @When I switch the way shipping methods are sorted :sortType by code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ public function iDescribeItAs(string $description): void
$this->client->addRequestData('description', $description);
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I browse tax categories
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@ public function iRemoveItsAmount(): void
$this->client->addRequestData('amount', '');
}

/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I browse tax rates
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Api/Admin/ManagingZonesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,6 @@ public function iRemoveTheZoneMember(ZoneInterface $zone): void
$this->removeZoneMember($zone);
}

/**
* @When I save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @Then the zone named :zone with the :country country member should appear in the registry
*/
Expand Down
33 changes: 33 additions & 0 deletions src/Sylius/Behat/Context/Api/Common/SaveContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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 Sylius\Behat\Context\Api\Common;

use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;

final class SaveContext implements Context
{
public function __construct(private ApiClientInterface $client)
{
}

/**
* @When I save my changes
* @When I try to save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}
}
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Api/Shop/CustomerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ public function iSpecifyCustomerTheEmail(string $email = ''): void
$this->client->addRequestData('email', $email);
}

/**
* @When I (try to) save my changes
*/
public function iSaveMyChanges(): void
{
$this->client->update();
}

/**
* @When I specify the current password as :password
*/
Expand Down
26 changes: 26 additions & 0 deletions src/Sylius/Behat/Resources/config/services/contexts/api/common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.behat.context.api.admin.save" class="Sylius\Behat\Context\Api\Common\SaveContext">
<argument type="service" id="sylius.behat.api_platform_client.admin" />
</service>

<service id="sylius.behat.context.api.shop.save" class="Sylius\Behat\Context\Api\Common\SaveContext">
<argument type="service" id="sylius.behat.api_platform_client.shop" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ default:

- sylius.behat.context.api.shop.address
- sylius.behat.context.api.shop.checkout
- sylius.behat.context.api.shop.save

filters:
tags: "@address_book&&@api"
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ default:
- sylius.behat.context.setup.user
- sylius.behat.context.setup.zone

- sylius.behat.context.api.shop.checkout
- sylius.behat.context.api.shop.customer
- sylius.behat.context.api.shop.login
- sylius.behat.context.api.shop.order
- sylius.behat.context.api.shop.order_item
- sylius.behat.context.api.shop.checkout
- sylius.behat.context.api.shop.login
- sylius.behat.context.api.shop.payment
- sylius.behat.context.api.shop.save
- sylius.behat.context.api.shop.shipment

filters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default:
- sylius.behat.context.setup.zone

- sylius.behat.context.api.admin.managing_countries
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_countries&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default:
- sylius.behat.context.setup.zone

- sylius.behat.context.api.admin.managing_zones
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_zones&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ default:
- sylius.behat.context.setup.zone

- sylius.behat.context.api.admin.managing_channels
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_channels&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default:
- sylius.behat.context.setup.exchange_rate

- sylius.behat.context.api.admin.managing_exchange_rates
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_exchange_rates&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ default:
- sylius.behat.context.setup.product_association

- sylius.behat.context.api.admin.managing_product_association_types
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_product_association_types&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default:
- sylius.behat.context.setup.admin_api_security

- sylius.behat.context.api.admin.managing_product_options
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_product_options&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default:
- sylius.behat.context.setup.product_review

- sylius.behat.context.api.admin.managing_product_reviews
- sylius.behat.context.api.admin.save

filters:
tags: "@managing_product_reviews&&@api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ default:
- sylius.behat.context.setup.shipping_category
- sylius.behat.context.setup.taxonomy
- sylius.behat.context.setup.zone
- Sylius\Behat\Context\Api\Admin\ManagingProductTaxonsContext

- sylius.behat.context.api.admin.managing_products
- sylius.behat.context.api.admin.save
- Sylius\Behat\Context\Api\Admin\ManagingProductTaxonsContext

filters:
tags: "@managing_products&&@api"
Expand Down
Loading

0 comments on commit 2974757

Please sign in to comment.