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

Skip to content

Commit 276fb1d

Browse files
committed
pr-fix
1 parent 487dfde commit 276fb1d

6 files changed

Lines changed: 45 additions & 24 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"ext-exif": "*",
2424
"ext-fileinfo": "*",
2525
"ext-gd": "*",
26-
"api-platform/core": "^2.5",
26+
"api-platform/core": "2.5.*",
2727
"babdev/pagerfanta-bundle": "^2.5",
2828
"behat/transliterator": "^1.3",
2929
"doctrine/collections": "^1.6",

src/Sylius/Behat/Context/Api/Shop/ProductContext.php

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Sylius\Behat\Client\ApiClientInterface;
1818
use Sylius\Behat\Client\Request;
1919
use Sylius\Behat\Client\ResponseCheckerInterface;
20+
use Sylius\Behat\Service\SharedStorageInterface;
21+
use Sylius\Component\Core\Model\ChannelInterface;
2022
use Sylius\Component\Core\Model\ProductInterface;
2123
use Sylius\Component\Taxonomy\Model\TaxonInterface;
2224
use Symfony\Component\HttpFoundation\Request as HttpRequest;
@@ -31,10 +33,17 @@ final class ProductContext implements Context
3133
/** @var ResponseCheckerInterface */
3234
private $responseChecker;
3335

34-
public function __construct(ApiClientInterface $client, ResponseCheckerInterface $responseChecker)
35-
{
36+
/** @var SharedStorageInterface */
37+
private $sharedStorage;
38+
39+
public function __construct(
40+
ApiClientInterface $client,
41+
ResponseCheckerInterface $responseChecker,
42+
SharedStorageInterface $sharedStorage
43+
) {
3644
$this->client = $client;
3745
$this->responseChecker = $responseChecker;
46+
$this->sharedStorage = $sharedStorage;
3847
}
3948

4049
/**
@@ -47,33 +56,43 @@ public function iOpenProductPage(ProductInterface $product): void
4756
}
4857

4958
/**
50-
* @When /^I browse products from (taxon "([^"]+)")$/
59+
* @When I browse products from taxon :taxon
5160
*/
52-
public function iCheckListOfProductsForTaxon(TaxonInterface $taxon): void
61+
public function iBrowseProductsFromTaxon(TaxonInterface $taxon): void
5362
{
5463
$this->client->index();
5564
$this->client->addFilter('productTaxons.taxon.code', $taxon->getCode());
5665
$this->client->filter();
5766
}
5867

5968
/**
60-
* @Then I should see the product price :productPrice
69+
* @Then /^I should see the product price ("[^"]+")$/
6170
*/
62-
public function iShouldSeeTheProductPrice(string $productPrice): void
71+
public function iShouldSeeTheProductPrice(int $price): void
6372
{
64-
$price = (int) filter_var($productPrice, FILTER_SANITIZE_NUMBER_INT);
65-
66-
Assert::true($this->hasProductWithPrice([$this->responseChecker->getResponseContent($this->client->getLastResponse())], $price));
73+
Assert::true(
74+
$this->hasProductWithPriceInChannel(
75+
[$this->responseChecker->getResponseContent($this->client->getLastResponse())],
76+
$price,
77+
$this->sharedStorage->get('channel'),
78+
)
79+
);
6780
}
6881

6982
/**
70-
* @Then I should see the product :product with price :productPrice
83+
* @Then /^I should see the (product "[^"]+") with price ("[^"]+")$/
7184
*/
72-
public function iShouldSeeTheProductWithPrice(ProductInterface $product, string $productPrice): void
85+
public function iShouldSeeTheProductWithPrice(ProductInterface $product, int $price): void
7386
{
74-
$price = (int) filter_var($productPrice, FILTER_SANITIZE_NUMBER_INT);
75-
76-
Assert::true($this->hasProductWithPrice($this->responseChecker->getCollection($this->client->getLastResponse()), $price, $product->getCode()));
87+
Assert::true(
88+
$this->hasProductWithPriceInChannel(
89+
$this->responseChecker->getCollection($this->client->getLastResponse()),
90+
$price,
91+
$this->sharedStorage->get('channel'),
92+
$product->getCode()
93+
),
94+
sprintf("there is no product with %s code and %s price", $product->getCode(), $price)
95+
);
7796
}
7897

7998
/**
@@ -113,18 +132,16 @@ public function itsCurrentVariantShouldBeNamed(string $variantName): void
113132
);
114133
}
115134

116-
private function hasProductWithPrice(array $resource, int $price, ?string $productCode = null): bool
135+
private function hasProductWithPriceInChannel(array $products, int $price, ChannelInterface $channel, ?string $productCode = null): bool
117136
{
118-
foreach ($resource as $product) {
119-
if ($productCode && $product['code'] !== $productCode) {
137+
foreach ($products as $product) {
138+
if ($productCode !== null && $product['code'] !== $productCode) {
120139
continue;
121140
}
122141

123142
foreach ($product['variants'] as $variant) {
124-
foreach ($variant['channelPricings'] as $channelPricing) {
125-
if ($channelPricing['price'] === $price) {
126-
return true;
127-
}
143+
if ($variant['channelPricings'][$channel->getCode()]['price'] === $price) {
144+
return true;
128145
}
129146
}
130147
}

src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<service id="sylius.behat.context.api.shop.product" class="Sylius\Behat\Context\Api\Shop\ProductContext">
8080
<argument type="service" id="sylius.behat.api_platform_client.shop.product" />
8181
<argument type="service" id="Sylius\Behat\Client\ResponseCheckerInterface" />
82+
<argument type="service" id="sylius.behat.shared_storage" />
8283
</service>
8384

8485
<service id="sylius.behat.context.api.shop.registration" class="Sylius\Behat\Context\Api\Shop\RegistrationContext">

src/Sylius/Behat/Resources/config/suites/api/product/viewing_products.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ default:
1616
- sylius.behat.context.setup.channel
1717
- sylius.behat.context.setup.locale
1818
- sylius.behat.context.setup.product
19-
- sylius.behat.context.setup.taxonomy
2019
- sylius.behat.context.setup.product_taxon
20+
- sylius.behat.context.setup.taxonomy
2121

2222
- sylius.behat.context.api.shop.product
2323

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
</itemOperation>
3232
</itemOperations>
3333

34+
<collectionOperations>
35+
</collectionOperations>
36+
37+
<property name="id" writable="false" readable="true" />
3438
<property name="price" writable="false" readable="true" />
3539
<property name="originalPrice" writable="false" readable="true" />
3640
</resource>

src/Sylius/Bundle/ApiBundle/Resources/config/serialization/ProductVariant.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
</attribute>
2727
<attribute name="product">
2828
<group>product_variant:read</group>
29-
<group>shop:product:read</group>
3029
</attribute>
3130
<attribute name="translations">
3231
<group>shop:order:account:read</group>

0 commit comments

Comments
 (0)