From b367d39841ae2e93ad1e7dfafc120367f3019838 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Fri, 26 Aug 2016 22:55:48 +0200 Subject: [PATCH] [DoctrineBridge] Fix exception message and tests after misresolved merge --- .../Security/User/EntityUserProvider.php | 2 +- .../Security/User/EntityUserProviderTest.php | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 28aacf650d5f..2882fd6ddd52 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -52,7 +52,7 @@ public function loadUserByUsername($username) } 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 4ec486a9c8a1..a4c1a77152a7 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 @@ public function testLoadUserByUsername() $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 @@ public function testLoadUserByUsernameWithUserProviderRepositoryAndWithoutProper /** * @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);