Skip to content

Commit e5aa018

Browse files
Merge branch '2.7' into 2.8
* 2.7: [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 ea7cc3b + 83d6628 commit e5aa018

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

Security/User/EntityUserProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function loadUserByUsername($username)
5252
} else {
5353
if (!$repository instanceof UserLoaderInterface) {
5454
if (!$repository instanceof UserProviderInterface) {
55-
throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface.', get_class($repository)));
55+
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)));
5656
}
5757

5858
@trigger_error('Implementing loadUserByUsername from Symfony\Component\Security\Core\User\UserProviderInterface is deprecated since version 2.8 and will be removed in 3.0. Implement the Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface instead.', E_USER_DEPRECATED);

Tests/Security/User/EntityUserProviderTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,68 @@ 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+
* @group legacy
58+
*/
59+
public function testLoadUserByUsernameWithUserProviderRepositoryAndWithoutProperty()
60+
{
61+
$user = new User(1, 1, 'user1');
62+
63+
$repository = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')
64+
->disableOriginalConstructor()
65+
->getMock();
66+
$repository
67+
->expects($this->once())
68+
->method('loadUserByUsername')
69+
->with('user1')
70+
->willReturn($user);
71+
72+
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
73+
->disableOriginalConstructor()
74+
->getMock();
75+
$em
76+
->expects($this->once())
77+
->method('getRepository')
78+
->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User')
79+
->willReturn($repository);
80+
81+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
82+
$this->assertSame($user, $provider->loadUserByUsername('user1'));
83+
}
84+
85+
/**
86+
* @expectedException \InvalidArgumentException
87+
* @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.
88+
*/
89+
public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty()
90+
{
91+
$em = DoctrineTestHelper::createTestEntityManager();
92+
$this->createSchema($em);
93+
94+
$user = new User(1, 1, 'user1');
95+
96+
$em->persist($user);
97+
$em->flush();
98+
99+
$provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User');
100+
$provider->loadUserByUsername('user1');
101+
}
102+
41103
public function testRefreshUserRequiresId()
42104
{
43105
$em = DoctrineTestHelper::createTestEntityManager();

0 commit comments

Comments
 (0)