public function testSupportProxy()
 {
     $em = DoctrineTestHelper::createTestEntityManager();
     $this->createSchema($em);
     $user1 = new User(1, 1, 'user1');
     $em->persist($user1);
     $em->flush();
     $em->clear();
     $provider = new EntityUserProvider($this->getManager($em), 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures\\User', 'name');
     $user2 = $em->getReference('Symfony\\Bridge\\Doctrine\\Tests\\Fixtures\\User', array('id1' => 1, 'id2' => 1));
     $this->assertTrue($provider->supportsClass(get_class($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));
 }
 /**
  * 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;
 }
 /**
  * {@inheritDoc}
  */
 public function loadUserByUsername($username)
 {
     try {
         $user = parent::loadUserByUsername($username);
     } catch (UsernameNotFoundException $e) {
         $user = $this->createEntity($username);
         $this->em->persist($user);
         $this->em->flush();
     }
     return $user;
 }
 public function __construct(Registry $registry)
 {
     parent::__construct($registry, User::class);
     $this->entityManager = $registry->getManager();
 }
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testLoadUserByUserNameShouldDeclineInvalidInterface()
 {
     $repository = $this->getMock('\\Symfony\\Component\\Security\\Core\\User\\AdvancedUserInterface');
     $provider = new EntityUserProvider($this->getManager($this->getObjectManager($repository)), 'Symfony\\Bridge\\Doctrine\\Tests\\Fixtures\\User');
     $provider->loadUserByUsername('name');
 }
Example #7
0
 public function __construct($em, $class, $property = null)
 {
     parent::__construct($em, $class, $property);
 }