diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 28aacf650d..2882fd6ddd 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -52,7 +52,7 @@ class EntityUserProvider implements UserProviderInterface } else { if (!$repository instanceof UserLoaderInterface) { if (!$repository instanceof UserProviderInterface) { - 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))); + throw new \InvalidArgumentException(sprintf('You must either make the "%s" entity Doctrine Repository ("%s") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.', $this->classOrAlias, get_class($repository))); } @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); diff --git a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php index 4ec486a9c8..a4c1a77152 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php @@ -53,6 +53,32 @@ class EntityUserProviderTest extends \PHPUnit_Framework_TestCase $this->assertSame($user, $provider->loadUserByUsername('user1')); } + public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty() + { + $user = new User(1, 1, 'user1'); + + $repository = $this->getMockBuilder('Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface') + ->disableOriginalConstructor() + ->getMock(); + $repository + ->expects($this->once()) + ->method('loadUserByUsername') + ->with('user1') + ->willReturn($user); + + $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + $em + ->expects($this->once()) + ->method('getRepository') + ->with('Symfony\Bridge\Doctrine\Tests\Fixtures\User') + ->willReturn($repository); + + $provider = new EntityUserProvider($this->getManager($em), 'Symfony\Bridge\Doctrine\Tests\Fixtures\User'); + $this->assertSame($user, $provider->loadUserByUsername('user1')); + } + /** * @group legacy */ @@ -84,9 +110,9 @@ class EntityUserProviderTest extends \PHPUnit_Framework_TestCase /** * @expectedException \InvalidArgumentException - * @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. + * @expectedExceptionMessage You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration. */ - public function testLoadUserByUsernameWithNonUserProviderRepositoryAndWithoutProperty() + public function testLoadUserByUsernameWithNonUserLoaderRepositoryAndWithoutProperty() { $em = DoctrineTestHelper::createTestEntityManager(); $this->createSchema($em);