Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a7233c

Browse files
authored
refactor #11282 [API][Shipping Method] Improvement after PR preview (AdamKasp)
This PR was merged into the 1.8-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | related with #11266 and #11269, part of #11250 | License | MIT <!-- - Bug fixes must be submitted against the 1.6 or 1.7 branches (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set --> Commits ------- 968c677 Fix custom api client method + minor fixes
2 parents e8ae758 + 968c677 commit 9a7233c

9 files changed

Lines changed: 45 additions & 24 deletions

File tree

src/Sylius/Behat/Client/ApiClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function sort(string $field, string $value): Response;
3838

3939
public function applyTransition(string $id, string $transition, array $content = []): Response;
4040

41-
public function customItemAction(string $id, string $action): Response;
41+
public function customItemAction(string $id, string $type, string $action): Response;
4242

4343
public function upload(): Response;
4444

src/Sylius/Behat/Client/ApiPlatformClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function applyTransition(string $id, string $transition, array $content =
9595
return $this->request($request);
9696
}
9797

98-
public function customItemAction(string $id, string $action): Response
98+
public function customItemAction(string $id, string $type, string $action): Response
9999
{
100-
$request = Request::customItemAction($this->resource, $id, $action, $this->sharedStorage->get('token'));
100+
$request = Request::customItemAction($this->resource, $id, $type, $action, $this->sharedStorage->get('token'));
101101

102102
return $this->request($request);
103103
}

src/Sylius/Behat/Client/Request.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public static function delete(string $resource, string $id, string $token): Requ
9494

9595
public static function transition(string $resource, string $id, string $transition, string $token): RequestInterface
9696
{
97-
return self::customItemAction($resource, $id, $transition, $token);
97+
return self::customItemAction($resource, $id, HttpRequest::METHOD_PATCH, $transition, $token);
9898
}
9999

100-
public static function customItemAction(string $resource, string $id, string $transition, string $token): RequestInterface
100+
public static function customItemAction(string $resource, string $id, string $type, string $action, string $token): RequestInterface
101101
{
102102
return new self(
103-
sprintf('/new-api/%s/%s/%s', $resource, $id, $transition),
104-
HttpRequest::METHOD_PATCH,
103+
sprintf('/new-api/%s/%s/%s', $resource, $id, $action),
104+
$type,
105105
['CONTENT_TYPE' => 'application/merge-patch+json', 'HTTP_Authorization' => 'Bearer ' . $token]
106106
);
107107
}

src/Sylius/Behat/Context/Api/Admin/ManagingShippingMethodsContext.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Sylius\Component\Addressing\Model\ZoneInterface;
2121
use Sylius\Component\Core\Model\ChannelInterface;
2222
use Sylius\Component\Core\Model\ShippingMethodInterface;
23+
use Symfony\Component\HttpFoundation\Request as HttpRequest;
2324
use Webmozart\Assert\Assert;
2425

2526
final class ManagingShippingMethodsContext implements Context
@@ -44,7 +45,17 @@ public function __construct(
4445
}
4546

4647
/**
47-
* @Given I am browsing shipping methods
48+
* @Given I am browsing archival shipping methods
49+
*/
50+
public function iAmBrowsingArchivalShippingMethods(): void
51+
{
52+
$this->client->index();
53+
$this->client->addFilter('exists[archivedAt]', true);
54+
$this->client->filter();
55+
}
56+
57+
/**
58+
* @When I am browsing shipping methods
4859
* @When I want to browse shipping methods
4960
*/
5061
public function iBrowseShippingMethods(): void
@@ -164,7 +175,7 @@ public function iChooseCalculator(string $shippingCalculator): void
164175
*/
165176
public function iArchiveTheShippingMethod(ShippingMethodInterface $shippingMethod): void
166177
{
167-
$this->client->customItemAction($shippingMethod->getCode(), 'archive');
178+
$this->client->customItemAction($shippingMethod->getCode(), HttpRequest::METHOD_PATCH, 'archive');
168179
$this->client->index();
169180
}
170181

@@ -173,7 +184,7 @@ public function iArchiveTheShippingMethod(ShippingMethodInterface $shippingMetho
173184
*/
174185
public function iRestoreTheShippingMethod(ShippingMethodInterface $shippingMethod): void
175186
{
176-
$this->client->customItemAction($shippingMethod->getCode(), 'restore');
187+
$this->client->customItemAction($shippingMethod->getCode(), HttpRequest::METHOD_PATCH, 'restore');
177188
$this->client->index();
178189
}
179190

@@ -245,16 +256,6 @@ public function iFilterArchivalShippingMethods(): void
245256
$this->client->filter();
246257
}
247258

248-
/**
249-
* @When I am browsing archival shipping methods
250-
*/
251-
public function iAmBrowsingArchivalShippingMethods(): void
252-
{
253-
$this->client->index();
254-
$this->client->addFilter('exists[archivedAt]', true);
255-
$this->client->filter();
256-
}
257-
258259
/**
259260
* @Then I should see :count shipping methods in the list
260261
*/

src/Sylius/Bundle/ApiBundle/Applicator/ArchivizationShippingMethodApplicator.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,22 @@
1313

1414
namespace Sylius\Bundle\ApiBundle\Applicator;
1515

16+
use Sylius\Bundle\ShippingBundle\Provider\DateTimeProvider;
1617
use Sylius\Component\Core\Model\ShippingMethodInterface;
1718

1819
final class ArchivizationShippingMethodApplicator
1920
{
21+
/** @var DateTimeProvider */
22+
private $calendar;
23+
24+
public function __construct(DateTimeProvider $calendar)
25+
{
26+
$this->calendar = $calendar;
27+
}
28+
2029
public function archive(ShippingMethodInterface $data): ShippingMethodInterface
2130
{
22-
$data->setArchivedAt(new \DateTime());
31+
$data->setArchivedAt($this->calendar->today());
2332

2433
return $data;
2534
}

src/Sylius/Bundle/ApiBundle/Doctrine/QueryCollectionExtension/HideArchivedShippingMethodExtension.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Paweł Jędrzejewski
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
declare(strict_types=1);
413

514
namespace Sylius\Bundle\ApiBundle\Doctrine\QueryCollectionExtension;

src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ShippingMethod.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<attribute name="filters">
5656
<attribute>sylius.api.shipping_method_order_filter</attribute>
5757
<attribute>sylius.api.translation_order_filter</attribute>
58-
<attribute>sylius.api.filter_archival_shipping_methods</attribute>
58+
<attribute>sylius.api.filter_archived_shipping_methods</attribute>
5959
</attribute>
6060
</collectionOperation>
6161
<collectionOperation name="post">

src/Sylius/Bundle/ApiBundle/Resources/config/services.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
</imports>
1818

1919
<services>
20-
<service id="sylius.api.archivation_shipping_method_applicator" class="Sylius\Bundle\ApiBundle\Applicator\ArchivizationShippingMethodApplicator" public="true" />
20+
<service id="sylius.api.archivation_shipping_method_applicator" class="Sylius\Bundle\ApiBundle\Applicator\ArchivizationShippingMethodApplicator" public="true">
21+
<argument type="service" id="sylius.calendar" />
22+
</service>
2123

2224
<service id="sylius.api.upload_avatar_image_action" class="Sylius\Bundle\ApiBundle\Controller\UploadAvatarImageAction" public="true">
2325
<argument type="service" id="sylius.factory.avatar_image" />

src/Sylius/Bundle/ApiBundle/Resources/config/services/filters.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<tag name="api_platform.filter" />
2626
</service>
2727

28-
<service id="sylius.api.filter_archival_shipping_methods" parent="api_platform.doctrine.orm.exists_filter">
28+
<service id="sylius.api.filter_archived_shipping_methods" parent="api_platform.doctrine.orm.exists_filter">
2929
<argument type="collection">
3030
<argument key="archivedAt">false</argument>
3131
</argument>

0 commit comments

Comments
 (0)