Skip to content

Commit

Permalink
[Account] Add spec to sync username with customer email
Browse files Browse the repository at this point in the history
  • Loading branch information
hatem20 committed Aug 11, 2020
1 parent 118559f commit c5e245f
Showing 1 changed file with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,35 @@ function it_sets_usernames_on_customer_create(
$this->onFlush($onFlushEventArgs);
}

function it_sets_usernames_on_customer_update_when_user_is_associated(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
UnitOfWork $unitOfWork,
CustomerInterface $customer,
ShopUserInterface $user,
ClassMetadata $userMetadata
): void {
$onFlushEventArgs->getEntityManager()->willReturn($entityManager);
$entityManager->getUnitOfWork()->willReturn($unitOfWork);

$unitOfWork->getScheduledEntityInsertions()->willReturn([$user]);
$unitOfWork->getScheduledEntityUpdates()->willReturn([]);

$user->getUsername()->willReturn(null);
$user->getUsernameCanonical()->willReturn(null);
$customer->getEmail()->willReturn('customer+extra@email.com');
$customer->getEmailCanonical()->willReturn('customer@email.com');

$user->getCustomer()->willReturn($customer);
$user->setUsername('customer+extra@email.com')->shouldBeCalled();
$user->setUsernameCanonical('customer@email.com')->shouldBeCalled();

$entityManager->getClassMetadata(get_class($user->getWrappedObject()))->willReturn($userMetadata);
$unitOfWork->recomputeSingleEntityChangeSet($userMetadata, $user)->shouldBeCalled();

$this->onFlush($onFlushEventArgs);
}

function it_updates_usernames_on_customer_email_change(
OnFlushEventArgs $onFlushEventArgs,
EntityManager $entityManager,
Expand Down

0 comments on commit c5e245f

Please sign in to comment.