Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loginAs results later into duplicate entry #334

Open
develth opened this issue Sep 20, 2017 · 3 comments
Open

loginAs results later into duplicate entry #334

develth opened this issue Sep 20, 2017 · 3 comments

Comments

@develth
Copy link

develth commented Sep 20, 2017

Hey there,

When i create my Client via loginAs and a Reference it will later, when i want to edit this user, into a duplicate entry.

FYI: I´m using FOSUserBundle.

What i do:

User Create:

$userManager = $this->container->get('fos_user.user_manager');
$user = new User();
$user->setUsername("myname");
$user->setEmail("[email protected]");
$user->setPlainPassword("testpass");
$user->setEnabled(true);
$userManager->updateCanonicalFields($user);
$userManager->updatePassword($user);
$this->addReference('user-default', $user);
$userManager->updateUser($user);

Fixtures Load (LiipFunctionalTestBundle)

$em = $this->getContainer()->get('doctrine')->getManager();
if (!isset($metadatas)) {
  $metadatas = $em->getMetadataFactory()->getAllMetadata();
}
$schemaTool = new SchemaTool($em);
$schemaTool->dropDatabase();
if (!empty($metadatas)) {
  $schemaTool->createSchema($metadatas);
}
$fixturesClasses = array(
  LoadUserData::class
);
$this->fixtures = $this->loadFixtures($fixturesClasses)->getReferenceRepository();

Client Create:

$currentUser = $this->fixtures->getReference("user-default");
$this->loginAs($currentUser, $fireWall);
$this->client = $this->makeClient();

User Update in Controller:

$user = $this->get('security.token_storage')->getToken()->getUser();
if ($user instanceof User) {
        $user->setlastActionAt(new \DateTime());
        $this->em->persist($user);
        $this->em->flush(); // results in a Integrity constraint violation: 1062 Duplicate entry
}

What i recognized is that the getEntityState in the UnitOfWork results in $assume, because the $this->entityStates is empty.

What i´m doing wrong? Or is it a bug?

Thanks,
Thomas

@alexislefebvre
Copy link
Collaborator

alexislefebvre commented Sep 20, 2017

When you perform the same things by yourself (i.e. by going to app_dev.php/…), do you have the same error?

@develth
Copy link
Author

develth commented Sep 20, 2017

What do you exactly mean with "same things"?
Just the "User Update in Controller"? That works.

@develth
Copy link
Author

develth commented Sep 20, 2017

By the way:
if i do a makeClient with username and password credentials, everything is working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants