Skip to content

Commit

Permalink
minor fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Mar 10, 2020
1 parent 38e84be commit 86a6f7d
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Feature: Recalculating product average rating
And this product has a review titled "Not bad" and rated 3 with a comment "Not bad car" added by customer "specter@teamharvey.com"
And I am logged in as an administrator

@ui @api @javascript
@ui @javascript
Scenario: Product's average rating is correctly recalculated after review's rate change
When I want to modify the "Awesome" product review
And I choose 5 as its rating
And I save my changes
Then I should be notified that it has been successfully edited
And average rating of product "Lamborghini Gallardo Model" should be 4

@ui @api
@ui
Scenario: Product's average rating is correctly recalculated after review's rate change
When I delete the "Awesome" product review
Then I should be notified that it has been successfully deleted
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<directory name="src/Sylius/Bundle/AddressingBundle/Tests" />
<directory name="src/Sylius/Bundle/AdminApiBundle/spec" />
<directory name="src/Sylius/Bundle/AdminApiBundle/Tests" />
<directory name="src/Sylius/Bundle/ApiBundle/spec" />
<directory name="src/Sylius/Bundle/ApiBundle/Tests" />
<directory name="src/Sylius/Bundle/AdminBundle/spec" />
<directory name="src/Sylius/Bundle/AdminBundle/Tests" />
<directory name="src/Sylius/Bundle/AttributeBundle/spec" />
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Client/ApiClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function buildCreateRequest(string $resource): void;

public function buildUpdateRequest(string $resource, string $id): void;

/** @param string|int */
/** @param string|int $value */
public function addRequestData(string $key, $value): void;

public function addCompoundRequestData(array $data): void;
Expand Down Expand Up @@ -54,7 +54,7 @@ public function isDeletionSuccessful(): bool;

public function isUpdateSuccessful(): bool;

/** @param string|int */
/** @param string|int $value */
public function responseHasValue(string $key, $value): bool;

public function hasItemWithValue(string $key, string $value): bool;
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Client/ApiPlatformClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function buildUpdateRequest(string $resource, string $id): void
$this->request['body'] = json_decode($this->client->getResponse()->getContent(), true);
}

/** @param string|int */
/** @param string|int $value */
public function addRequestData(string $key, $value): void
{
$this->request['body'][$key] = $value;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function applyTransition(string $resource, string $id, string $transition
{
$this->request(
'PATCH',
sprintf('/new-api/%s/%s/apply_transition/%s', $resource, $id, $transition),
sprintf('/new-api/%s/%s/%s', $resource, $id, $transition),
['CONTENT_TYPE' => 'application/merge-patch+json'],
'{}'
);
Expand Down Expand Up @@ -147,7 +147,7 @@ public function isDeletionSuccessful(): bool
return $this->client->getResponse()->getStatusCode() === Response::HTTP_NO_CONTENT;
}

/** @param string|int */
/** @param string|int $value */
public function responseHasValue(string $key, $value): bool
{
return $this->getResponseContentValue($key) === $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

use Behat\Behat\Context\Context;
use Sylius\Behat\Client\ApiClientInterface;
use Sylius\Behat\Service\SharedStorage;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\ProductReviewTransitions;
use Sylius\Component\Review\Model\ReviewInterface;
use Webmozart\Assert\Assert;

Expand All @@ -27,7 +24,7 @@ final class ManagingProductReviewsContext implements Context
/** @var ApiClientInterface */
private $client;

/** @var SharedStorage */
/** @var SharedStorageInterface */
private $sharedStorage;

public function __construct(
Expand Down Expand Up @@ -91,19 +88,11 @@ public function iChooseAsItsRating(int $rating): void
}

/**
* @When I accept the :productReview product review
* @When /^I (accept|reject) the ("([^"]+)" product review)$/
*/
public function iAcceptTheProductReview( ReviewInterface $productReview): void
public function iChangeStateTheProductReview(string $state, ReviewInterface $productReview): void
{
$this->client->applyTransition('product_reviews', (string) $productReview->getId(), 'accept');
}

/**
* @When I reject the :productReview product review
*/
public function iRejectTheProductReview( ReviewInterface $productReview): void
{
$this->client->applyTransition('product_reviews', (string) $productReview->getId(), 'reject');
$this->client->applyTransition('product_reviews', (string) $productReview->getId(), $state);
}

/**
Expand Down Expand Up @@ -204,14 +193,6 @@ public function thisProductReviewShouldStillHaveAComment(ReviewInterface $produc
$this->assertIfReviewHasElementWithValue($productReview, 'comment', $comment);
}

/**
* @Then /^average rating of (product "[^"]+") should be (\d+)$/
*/
public function thisProductAverageRatingShouldBe(ProductInterface $product, int $averageRating): void
{
// TODO, this step should be in product context which will be covered in separate RP
}

private function isItemOnIndex(string $property, string $value): bool
{
$this->client->index('product_reviews');
Expand Down
8 changes: 5 additions & 3 deletions src/Sylius/Behat/Context/Transform/ProductReviewContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Behat\Behat\Context\Context;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Review\Model\ReviewInterface;
use Webmozart\Assert\Assert;

final class ProductReviewContext implements Context
Expand All @@ -29,14 +30,15 @@ public function __construct(RepositoryInterface $productReviewRepository)

/**
* @Transform :productReview
* @Transform /^"([^"]+)" product review$/
*/
public function getProductReviewByTitle($productReviewTitle)
public function getProductReviewByTitle(string $title): ReviewInterface
{
$productReview = $this->productReviewRepository->findOneBy(['title' => $productReviewTitle]);
$productReview = $this->productReviewRepository->findOneBy(['title' => $title]);

Assert::notNull(
$productReview,
sprintf('Product review with title "%s" does not exist', $productReviewTitle)
sprintf('Product review with title "%s" does not exist', $title)
);

return $productReview;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
</itemOperation>
<itemOperation name="accept_product_review">
<attribute name="method">PATCH</attribute>
<attribute name="path">/product_reviews/{id}/apply_transition/accept</attribute>
<attribute name="path">/product_reviews/{id}/accept</attribute>
<attribute name="controller">sylius.api.state_machine_transition_applicator:accept</attribute>
</itemOperation>
<itemOperation name="reject_product_review">
<attribute name="method">PATCH</attribute>
<attribute name="path">/product_reviews/{id}/apply_transition/reject</attribute>
<attribute name="path">/product_reviews/{id}/reject</attribute>
<attribute name="controller">sylius.api.state_machine_transition_applicator:reject</attribute>
</itemOperation>
</itemOperations>
Expand Down
1 change: 0 additions & 1 deletion src/Sylius/Bundle/ApiBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
-->

<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>
<service id="sylius.api.state_machine_transition_applicator" class="Sylius\Bundle\ApiBundle\Applicator\ProductReviewStateMachineTransitionApplicator" public="true">
<argument id="sm.factory" type="service" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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 spec\Sylius\Bundle\ApiBundle\Applicator;

use PhpSpec\ObjectBehavior;
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
use SM\StateMachine\StateMachine;
use Sylius\Component\Core\ProductReviewTransitions;
use Sylius\Component\Review\Model\ReviewInterface;

final class ProductReviewStateMachineTransitionApplicatorSpec extends ObjectBehavior
{
function let(StateMachineFactoryInterface $stateMachineFactory) {
$this->beConstructedWith($stateMachineFactory);
}

public function it_accepts_product_review(
StateMachineFactoryInterface $stateMachineFactory,
ReviewInterface $review,
StateMachine $stateMachine
): void {
$stateMachineFactory->get($review, ProductReviewTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->apply(ProductReviewTransitions::TRANSITION_ACCEPT)->shouldBeCalled();

$this->accept($review);
}

public function it_rejects_product_review(
StateMachineFactoryInterface $stateMachineFactory,
ReviewInterface $review,
StateMachine $stateMachine
): void {
$stateMachineFactory->get($review, ProductReviewTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->apply(ProductReviewTransitions::TRANSITION_REJECT)->shouldBeCalled();

$this->reject($review);
}
}

0 comments on commit 86a6f7d

Please sign in to comment.