liip / liip/LiipFunctionalTestBundle
loginAs results later into duplicate entry
- Dominant language
- PHP
- Stars
- 648
- Forks
- 179
- PR merge metrics
- No merged PRs in 30d
Description
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("my.mail@provider.com");
$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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the fixture setup with LoadUserData, loginAs, and the controller flush shown in the report. Inspect the UnitOfWork getEntityState result and entity state around loginAs and flush; done means identifying whether the bundle causes the duplicate entry and documenting a confirmed fix or reproducible regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, symfony
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100