diff --git a/UPGRADE-1.9.md b/UPGRADE-1.9.md index c643bcf943f5..8b451848d3f5 100644 --- a/UPGRADE-1.9.md +++ b/UPGRADE-1.9.md @@ -1,3 +1,11 @@ +# UPGRADE FROM `v1.9.2` TO `v1.9.3` + +1. To have better control over the serialization process, we introduced `shop` and `admin` prefixes to names of serialization groups on `src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/*` and `src/Sylius/Bundle/ApiBundle/Resources/config/serialization/*`. + Several additional serialization groups have been rephrased, to improve readability and predictability of them. + If you are using they on your custom entity `api_resource` configuration or serialization groups, you should check if one of these changes may affect on your app. If yes, change all occurs by this pattern: + +- `product_review:update` changed to: `admin:product_review:update` and `shop:product_review:update` + # UPGRADE FROM `v1.8.X` TO `v1.9.0` ### Package upgrades diff --git a/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php b/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php index 4f4dec5060f4..830f27e5881d 100644 --- a/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php +++ b/src/Sylius/Behat/Context/Api/Shop/ProductReviewContext.php @@ -61,25 +61,6 @@ public function iCheckThisProductsReviews(): void $this->client->filter(); } - /** - * @Then I should see :amount product reviews in the list - * @Then I should be notified that there are no reviews - */ - public function iShouldSeeProductReviewsInTheList(int $amount = 0): void - { - $productReviews = $this->responseChecker->getCollection($this->client->getLastResponse()); - - Assert::count($productReviews, $amount); - } - - /** - * @Then I should not see review titled :title in the list - */ - public function iShouldNotSeeReviewTitledInTheList(string $title): void - { - Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($this->client->getLastResponse(), 'title', $title)); - } - /** * @When I add it */ @@ -126,4 +107,23 @@ public function iShouldBeNotifiedThatMyReviewIsWaitingForTheAcceptation(): void ReviewInterface::STATUS_NEW ); } + + /** + * @Then I should see :amount product reviews in the list + * @Then I should be notified that there are no reviews + */ + public function iShouldSeeProductReviewsInTheList(int $amount = 0): void + { + $productReviews = $this->responseChecker->getCollection($this->client->getLastResponse()); + + Assert::count($productReviews, $amount); + } + + /** + * @Then I should not see review titled :title in the list + */ + public function iShouldNotSeeReviewTitledInTheList(string $title): void + { + Assert::isEmpty($this->responseChecker->getCollectionItemsWithValue($this->client->getLastResponse(), 'title', $title)); + } } diff --git a/src/Sylius/Bundle/ApiBundle/Command/AddProductReview.php b/src/Sylius/Bundle/ApiBundle/Command/AddProductReview.php index fee077d31952..9cbcbe3462e5 100644 --- a/src/Sylius/Bundle/ApiBundle/Command/AddProductReview.php +++ b/src/Sylius/Bundle/ApiBundle/Command/AddProductReview.php @@ -14,7 +14,7 @@ namespace Sylius\Bundle\ApiBundle\Command; /** @experimental */ -class AddProductReview +class AddProductReview implements CommandAwareDataTransformerInterface { /** * @var string diff --git a/src/Sylius/Bundle/ApiBundle/CommandHandler/AddProductReviewHandler.php b/src/Sylius/Bundle/ApiBundle/CommandHandler/AddProductReviewHandler.php index 89470f4b3a4b..961110816c2e 100644 --- a/src/Sylius/Bundle/ApiBundle/CommandHandler/AddProductReviewHandler.php +++ b/src/Sylius/Bundle/ApiBundle/CommandHandler/AddProductReviewHandler.php @@ -29,9 +29,6 @@ /** @experimental */ final class AddProductReviewHandler implements MessageHandlerInterface { - /** @var UserContextInterface */ - private $userContext; - /** @var CustomerProviderInterface */ private $customerProvider; @@ -45,13 +42,11 @@ final class AddProductReviewHandler implements MessageHandlerInterface private $productRepository; public function __construct( - UserContextInterface $userContext, CustomerProviderInterface $customerProvider, RepositoryInterface $productReviewRepository, FactoryInterface $productReviewFactory, ProductRepositoryInterface $productRepository ) { - $this->userContext = $userContext; $this->customerProvider = $customerProvider; $this->productReviewRepository = $productReviewRepository; $this->productReviewFactory = $productReviewFactory; @@ -63,20 +58,15 @@ public function __invoke(AddProductReview $addProductReview): ReviewInterface /** @var ProductInterface $product */ $product = $this->productRepository->findOneByCode($addProductReview->productCode); - /** @var CustomerInterface|null $customer */ - $customer = $this->getCustomer(); - /** @var string|null $email */ $email = $addProductReview->email; - if ($customer === null && $email === null) { + if ($email === null) { throw new \InvalidArgumentException('Visitor should provide an email'); } - if ($customer === null && $email !== null) { - /** @var CustomerInterface $customer */ - $customer = $this->customerProvider->provide($email); - } + /** @var CustomerInterface $customer */ + $customer = $this->customerProvider->provide($email); /** @var ReviewInterface $review */ $review = $this->productReviewFactory->createNew(); @@ -92,15 +82,4 @@ public function __invoke(AddProductReview $addProductReview): ReviewInterface return $review; } - - private function getCustomer(): ?CustomerInterface - { - /** @var UserInterface|null $user */ - $user = $this->userContext->getUser(); - if ($user !== null && $user instanceof ShopUserInterface) { - return $user->getCustomer(); - } - - return null; - } } diff --git a/src/Sylius/Bundle/ApiBundle/DataTransformer/AddProductReviewInputDataTransformer.php b/src/Sylius/Bundle/ApiBundle/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformer.php similarity index 90% rename from src/Sylius/Bundle/ApiBundle/DataTransformer/AddProductReviewInputDataTransformer.php rename to src/Sylius/Bundle/ApiBundle/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformer.php index 2c226f549b46..24ddae33e9c2 100644 --- a/src/Sylius/Bundle/ApiBundle/DataTransformer/AddProductReviewInputDataTransformer.php +++ b/src/Sylius/Bundle/ApiBundle/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformer.php @@ -20,7 +20,7 @@ use Sylius\Component\Core\Model\ShopUserInterface; /** @experimental */ -final class AddProductReviewInputDataTransformer implements CommandDataTransformerInterface +final class LoggedInShopUserEmailAwareCommandDataTransformer implements CommandDataTransformerInterface { /** @var UserContextInterface */ private $userContext; @@ -35,7 +35,7 @@ public function transform($object, string $to, array $context = []) /** @var CustomerInterface|null $customer */ $customer = $this->getCustomer(); - if ($object->email === null && $customer !== null) { + if ($customer !== null) { $object->email = $customer->getEmail(); } diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/ProductReview.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/ProductReview.xml index 3e22c2c2dbac..9c47c6ad5264 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/ProductReview.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/serialization/ProductReview.xml @@ -43,6 +43,7 @@ admin:product_review:read + shop:product_review:read admin:product_review:read diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml index 08944a93a581..e356bf7ce173 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services.xml @@ -120,6 +120,11 @@ + + + + + diff --git a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml index 49f501285e8e..6d429aab54f7 100644 --- a/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml +++ b/src/Sylius/Bundle/ApiBundle/Resources/config/services/command_handlers.xml @@ -99,7 +99,6 @@ - diff --git a/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/AddProductReviewHandlerSpec.php b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/AddProductReviewHandlerSpec.php index 10d228ec43f6..ce853b1ff888 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/AddProductReviewHandlerSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/CommandHandler/AddProductReviewHandlerSpec.php @@ -15,11 +15,9 @@ use PhpSpec\ObjectBehavior; use Sylius\Bundle\ApiBundle\Command\AddProductReview; -use Sylius\Bundle\ApiBundle\Context\UserContextInterface; use Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\ProductInterface; -use Sylius\Component\Core\Model\ShopUserInterface; use Sylius\Component\Core\Repository\ProductRepositoryInterface; use Sylius\Component\Resource\Factory\FactoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; @@ -28,14 +26,12 @@ final class AddProductReviewHandlerSpec extends ObjectBehavior { function let( - UserContextInterface $userContext, CustomerProviderInterface $customerProvider, RepositoryInterface $productReviewRepository, FactoryInterface $productReviewFactory, ProductRepositoryInterface $productRepository ): void { $this->beConstructedWith( - $userContext, $customerProvider, $productReviewRepository, $productReviewFactory, @@ -43,101 +39,56 @@ function let( ); } - function it_adds_product_review_for_login_shop_user( - UserContextInterface $userContext, + function it_adds_product_review( + CustomerProviderInterface $customerProvider, RepositoryInterface $productReviewRepository, FactoryInterface $productReviewFactory, ProductRepositoryInterface $productRepository, ProductInterface $product, - ShopUserInterface $shopUser, CustomerInterface $customer, ReviewInterface $review ): void { - $addProductReview = new AddProductReview( - 'Good stuff', - 5, - 'Really good stuff', - 'winter_cap' - ); + $productRepository->findOneByCode('winter_cap')->willReturn($product); - $productRepository->findOneByCode($addProductReview->productCode)->willReturn($product); - - $userContext->getUser()->willReturn($shopUser); - - $shopUser->getCustomer()->willReturn($customer); + $customerProvider->provide('mark@example.com')->willReturn($customer); $productReviewFactory->createNew()->willReturn($review); - $review->setTitle($addProductReview->title)->shouldBeCalled(); - $review->setRating($addProductReview->rating)->shouldBeCalled(); - $review->setComment($addProductReview->comment)->shouldBeCalled(); + $review->setTitle('Good stuff')->shouldBeCalled(); + $review->setRating(5)->shouldBeCalled(); + $review->setComment('Really good stuff')->shouldBeCalled(); $review->setReviewSubject($product->getWrappedObject())->shouldBeCalled(); $review->setAuthor($customer)->shouldBeCalled(); $productReviewRepository->add($review); - $this($addProductReview); - } + $product->addReview($review->getWrappedObject())->shouldBeCalled(); - function it_adds_product_review_for_visitor( - UserContextInterface $userContext, - CustomerProviderInterface $customerProvider, - RepositoryInterface $productReviewRepository, - FactoryInterface $productReviewFactory, - ProductRepositoryInterface $productRepository, - ProductInterface $product, - ShopUserInterface $shopUser, - CustomerInterface $customer, - ReviewInterface $review - ): void { - $addProductReview = new AddProductReview( + $this(new AddProductReview( 'Good stuff', 5, 'Really good stuff', 'winter_cap', - 'boob@example.com' - ); - - $productRepository->findOneByCode($addProductReview->productCode)->willReturn($product); - - $userContext->getUser()->willReturn($shopUser); - - $shopUser->getCustomer()->willReturn($customer); - - $customerProvider->provide($addProductReview->email)->willReturn($customer); - - $productReviewFactory->createNew()->willReturn($review); - - $review->setTitle($addProductReview->title)->shouldBeCalled(); - $review->setRating($addProductReview->rating)->shouldBeCalled(); - $review->setComment($addProductReview->comment)->shouldBeCalled(); - $review->setReviewSubject($product->getWrappedObject())->shouldBeCalled(); - $review->setAuthor($customer)->shouldBeCalled(); - - $productReviewRepository->add($review); - - $this($addProductReview); + 'mark@example.com' + )); } - function it_throws_exception_if_shop_user_has_not_been_found( - UserContextInterface $userContext, + function it_throws_an_exception_if_email_has_not_been_found( ProductRepositoryInterface $productRepository, ProductInterface $product ): void { - $addProductReview = new AddProductReview( - 'Good stuff', - 5, - 'Really good stuff', - 'winter_cap' - ); - - $productRepository->findOneByCode($addProductReview->productCode)->willReturn($product); - - $userContext->getUser()->willReturn(null); + $productRepository->findOneByCode('winter_cap')->willReturn($product); $this ->shouldThrow(\InvalidArgumentException::class) - ->during('__invoke', [$addProductReview]) + ->during('__invoke', [ + new AddProductReview( + 'Good stuff', + 5, + 'Really good stuff', + 'winter_cap' + ) + ]) ; } } diff --git a/src/Sylius/Bundle/ApiBundle/spec/DataTransformer/AddProductReviewInputDataTransformerSpec.php b/src/Sylius/Bundle/ApiBundle/spec/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformerSpec.php similarity index 76% rename from src/Sylius/Bundle/ApiBundle/spec/DataTransformer/AddProductReviewInputDataTransformerSpec.php rename to src/Sylius/Bundle/ApiBundle/spec/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformerSpec.php index b79ad2d833ad..cc23c6da4521 100644 --- a/src/Sylius/Bundle/ApiBundle/spec/DataTransformer/AddProductReviewInputDataTransformerSpec.php +++ b/src/Sylius/Bundle/ApiBundle/spec/DataTransformer/LoggedInShopUserEmailAwareCommandDataTransformerSpec.php @@ -20,13 +20,13 @@ use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\ShopUserInterface; -final class AddProductReviewInputDataTransformerSpec extends ObjectBehavior +final class LoggedInShopUserEmailAwareCommandDataTransformerSpec extends ObjectBehavior { function let(UserContextInterface $userContext) { $this->beConstructedWith($userContext); } - function it_adds_email_to_add_product_review_for_login_customer( + function it_adds_email_to_add_product_review_for_logged_in_customer( UserContextInterface $userContext, ShopUserInterface $shopUser, CustomerInterface $customer @@ -37,10 +37,10 @@ function it_adds_email_to_add_product_review_for_login_customer( $this->transform( new AddProductReview( - 'Good stuff', - 5, - 'Really good stuff', - 'winter_cap' + 'Good stuff', + 5, + 'Really good stuff', + 'winter_cap' ), 'Sylius\Component\Core\Model\ProductReview', [] @@ -69,14 +69,16 @@ function it_does_not_add_email_to_add_product_review_for_visitor( ); } - function it_supports_add_product_review(): void + function it_supports_command_for_adding_product_review(): void { - $this->supportsTransformation(new AddProductReview( - 'Good stuff', - 5, - 'Really good stuff', - 'winter_cap' - ))->shouldReturn(true); + $this->supportsTransformation( + new AddProductReview( + 'Good stuff', + 5, + 'Really good stuff', + 'winter_cap' + ) + )->shouldReturn(true); } function it_does_not_support_not_add_product_review(): void