forked from Sylius/Sylius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API] Configuration for shipment api browsing
- Loading branch information
Showing
22 changed files
with
505 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/Sylius/Behat/Context/Api/Admin/ManagingShipmentsContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?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\Admin; | ||
|
||
use ApiPlatform\Core\Api\IriConverterInterface; | ||
use Behat\Behat\Context\Context; | ||
use Sylius\Behat\Client\ApiClientInterface; | ||
use Sylius\Behat\Client\ResponseCheckerInterface; | ||
use Sylius\Component\Channel\Model\ChannelInterface; | ||
use Sylius\Component\Core\Formatter\StringInflector; | ||
use Sylius\Component\Customer\Model\CustomerInterface; | ||
use Sylius\Component\Order\Model\OrderInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ManagingShipmentsContext implements Context | ||
{ | ||
/** @var ApiClientInterface */ | ||
private $client; | ||
|
||
/** @var ResponseCheckerInterface */ | ||
private $responseChecker; | ||
|
||
/** @var IriConverterInterface */ | ||
private $iriConverter; | ||
|
||
public function __construct( | ||
ApiClientInterface $client, | ||
ResponseCheckerInterface $responseChecker, | ||
IriConverterInterface $iriConverter | ||
) { | ||
$this->client = $client; | ||
$this->responseChecker = $responseChecker; | ||
$this->iriConverter = $iriConverter; | ||
} | ||
|
||
/** | ||
* @When I browse shipments | ||
*/ | ||
public function iBrowseShipments(): void | ||
{ | ||
$this->client->index(); | ||
} | ||
|
||
/** | ||
* @Then I should see( only) :count shipment(s) in the list | ||
* @Then I should see a single shipment in the list | ||
*/ | ||
public function iShouldSeeCountShipmentsInList(int $count = 1): void | ||
{ | ||
Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $count); | ||
} | ||
|
||
/** | ||
* @Then /^I should see the shipment of (order "[^"]+") as "([^"]+)"$/ | ||
*/ | ||
public function iShouldSeeTheShipmentOfOrderAs(OrderInterface $order, string $shippingState): void | ||
{ | ||
Assert::true( | ||
$this->responseChecker->hasItemWithValues($this->client->getLastResponse(), [ | ||
'order' => $this->iriConverter->getIriFromItem($order), | ||
'state' => strtolower($shippingState) | ||
]), | ||
sprintf('Shipment for order %s with state %s does not exist', $order->getNumber(), $shippingState) | ||
); | ||
} | ||
|
||
/** | ||
* @Then /^I should see shipment for the ("[^"]+" order) as (\d+)(?:|st|nd|rd|th) in the list$/ | ||
*/ | ||
public function iShouldSeeShipmentForTheOrderInTheList(OrderInterface $order, int $position): void | ||
{ | ||
Assert::true( | ||
$this->responseChecker->hasItemOnPositionWithValue( | ||
$this->client->getLastResponse(), | ||
--$position, | ||
'order', | ||
$this->iriConverter->getIriFromItem($order) | ||
), | ||
sprintf('On position %s there is no shipment for order %s', $position, $order->getNumber()) | ||
); | ||
} | ||
|
||
/** | ||
* @Then the shipment of the :orderNumber order should be :shippingState for :customer | ||
* @Then the shipment of the :orderNumber order should be :shippingState for :customer in :channel channel | ||
*/ | ||
public function shipmentOfOrderShouldBe( | ||
string $orderNumber, | ||
string $shippingState, | ||
CustomerInterface $customer, | ||
ChannelInterface $channel = null | ||
): void { | ||
$this->client->index(); | ||
|
||
foreach ($this->responseChecker->getCollectionItemsWithValue($this->client->getLastResponse(), 'state', | ||
StringInflector::nameToLowercaseCode($shippingState)) as $shipment) { | ||
$orderIri = $shipment['order']; | ||
$orderShowResponse = $this->client->showByIri($orderIri); | ||
|
||
if (!$this->responseChecker->HasValue($orderShowResponse, 'number', $orderNumber)) { | ||
continue; | ||
} | ||
|
||
$this->client->showByIri($this->responseChecker->getValue($orderShowResponse, 'customer')); | ||
if (!$this->responseChecker->HasValue($this->client->getLastResponse(), 'email', $customer->getEmail())) { | ||
continue; | ||
} | ||
$this->client->showByIri($this->responseChecker->getValue($orderShowResponse, 'channel')); | ||
if ($this->responseChecker->HasValue($this->client->getLastResponse(), 'name', $channel->getName())) { | ||
return; | ||
} | ||
} | ||
|
||
throw new \InvalidArgumentException('There is no shipment with given data'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Sylius/Behat/Resources/config/suites/api/shipping/managing_shipments.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file is part of the Sylius package. | ||
# (c) Paweł Jędrzejewski | ||
|
||
default: | ||
suites: | ||
api_managing_shipments: | ||
contexts: | ||
- sylius.behat.context.hook.doctrine_orm | ||
|
||
- sylius.behat.context.transform.address | ||
- sylius.behat.context.transform.channel | ||
- sylius.behat.context.transform.country | ||
- sylius.behat.context.transform.customer | ||
- sylius.behat.context.transform.order | ||
- sylius.behat.context.transform.payment | ||
- sylius.behat.context.transform.product | ||
- sylius.behat.context.transform.shared_storage | ||
- sylius.behat.context.transform.shipping_method | ||
- sylius.behat.context.transform.zone | ||
|
||
- sylius.behat.context.setup.admin_api_security | ||
- sylius.behat.context.setup.calendar | ||
- sylius.behat.context.setup.channel | ||
- sylius.behat.context.setup.geographical | ||
- sylius.behat.context.setup.order | ||
- sylius.behat.context.setup.payment | ||
- sylius.behat.context.setup.product | ||
- sylius.behat.context.setup.shipping | ||
- sylius.behat.context.setup.zone | ||
|
||
- sylius.behat.context.api.admin.managing_shipments | ||
filters: | ||
tags: "@managing_shipments && @api" | ||
javascript: false |
38 changes: 38 additions & 0 deletions
38
src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/Channel.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<resources xmlns="https://api-platform.com/schema/metadata" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd" | ||
> | ||
<resource class="%sylius.model.channel.class%" shortName="Channel"> | ||
<attribute name="normalization_context"> | ||
<attribute name="groups"> | ||
<attribute>channel:read</attribute> | ||
</attribute> | ||
</attribute> | ||
|
||
<collectionOperations /> | ||
|
||
<itemOperations> | ||
<itemOperation name="get"> | ||
<attribute name="groups"> | ||
<attribute>channel:read</attribute> | ||
</attribute> | ||
</itemOperation> | ||
</itemOperations> | ||
|
||
<property name="code" identifier="true" writable="false" readable="true" /> | ||
<property name="name" writable="true" readable="true"/> | ||
</resource> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.