Skip to content

Commit bad5abf

Browse files
Merge branch '2.8' into 3.1
* 2.8: [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes [FrameworkBundle][Security] Remove useless mocks [DoctrineBridge] Enhance exception message in EntityUserProvider added friendly exception when constraint validator does not exist or it is not enabled remove duplicate instruction [FrameworkBundle] Remove TranslatorBagInterface check [FrameworkBundle] Remove duplicated code in RouterDebugCommand [Validator] fixed duplicate constraints with parent class interfaces SecurityBundle:BasicAuthenticationListener: removed a default argument on getting a header value
2 parents 7829b49 + e5aa018 commit bad5abf

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function loadUserByUsername($username)
5151
$user = $repository->findOneBy(array($this->property => $username));
5252
} else {
5353
if (!$repository instanceof UserLoaderInterface) {
54-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($repository)));
54+
throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_class($repository)));
5555
}
5656

5757
$user = $repository->loadUserByUsername($username);

Tests/Security/User/EntityUserProviderTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,39 @@ public function testRefreshUserGetsUserByPrimaryKey()
3838
$this->assertSame($user1, $provider->refreshUser($user1));
3939
}
4040

41+
public function testLoadUserByUsername()
42+
{
43+
$em = DoctrineTestHelper::createTestEntityManager();
44+
$this->createSchema($em);
45+
46+
$user = new User(1, 1, 'user1');
47+
48+
$em->persist($user);
49+
$em->flush();
50+
51+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User', 'name');
52+
53+
$this->assertSame($user, $provider->loadUserByUsername('user1'));
54+
}
55+
56+
/**
57+
* @expectedException \InvalidArgumentException
58+
* @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Component\Security\Core\User\UserProviderInterface" or set the "property" option in the corresponding entity provider configuration.
59+
*/
60+
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
61+
{
62+
$em = DoctrineTestHelper::createTestEntityManager();
63+
$this->createSchema($em);
64+
65+
$user = new User(1, 1, 'user1');
66+
67+
$em->persist($user);
68+
$em->flush();
69+
70+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
71+
$provider->loadUserByUsername('user1');
72+
}
73+
4174
public function testRefreshUserRequiresId()
4275
{
4376
$em = DoctrineTestHelper::createTestEntityManager();

0 commit comments

Comments
 (0)