/**
  * {@inheritdoc}
  */
 public function validate($review, Constraint $constraint)
 {
     /* @var $customer ReviewerInterface */
     $customer = $review->getAuthor();
     $token = $this->tokenStorage->getToken();
     if ($this->checkIfUserIsAuthenticated($token)) {
         if (null !== $customer && $token->getUser()->getCustomer()->getEmail() === $customer->getEmail()) {
             return;
         }
     }
     if (null !== $customer && null !== $this->userRepository->findOneByEmail($customer->getEmail())) {
         $this->context->addViolationAt('author', $constraint->message, [], null);
     }
 }
 function it_validates_if_user_with_given_email_is_already_registered(UserRepository $userRepository, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, ExecutionContext $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);
 }