/** * Refreshes the user by reloading it from the user provider. * This method was copied from Symfony\Component\Security\Http\Firewall\ContextListener. * * @param TokenInterface $token * * @return TokenInterface|null * * @throws \RuntimeException */ protected function refreshUser(TokenInterface $token) { $user = $token->getUser(); if (!$user instanceof UserInterface) { return; } $refreshedUser = $this->userProvider->refreshUser($user); $token->setUser($refreshedUser); return $token; }
public function testRefreshInvalidUser() { $em = DoctrineTestHelper::createTestEntityManager(); $this->createSchema($em); $user1 = new User(1, 1, 'user1'); $em->persist($user1); $em->flush(); $provider = new EntityUserProvider($this->getManager($em), 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures\\User', 'name'); $user2 = new User(1, 2, 'user2'); $this->setExpectedException('Symfony\\Component\\Security\\Core\\Exception\\UsernameNotFoundException', 'User with id {"id1":1,"id2":2} not found'); $provider->refreshUser($user2); }
public function testRefreshUserGetsUserByPrimaryKey() { $em = $this->createTestEntityManager(); $this->createSchema($em); $user1 = new CompositeIdentEntity(1, 1, 'user1'); $user2 = new CompositeIdentEntity(1, 2, 'user2'); $em->persist($user1); $em->persist($user2); $em->flush(); $provider = new EntityUserProvider($em, 'Symfony\\Tests\\Bridge\\Doctrine\\Fixtures\\CompositeIdentEntity', 'name'); // try to change the user identity $user1->name = 'user2'; $this->assertSame($user1, $provider->refreshUser($user1)); }