em = self::getContainer()->get(EntityManagerInterface::class); } public function testOwnerRoundTripsThroughPersistence(): void { $owner = new User(); $owner->setEmail('scenario-owner-test@example.com'); $owner->setPassword('irrelevant-hash'); $this->em->persist($owner); $scenario = new Scenario(); $scenario->setName('Household Budget'); $scenario->setOwner($owner); $this->em->persist($scenario); $this->em->flush(); $scenarioId = $scenario->getId(); $ownerId = $owner->getId(); $this->em->clear(); $reloaded = $this->em->find(Scenario::class, $scenarioId); self::assertNotNull($reloaded, 'Scenario must be retrievable from the database after an identity-map clear.'); self::assertInstanceOf(User::class, $reloaded->getOwner()); self::assertTrue( $ownerId->equals($reloaded->getOwner()->getId()), 'The owner set before persistence must survive a flush + clear + reload round-trip.', ); } }