From d71210cef08ccfcf799c31fc35c0babe6a9a65c1 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Tue, 30 Mar 2021 07:48:26 +0200 Subject: [PATCH] move context to productReviewContext --- .../Behat/Context/Api/Shop/ProductContext.php | 63 +------------------ .../Context/Api/Shop/ProductReviewContext.php | 44 +++++++++++++ .../config/services/contexts/api/shop.xml | 3 - 3 files changed, 45 insertions(+), 65 deletions(-) diff --git a/src/Sylius/Behat/Context/Api/Shop/ProductContext.php b/src/Sylius/Behat/Context/Api/Shop/ProductContext.php index 357fa810b920..2f5fb6740c6f 100644 --- a/src/Sylius/Behat/Context/Api/Shop/ProductContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/ProductContext.php @@ -13,12 +13,10 @@ 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; use Sylius\Behat\Client\ResponseCheckerInterface; -use Sylius\Behat\Service\SharedStorageInterface; use Sylius\Component\Core\Model\ChannelInterface; use Sylius\Component\Core\Model\ProductInterface; use Sylius\Component\Taxonomy\Model\TaxonInterface; @@ -34,27 +32,12 @@ final class ProductContext implements Context /** @var ResponseCheckerInterface */ private $responseChecker; - /** @var SharedStorageInterface */ - private $sharedStorage; - - /** @var ApiClientInterface */ - private $productReviewClient; - - /** @var IriConverterInterface */ - private $iriConverter; - public function __construct( ApiClientInterface $client, - ResponseCheckerInterface $responseChecker, - SharedStorageInterface $sharedStorage, - ApiClientInterface $productReviewClient, - IriConverterInterface $iriConverter + ResponseCheckerInterface $responseChecker ) { $this->client = $client; $this->responseChecker = $responseChecker; - $this->sharedStorage = $sharedStorage; - $this->productReviewClient = $productReviewClient; - $this->iriConverter = $iriConverter; } /** @@ -94,39 +77,6 @@ public function iSearchForProductsWithName(string $name) $this->client->filter(); } - /** - * @Then I should see :amount product reviews - */ - public function iShouldSeeProductReviews(int $amount): void - { - /** @var ProductInterface $product */ - $product = $this->sharedStorage->get('product'); - - $this->productReviewClient->index(); - $this->productReviewClient->addFilter('reviewSubject', $this->iriConverter->getIriFromItem($product)); - $this->productReviewClient->addFilter('itemsPerPage', 3); - $this->productReviewClient->addFilter('order[createdAt]', 'desc'); - $this->productReviewClient->filter(); - - Assert::same($this->responseChecker->countCollectionItems($this->productReviewClient->getLastResponse()), $amount); - } - - /** - * @Then I should see reviews titled :titleOne, :titleTwo and :titleThree - */ - public function iShouldSeeReviewsTitledAnd(string ...$titles): void - { - Assert::true($this->hasReviewsWithTitles($titles)); - } - - /** - * @Then I should not see review titled :title - */ - public function iShouldNotSeeReviewTitled(string $title): void - { - Assert::false($this->hasReviewsWithTitles([$title])); - } - /** * @Then I should see the product :name */ @@ -248,15 +198,4 @@ private function hasProductWithName(array $products, string $name): bool return false; } - - private function hasReviewsWithTitles(array $titles): bool - { - foreach ($titles as $title) { - if (!$this->responseChecker->hasItemWithValue($this->productReviewClient->getLastResponse(), 'title', $title)) { - return false; - } - } - - return true; - } } diff --git a/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php b/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php index 830f27e5881d..3b4a843ee771 100644 --- a/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php @@ -89,6 +89,39 @@ public function iLeaveACommentTitled(string $comment, string $title, ?string $em $this->client->addRequestData('email', $email); } + /** + * @Then I should see :amount product reviews + */ + public function iShouldSeeProductReviews(int $amount = 0): void + { + /** @var ProductInterface $product */ + $product = $this->sharedStorage->get('product'); + + $this->client->index(); + $this->client->addFilter('reviewSubject', $this->iriConverter->getIriFromItem($product)); + $this->client->addFilter('itemsPerPage', 3); + $this->client->addFilter('order[createdAt]', 'desc'); + $this->client->filter(); + + Assert::same($this->responseChecker->countCollectionItems($this->client->getLastResponse()), $amount); + } + + /** + * @Then I should see reviews titled :titleOne, :titleTwo and :titleThree + */ + public function iShouldSeeReviewsTitledAnd(string ...$titles): void + { + Assert::true($this->hasReviewsWithTitles($titles)); + } + + /** + * @Then I should not see review titled :title + */ + public function iShouldNotSeeReviewTitled(string $title): void + { + Assert::false($this->hasReviewsWithTitles([$title])); + } + /** * @When I rate it with :rating point(s) */ @@ -126,4 +159,15 @@ public function iShouldNotSeeReviewTitledInTheList(string $title): void { Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($this->client->getLastResponse(), 'title', $title)); } + + private function hasReviewsWithTitles(array $titles): bool + { + foreach ($titles as $title) { + if (!$this->responseChecker->hasItemWithValue($this->client->getLastResponse(), 'title', $title)) { + return false; + } + } + + return true; + } } diff --git a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml index aa3928df90ce..977e5192fd55 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/api/shop.xml @@ -82,9 +82,6 @@ - - -