function it_updates_review_subject_average_rating_from_review($averageRatingCalculator, $reviewSubjectManager, ReviewableInterface $reviewSubject, ReviewInterface $review)
 {
     $review->getReviewSubject()->willReturn($reviewSubject);
     $averageRatingCalculator->calculate($reviewSubject)->willReturn(4.5);
     $reviewSubject->setAverageRating(4.5)->shouldBeCalled();
     $reviewSubjectManager->flush($reviewSubject)->shouldBeCalled();
     $this->updateFromReview($review);
 }
 /**
  * @param ReviewInterface $review
  * @param ReviewableInterface[] $reviewSubjectsToRecalculate
  *
  * @return array
  */
 private function removeReviewsAndExtractSubject(ReviewInterface $review, array $reviewSubjectsToRecalculate)
 {
     $reviewSubject = $review->getReviewSubject();
     if (!in_array($reviewSubject, $reviewSubjectsToRecalculate)) {
         $reviewSubjectsToRecalculate[] = $reviewSubject;
     }
     $this->reviewManager->remove($review);
     return $reviewSubjectsToRecalculate;
 }
 function it_removes_soft_deleted_customer_reviews_and_recalculates_their_product_ratings($averageRatingUpdater, $reviewRepository, $reviewManager, ReviewerInterface $author, ReviewableInterface $reviewSubject, ReviewInterface $review)
 {
     $reviewRepository->findBy(['author' => $author])->willReturn([$review]);
     $review->getReviewSubject()->willReturn($reviewSubject);
     $reviewManager->remove($review)->shouldBeCalled();
     $reviewManager->flush()->shouldBeCalled();
     $averageRatingUpdater->update($reviewSubject)->shouldBeCalled();
     $this->removeReviewerReviews($author);
 }
 function it_calculates_average_price(ReviewableInterface $reviewable, ReviewInterface $review1, ReviewInterface $review2)
 {
     $reviewable->getReviews()->willReturn([$review1, $review2]);
     $review1->getStatus()->willReturn(ReviewInterface::STATUS_ACCEPTED)->shouldBeCalled();
     $review2->getStatus()->willReturn(ReviewInterface::STATUS_ACCEPTED)->shouldBeCalled();
     $review1->getRating()->willReturn(4);
     $review2->getRating()->willReturn(5);
     $this->calculate($reviewable)->shouldReturn(4.5);
 }
 function it_validates_if_user_with_given_email_is_already_registered($userRepository, $tokenStorage, $authorizationChecker, $context, TokenInterface $token, UniqueReviewerEmail $constraint, ReviewInterface $review, CustomerInterface $customer, CustomerInterface $existingUser)
 {
     $tokenStorage->getToken()->willReturn($token);
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(false);
     $review->getAuthor()->willReturn($customer);
     $customer->getEmail()->willReturn('*****@*****.**');
     $userRepository->findOneByEmail('*****@*****.**')->willReturn($existingUser);
     $constraint->message = 'This email is already registered. Please log in.';
     $context->addViolationAt('author', 'This email is already registered. Please log in.', [], null)->shouldBeCalled();
     $this->validate($review, $constraint);
 }
 function it_validates_if_user_with_given_email_is_already_registered(UserRepository $userRepository, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, ExecutionContextInterface $executionContextInterface, ConstraintViolationBuilderInterface $constraintViolationBuilder, TokenInterface $token, ReviewInterface $review, CustomerInterface $customer, CustomerInterface $existingUser)
 {
     $constraint = new UniqueReviewerEmail();
     $tokenStorage->getToken()->willReturn($token);
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(false);
     $review->getAuthor()->willReturn($customer);
     $customer->getEmail()->willReturn('*****@*****.**');
     $userRepository->findOneByEmail('*****@*****.**')->willReturn($existingUser);
     $executionContextInterface->buildViolation($constraint->message)->shouldBeCalled()->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->atPath('author')->shouldBeCalled()->willReturn($constraintViolationBuilder);
     $constraintViolationBuilder->addViolation()->shouldBeCalled();
     $this->validate($review, $constraint);
 }
 function it_returns_zero_if_given_reviewable_object_has_reviews_but_none_of_them_is_accepted(ReviewableInterface $reviewable, ReviewInterface $review)
 {
     $reviewable->getReviews()->willReturn([$review]);
     $review->getStatus()->willReturn(ReviewInterface::STATUS_NEW);
     $this->calculate($reviewable)->shouldReturn(0);
 }
 /**
  * @Then /^(this product review) should no longer exist in the registry$/
  */
 public function thisProductReviewShouldNoLongerExistInTheRegistry(ReviewInterface $productReview)
 {
     Assert::false($this->indexPage->isSingleResourceOnPage(['title' => $productReview->getTitle()]), sprintf('Product review with title "%s" should no longer exist in the registry.', $productReview->getTitle()));
 }
 /**
  * {@inheritdoc}
  */
 public function updateFromReview(ReviewInterface $review)
 {
     $this->modifyReviewSubjectAverageRating($review->getReviewSubject());
 }